1003 Fall with Trees(公式+精度)
1003
题意: 就是给你在坐标轴上建立一个满二叉树,,然后让你求出他外围边边所围成的面积,那这个时候就要你推公式了!
思路: 高度为h,是不变的,第2层的宽度为
b
2
=
d
b2=d
b2=d,那么接下来的第i层的宽度就是
b
i
=
∑
i
=
1
k
d
?
2
2
?
i
bi=\displaystyle\sum_{i=1}^kd*2^{2-i}
bi=i=1∑k?d?22?i
=
2
?
2
2
?
k
=2-2^{2-k}
=2?22?k ,那么第k层面积就是
S
k
=
h
?
S_k=h*
Sk?=h?
b
i
?
1
+
b
i
2
\frac{b_{i-1}+b_i}{2}
2bi?1?+bi??,那么面积就是
S
=
∑
i
=
1
k
?
1
S
k
S=\displaystyle\sum_{i=1}^{k-1}S_k
S=i=1∑k?1?Sk?,然后带进去展开
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int k;
scanf("%d",&k);
double xt,yt,xl,yl,xr,yr;
scanf("%lf%lf%lf%lf%lf%lf",&xt,&yt,&xl,&yl,&xr,&yr);
double d=(xr-xl)/2;
double h=yt-yr;
double ans=h*d*(4*k-10+3.0/pow(2,k-2));
printf("%.3f\n",ans);
}
}
这里还有一个精度bug!!!我之前使用cin来读的,结果就精度不正确给挂了!!气,wa了两发,于是好好的补了下精度 pow、cin都会导致精度缺失,下次注意!
1010 Smzzl with Tropical Taste(签到题)
1010 题意: 一个游泳池,你边喝水,他边放水,请问什么时候什么时候他的水位会下降
思路: 就判断他给你的俩个数就好了
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
double p,q;
scanf("%lf%lf",&p,&q);
if(p<=q)cout<<"N0 M0R3 BL4CK 1CE TEA!"<<endl;
else cout<<"ENJ0Y YOURS3LF!"<<endl;
}
return 0;
}
1008 Smzzl with Greedy Snake(模拟+贪心)
题意: 贪吃蛇,不会吧不会吧,不会有人没玩过贪吃蛇把?
思路: 模拟+贪心
#include<bits/stdc++.h>
using namespace std;
string go(int x, int y, int &d, int sx, int sy)
{
string s1="";
if(sx<x && d!=3){
if(d==0)s1+='u';
if(d==2)s1+='c';
if(d==1)s1+="uu";
d=3;
}
if(sx>x && d!=1){
if(d==0)s1+='c';
if(d==2)s1+='u';
if(d==3)s1+="uu";
d=1;
}
s1 += string(abs(sx-x), 'f');
if(sy<y && d!=2){
if(d==0)s1+="cc";
if(d==1)s1+='c';
if(d==3)s1+='u';
d=2;
}
if(sy>y && d!=0){
if(d==1)s1+='u';
if(d==2)s1+="uu";
if(d==3)s1+='c';
d=0;
}
s1 += string(abs(sy-y), 'f');
return s1;
}
string go2(int x, int y, int &d, int sx, int sy)
{
string s1="";
if(sy<y && d!=2){
if(d==0)s1+="cc";
if(d==1)s1+='c';
if(d==3)s1+='u';
d=2;
}
if(sy>y && d!=0){
if(d==1)s1+='u';
if(d==2)s1+="uu";
if(d==3)s1+='c';
d=0;
}
s1 += string(abs(sy-y), 'f');
if(sx<x && d!=3){
if(d==0)s1+='u';
if(d==2)s1+='c';
if(d==1)s1+="uu";
d=3;
}
if(sx>x && d!=1){
if(d==0)s1+='c';
if(d==2)s1+='u';
if(d==3)s1+="uu";
d=1;
}
s1 += string(abs(sx-x), 'f');
return s1;
}
int main()
{ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
int x, y, d; cin>>x>>y>>d;
int n; cin>>n;
string ans = "";
for(int i = 1; i <= n; i++){
int sx, sy; cin>>sx>>sy;
int d1=d, d2=d;
string t1= go(x,y,d1,sx,sy);
string t2= go2(x,y,d2,sx,sy);
if(t1.size()<t2.size())ans+=t1,d=d1;
else ans+=t2,d=d2;
x = sx, y = sy;
}
cout<<ans<<"\n";
}
return 0;
}
|