SGU 126. Boxes
来源:互联网 发布:亲润淘宝旗舰店 编辑:程序博客网 时间:2024/04/30 03:15
http://acm.sgu.ru/problem.php?contest=0&problem=126
There are two boxes. There are A balls in the first box, and B balls in the second box (0 < A + B < 2147483648). It is possible to move balls from one box to another. From one box into another one should move as many balls as the other box already contains. You have to determine, whether it is possible to move all balls into one box.
#include <iostream>using namespace std;int solve_boxs(int a, int b){ int num=0; while(a!=0 && b!=0){ if(((a+b)&1)==1)return -1;//a,b的和是奇数则无解 if(a<b){ b=b-a; b>>=1; }else{ a=a-b; a>>=1; }num++; } return num;}int main(){int a;int b;while(cin>>a>>b){cout << solve_boxs(a,b)<<endl;}return 0;}
0 0
- [SGU]126. Boxes
- SGU 126. Boxes
- SGU 126. Boxes 找规律 数学 二进制
- SGU 126 Boxes
- sgu 126 Boxes
- SGU 126 - Boxes
- SGU 126 Boxes
- SGU 126 Boxes(数论)
- SGU 126Boxes(模拟题|二进制)
- sgu 126 Boxes 数学推导(打表找规律??...)
- Boxes
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- CF #261 (Div. 2) A
- STL set之求交并差
- IOS 推送消息 php做推送服务端(沙盒测试与正式发布两个版本)
- GoodZhang在学Python(十一)--下一步应该学啥
- windows7回环网卡配置
- SGU 126. Boxes
- FAT32文件系统的存储组织结构(一)
- android开发中activity的启动方式
- 开源 免费 java CMS - FreeCMS2.1 会员我的留言
- iOS中js与objective-c的交互
- 【阅读】《Head First JavaScript》第八章——驾驭网页(利用DOM)分割HTML
- crm使用soap批量删除数据
- vmware workstation 10 简单安装 ubuntu 12,然后打开终端,设置root密码
- FAT32文件系统的存储组织结构(二)