题目链接: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 —— 二进制的更多相关文章

  1. Gold Rush(hnu13249)

    Gold Rush Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB Total submit users: 15 ...

  2. 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 ...

  3. SIP SDP RTSP RTP RTCP webrtc

    rfc1889  rfc2326  rfc3261  rfc3550  rfc3856  rfc6120. SIP SDP RTSP  RTP RTCP,就像他们出现的顺序一样,他们在实际应用中的启用 ...

  4. BBC票选出的100部最经典美国电影,你看过几部?

    BBC票选出的100部最经典美国电影,你看过几部? 导读:BBC票选出的100部最经典美国电影,你看过几部? 2015-07-27欧美内参欧美内参欧美内参 微信号zoujinoumei 功能介绍< ...

  5. The 10 Best Neighborhoods in Seattle

    https://www.seattlemet.com/articles/2015/4/24/the-10-best-neighborhoods-in-seattle-may-2015 By Darre ...

  6. Training Neural Networks: Q&A with Ian Goodfellow, Google

    Training Neural Networks: Q&A with Ian Goodfellow, Google Neural networks require considerable t ...

  7. 吐血推荐250部必看电影下载 IMDB TOP 250 download

    中文名: IMDB Top 250合辑 TLF-MiniSD收藏版英文名: IMDB Top 250 TLF-MiniSD Collection版本: (更新至TOP119)[MiniSD]发行日期: ...

  8. 只用120行Java代码写一个自己的区块链-3挖矿算法

    在本系列前两篇文章中,我们向大家展示了如何通过精炼的Java代码实现一个简单的区块链.包括生成块,验证块数据,广播通信等等,这一篇让我们聚焦在如何实现 PoW算法. 大家都无不惊呼比特币.以太坊及其他 ...

  9. Dawson City【道森市】

    Dawson City Cities usually have a good reason for being where they are, like a nearby port or river. ...

随机推荐

  1. Ant -----ant标签和自定义任务

    随便记一下 Ant的用法吧.ant ,maven, gradle ,三个打包工具到齐了,Ant 常见标签解析,ant 自定义task . <?xml version="1.0" ...

  2. Flex 布局教程学习

    转载自:阮一峰的网络日志(http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html) 网页布局(layout)是 CSS 的一个重点应用. 布局 ...

  3. 随笔:Golang 时间Time

    先了解下time类型: type Time struct { // sec gives the number of seconds elapsed since // January 1, year 1 ...

  4. Css Position定位(简易版本)

    准备前的知识: 定位只对块级起作用.如div,p等元素是块级元素,如果是内联元素则可以先变成块级元素,display:block即可. 开始讲解: 定位共四种:static,fixed,relativ ...

  5. 解决mac osx下pip安装ipython权限的问题

    1 pip install ipython --user -U 下面是pip install gevent的错误提示, 又是 Operation not permitted …   1 2 3 4 5 ...

  6. PhantomJS 基础及示例 (转)

    概述 PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support f ...

  7. 借助树莓派模拟Wimonitor并实现WiFi窃听和嗅探

    Wimonitor是一款非常优秀的黑客工具,它不仅可以帮渗透测试人员省去配置虚拟机和无线网卡等一系列麻烦事,而且它的Web接口配置起来也非常的方便.实际上,它就是一款TP-Link-MR3020路由器 ...

  8. mysql insert into 时报1062错误

    插入数据库时报1062错误,并没有错误详解 而网上的原因大多是主键重复,找了半天并没有解决办法 最后发现是表设置了联合唯一 ,插入的数据和之前的一样 >_< 太真实了

  9. CUDA编程-&gt;CUDA入门了解(一)

    安装好CUDA6.5+VS2012,操作系统为Win8.1版本号,首先下个GPU-Z检測了一下: 看出本显卡属于中低端配置.关键看两个: Shaders=384.也称作SM.或者说core/流处理器数 ...

  10. Laravel 数据库连接, 数据库名,配置文件修改

    数据库连接:在根目录(laravel5.1下面有个.env文件,如果没有则会有个.env.example然后将此文件修改成.env文件即可)打开文件:找到:DB_HOST=127.0.0.1  //连 ...