您的位置:首页 > 其它

BC22hdoj5142&&hdoj5143&&hdoj5144

2016-03-02 22:01 260 查看


NPY and FFT

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 771    Accepted Submission(s): 469


Problem Description

A boy named NPY is learning FFT algorithm now.In that algorithm,he needs to do an operation called "reverse".

For example,if the given number is 10.Its binary representaion is 1010.After reversing,the binary number will be 0101.And then we should ignore the leading zero.Then the number we get will be 5,whose binary representaion is 101.

NPY is very interested in this operation.For every given number,he want to know what number he will get after reversing.Can you help him?

 

Input

The first line contains a integer T — the number of queries (1≤T≤100).

The next T lines,each contains a integer X(0≤X≤231−1),the
given number.

 

Output

For each query,print the reversed number in a separate line.

 

Sample Input

3
6
8
1

 

Sample Output

3
1
1

 

Source

BestCoder Round #22

 

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=10010;
int bit[35];
int main()
{
int t,x,i;
scanf("%d",&t);
while(t--){
scanf("%d",&x);
int cnt=0,ans=0;
while(x){
bit[++cnt]=x&1;
x>>=1;
}
int d=1;
for(i=cnt;i>=0;--i){
ans=ans+bit[i]*d;
d<<=1;
}
printf("%d\n",ans);
}
return 0;
}


NPY and arithmetic progression

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 836    Accepted Submission(s): 267


Problem Description

NPY is learning arithmetic progression in his math class. In mathematics, an arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive terms is constant.(from wikipedia)

He thinks it's easy to understand,and he found a challenging problem from his talented math teacher:

You're given four integers, a1,a2,a3,a4,
which are the numbers of 1,2,3,4 you have.Can you divide these numbers into some Arithmetic Progressions,whose lengths are equal to or greater than 3?(i.e.The number of AP can be one)

Attention: You must use every number exactly once.

Can you solve this problem?

 

Input

The first line contains a integer T — the number of test cases (1≤T≤100000).

The next T lines,each contains 4 integers a1,a2,a3,a4(0≤a1,a2,a3,a4≤109).

 

Output

For each test case,print "Yes"(without quotes) if the numbers can be divided properly,otherwise print "No"(without quotes).

 

Sample Input

3
1 2 2 1
1 0 0 0
3 0 0 0

 

Sample Output

Yes
No
Yes
HintIn the first case,the numbers can be divided into {1,2,3} and {2,3,4}.
In the second case,the numbers can't be divided properly.
In the third case,the numbers can be divided into {1,1,1}.

 

解题思路暴力枚举:自己做的列出所有可能情况写了100多行结果提交就wa我自己有测试了几组测试数据都是对的无奈之下找了一个对拍程序和别人ac的代码对拍结果发现错误一大堆啊!果断放弃了自己的代码。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=10010;
int array[4];
bool judge(int n){
if(n>=3||n==0)
return true;
return false;
}
int main()
{
int t,i,j,k;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&array[0],&array[1],&array[2],&array[3]);
bool sign=false;
for(i=0;i<3;++i){//枚举123 234 1234 三种情况
for(j=0;j<3;++j){
for(k=0;k<3;++k){
array[0]=array[0]-i-k;
array[1]=array[1]-i-j-k;
array[2]=array[2]-i-j-k;
array[3]=array[3]-j-k;
if(judge(array[0])&&judge(array[1])&&judge(array[2])&&judge(array[3]))sign=true;
array[0]=array[0]+i+k;
array[1]=array[1]+i+j+k;
array[2]=array[2]+i+j+k;
array[3]=array[3]+j+k;
}
}
}
if(sign)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
[ Copy to Clipboard ] [ Save to File]


NPY and shot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 785    Accepted Submission(s): 328


Problem Description

NPY is going to have a PE test.One of the test subjects is throwing the shot.The height of NPY is H meters.He can throw the shot at the speed of v0 m/s and at the height of exactly H meters.He wonders if he throws the shot at the best angle,how far can he throw
?(The acceleration of gravity, g, is 9.8m/s2)

 

Input

The first line contains a integer T(T≤10000),which
indicates the number of test cases.

The next T lines,each contains 2 integers H(0≤h≤10000m),which
means the height of NPY,and v0(0≤v0≤10000m/s),
which means the initial velocity.

 

Output

For each query,print a real number X that was rounded to 2 digits after decimal point in a separate line.X indicates the farthest distance he can throw.

 

Sample Input

2
0 1
1 2

 

Sample Output

0.10
0.99
HintIf the height of NPY is 0,and he throws the shot at the 45° angle, he can throw farthest.

 

Source

BestCoder Round #22

 

三分角度即可

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
#define PI acos(-1.0)
#define eps 1e-8;
using namespace std;
const int maxn=10010;
double h,v;
double judge(double ang){
double vx=v*cos(ang),vy=v*sin(ang);
double t1=vy/9.8;
double x=0.5*9.8*t1*t1;
double t2=sqrt(2.0*(h+x)/9.8);
return vx*(t1+t2);
}
int main()
{
int t,i,j,k;
scanf("%d",&t);
while(t--){
scanf("%lf%lf",&h,&v);
int size=100;
double l=0,r=PI/2.0;
while(size--){
double mid=(l+r)/2.0;
double mmid=(mid+r)/2.0;
if(judge(mid)<judge(mmid)){
l=mid+eps;
}
else {
r=mmid-eps;
}
}
printf("%.2lf\n",judge(l));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  BC22hdoj5142hdoj5143