CSU - 1530 Gold Rush —— 二进制
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1530
对于一块2^n质量的gold。需要把它分成a质量和b质量(a+b=2^n),且每次分时是平分。问至少要平分多少次?
其实只需要知道最小分块的质量,就能知道它分了多少次。
比如当a=5, b=3,n=3时:
2^3: 1000
5 : 0101(3的情况也一样)
可知最小分块的质量为1。一块石头,它由8个质量分到1个质量,需要经过三次平分。
所以答案就是(2^n)的二进制的最高位1的位置减去a二进制中最低位1的位置。即:ans = (n+1) - (a二进制从右数起0的个数+1) = n - a二进制从右数起0的个数
代码如下:
题解:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int maxn = 2000000+10;
const int mod = 1e9+7; void solve()
{
LL a,b,n;
scanf("%lld%lld%lld",&n,&a,&b); LL t = 0;
while(!(a&1))//只需找到最小的分块,就能知道分了多少次
{
t++;
a >>= 1;
}
printf("%lld\n",n-t);
} int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
int t;
scanf("%d", &t);
while(t--){
solve();
}
return 0;
}
CSU - 1530 Gold Rush —— 二进制的更多相关文章
- Gold Rush(hnu13249)
Gold Rush Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB Total submit users: 15 ...
- 10 Best TV Series Based On Hacking And Technology
Technology is rapidly becoming the key point in human lives. Here we have discussed top TV shows whi ...
- SIP SDP RTSP RTP RTCP webrtc
rfc1889 rfc2326 rfc3261 rfc3550 rfc3856 rfc6120. SIP SDP RTSP RTP RTCP,就像他们出现的顺序一样,他们在实际应用中的启用 ...
- BBC票选出的100部最经典美国电影,你看过几部?
BBC票选出的100部最经典美国电影,你看过几部? 导读:BBC票选出的100部最经典美国电影,你看过几部? 2015-07-27欧美内参欧美内参欧美内参 微信号zoujinoumei 功能介绍< ...
- The 10 Best Neighborhoods in Seattle
https://www.seattlemet.com/articles/2015/4/24/the-10-best-neighborhoods-in-seattle-may-2015 By Darre ...
- Training Neural Networks: Q&A with Ian Goodfellow, Google
Training Neural Networks: Q&A with Ian Goodfellow, Google Neural networks require considerable t ...
- 吐血推荐250部必看电影下载 IMDB TOP 250 download
中文名: IMDB Top 250合辑 TLF-MiniSD收藏版英文名: IMDB Top 250 TLF-MiniSD Collection版本: (更新至TOP119)[MiniSD]发行日期: ...
- 只用120行Java代码写一个自己的区块链-3挖矿算法
在本系列前两篇文章中,我们向大家展示了如何通过精炼的Java代码实现一个简单的区块链.包括生成块,验证块数据,广播通信等等,这一篇让我们聚焦在如何实现 PoW算法. 大家都无不惊呼比特币.以太坊及其他 ...
- Dawson City【道森市】
Dawson City Cities usually have a good reason for being where they are, like a nearby port or river. ...
随机推荐
- 【APIO2016】Gap
题目描述 有 $N$ 个严格递增的非负整数 $a_1, a_2, \dots, a_N$($0 \leq a_1 < a_2 < \cdots < a_N \leq 10^{18}$ ...
- 用Java做一个跳一跳辅助
Java跳一跳辅助 首先..让大家看下效果: 由于是闲着没事写的.也懒得看OpenCV的API了. 要用到的工具如下: adb+jdk 把adb添加到环境变量里就行.很简单. 全部代码如下.就这么多. ...
- Codeforces 235 C
题目大意 给定一个模板串, 再给出\(n\)个询问, 询问每一个串的循环串总共在原串中出现了多少次. 循环串: 比如说有\(str[] = \{ABCD\}\), 则其循环串有\(\{ABCD\}, ...
- ARC下循环引用的问题
最初 最近在开发应用时碰到使用ASIHttpRequest后在某些机器上发不出请求的问题,项目开启了ARC,代码是这样写的: @implement MainController - (void) fe ...
- uitableview执行deleteRowsAtIndexPaths时出错
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid updat ...
- cocos2d-x step by step(3) Double Kill
喏,咱们已经调通hello world 了,然后呢,咱们做一些高大上的东西,那做什么呢,做一个打乒乓球的小东西,啊哈! 这就是最终界面了,没画一个球形 就用一个白色方框代替吧. 啊哈! public ...
- iOS -- MBProgressHUB
高级: http://www.jianshu.com/p/485b8d75ccd4 //只有小菊花 - (void)indeterminateExample { // Show the HUD on ...
- 【Tensorflow】tf.argmax函数
tf.argmax(input, axis=None, name=None, dimension=None) 此函数是对矩阵按行或列计算最大值 参数 input:输入Tensor axis:0表示 ...
- IDEA Java/Scala混合项目maven打包
1.首先创建maven项目 2.创建成功后新建class,只有java的,没有scala的 3.修改pom.xml文件,引入scala <?xml version="1.0" ...
- 记事本中写c/c++程序在Windows下运行
1.在桌面新建一个1.c,内容例如以下: 2.打开cmd命令行窗体,进入CodeBlock安装文件夹下的:E:\Installed\CodeBlocks\MinGW.然后运行mingwvars. ...