无语……
第一个点是什么啊?好强大……
查看状态 Show Status
状态题目:盒子
题目编号:268-盒子 查看该题
状态: Unaccepted
测评机: Xeost[5]
得分: 90分
提交日期: 2009-10-29 21:45:00
有效耗时: 423毫秒
测试结果1: 选手程序无输出
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时47ms
测试结果4: 通过本测试点|有效耗时47ms
测试结果5: 通过本测试点|有效耗时47ms
测试结果6: 通过本测试点|有效耗时47ms
测试结果7: 通过本测试点|有效耗时47ms
测试结果8: 通过本测试点|有效耗时47ms
测试结果9: 通过本测试点|有效耗时47ms
测试结果10: 通过本测试点|有效耗时47ms
提交代码: /*
查看题目 Show Problem
题目:盒子
问题编号:268 [提交该题] [讨论该问题] [有关讨论] [Who AC] [相关题解] [最优解]
My Flag:Unsubmited
题目类型
数论 / 数值
描述
有2个无限大的盒子。
A个球在第1个盒子里,B个球在第2个盒子里(0 < A + B < 2147483648)。
我们可以将一个盒子里的一些球移动到另一个盒子里,但移动球的数量必须跟所移动到的盒子里原有的球数量一样多。
这就需要你来判断,是否有可能让所有的球都移动到其中一个盒子里。
输入格式
第1行一个正整数K,表示有K组数据(K<=3)。
接下来K行,每行2个整数A和B。
输出格式
输出包括K行。
对于每组的数据,分别输出所需要将所有球都移动到一个盒子里所需要的步数,如果不能移动到同一个盒子里则输出-1。
样例输入
1
1 3
样例输出
2
*/
#include<iostream>
using namespace std;
int gcd(int a,int b){
if (a%b==0) return b;
return gcd(b,a%b);
}
int main (void){
int k;
cin>>k;
for (;k>0;--k){
int a,b;
cin>>a>>b;
int c=gcd(a,b),s=a/c+b/c,n=0;
bool exp2=true;
while (s!=1){
if (s%2!=0){
exp2=false;
break;
}
else{
++n;
s/=2;
}
}
if (exp2) cout<<n<<endl;
else cout<<"-1"<<endl;
}
return 0;
}
查看状态 Show Status
状态题目:盒子
题目编号:268-盒子 查看该题
状态: Accepted
测评机: Xeost[5]
得分: 100分
提交日期: 2009-10-30 20:49:00
有效耗时: 485毫秒
测试结果1: 通过本测试点|有效耗时62ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时47ms
测试结果4: 通过本测试点|有效耗时47ms
测试结果5: 通过本测试点|有效耗时47ms
测试结果6: 通过本测试点|有效耗时47ms
测试结果7: 通过本测试点|有效耗时47ms
测试结果8: 通过本测试点|有效耗时47ms
测试结果9: 通过本测试点|有效耗时47ms
测试结果10: 通过本测试点|有效耗时47ms
提交代码: /*
查看题目 Show Problem
题目:盒子
问题编号:268 [提交该题] [讨论该问题] [有关讨论] [Who AC] [相关题解] [最优解]
My Flag:Unsubmited
题目类型
数论 / 数值
描述
有2个无限大的盒子。
A个球在第1个盒子里,B个球在第2个盒子里(0 < A + B < 2147483648)。
我们可以将一个盒子里的一些球移动到另一个盒子里,但移动球的数量必须跟所移动到的盒子里原有的球数量一样多。
这就需要你来判断,是否有可能让所有的球都移动到其中一个盒子里。
输入格式
第1行一个正整数K,表示有K组数据(K<=3)。
接下来K行,每行2个整数A和B。
输出格式
输出包括K行。
对于每组的数据,分别输出所需要将所有球都移动到一个盒子里所需要的步数,如果不能移动到同一个盒子里则输出-1。
样例输入
1
1 3
样例输出
2
*/
#include<iostream>
using namespace std;
int gcd(int a,int b){
if (a%b==0) return b;
return gcd(b,a%b);
}
int main (void){
int k;
cin>>k;
for (;k>0;--k){
int a,b;
cin>>a>>b;
if (a==b||(!(a&&b))){
cout<<"0"<<endl;
continue;
}
int c=gcd(a,b),s=a/c+b/c,n=0;
bool exp2=true;
while (s!=1){
if (s%2!=0){
exp2=false;
break;
}
else{
++n;
s/=2;
}
}
if (exp2) cout<<n<<endl;
else cout<<"-1"<<endl;
}
return 0;
}