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. ...
随机推荐
- 思科CCIE全新升级,SDN/SD-WAN成重头戏!
CCIE,全称Cisco Certified Internetwork Expert,是美国Cisco公司于1993年开始推出的专家级认证考试.被全球公认为IT业最权威的认证,是全球Internetw ...
- git alias
alias|grep git g=git ga='git add' gaa='git add --all' gapa='git add --patch' gb='git branch' gba='gi ...
- Ext 上传文件
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title> ...
- SQL 列转行与行转列
假设有张学生成绩表(tb)如下:Name Subject Result张三 语文 74张三 数学 83张三 物理 93李四 语文 74李四 数学 84李四 物理 94*/ -------------- ...
- 类加载器在加载类 的时候就已经对类的static代码块和static变量进行了初始化
类装载器ClassLoader 类装载器工作机制 类装载器就是寻找类的节码文件并构造出类在JVM内部表示对象的组件.在Java中,类装载器把一个类装入JVM中,要经过以下步骤: [1.]装载:查找和导 ...
- UITableView 滚动时使用reloaddata出现 crash'-[__NSCFArray objectAtIndex:]: index (1) beyond bounds (0)' Crash
例子: - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)in ...
- linux 中两个文档怎么对比内容是否一致
可以用diff命令对比文档内容.[语法]: diff [参数] 文件1 文件2[说明]: 本命令比较两个文本文件,将不同的行列出来-b 将一串空格或TAB 转换成一个空格或TAB-e 生成一个编辑角本 ...
- OpenSceneGraph FAQ 【转】
1.地球背面的一个点,计算它在屏幕上的坐标,能得到吗? 不是被挡住了吗? 答:计算一个空间点的屏幕坐标,使用osgAPEx::GetScreenPosition函数.当空间点处于相机视空间内(不管它是 ...
- margin: 0 auto; 元素水平居中布局无效
失效原因: 要给居中的元素一个宽度,否则无效. 该元素一定不能浮动或绝对定位,否则无效. 在HTML中使用<center></center>标签,需考虑好整体构架,否者全部元素 ...
- spring security开发步骤
1.web.xml中加载spring ,spring security 2.spring security配置文件中配置好.... 3.自己写一个myFilter代替原有的FilterSecurity ...