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. ...
随机推荐
- Java -----transient 和static
越来越喜欢深究java基础了,讲讲 transient 和static 对序列化的影响.废话少说,直接上代码就可以了 package serializable; import java.io.Ser ...
- Scala IDE里的WorkSheet的使用
所见即所得的一个工具, 左边编码,右边立即出结果 https://www.cnblogs.com/zlslch/p/6115118.html
- 彻底搞懂oracle的标量子查询
oracle标量子查询和自己定义函数有时用起来比較方便,并且开发者也常常使用.数据量小还无所谓.数据量大,往往存在性能问题. 下面測试帮助大家彻底搞懂标量子查询. SQL> create tab ...
- meta标签多种用法
<meta name=”google” content=”notranslate” /> <!-- 有时,Google在结果页面会提供一个翻译链接,但有时候你不希望出现这个链接,你可 ...
- MySQL双主热备问题处理
1. Slave_IO_Running: No mysql> show slave status\G *************************** 1. row *********** ...
- 设置安卓开机动画、开机logo
我们要修改的是system>media文件夹下的bootanimation.zip(手机开机动画)这个文件 先来讲讲这个文件结构:该zip解压后得到两个文件, 第一个目录存放了开机时播放的图片( ...
- Codeforces 490F Treeland Tour 树上的最长上升子序列
题目链接:点击打开链接 题意: 给定n个点的树. 以下n个数表示点权. 以下n-1行给出树. 找一条链,然后找出这条链中的点权组成的最长上升子序列. 求:最长上升子序列的长度. 思路: 首先是维护一条 ...
- 内核顶层Makefile相关4
http://www.groad.net/bbs/simple/?f104.html make 的递归执行与 MAKEFLAGS 变量 make 的递归调用是指:在 Makefile 中使用 make ...
- cubietruck制作刷新lubuntu-kernel
一:安装交叉编译工具链以及相应的工具(系统最好是ubutnu-64位-server) sudo apt-get install g++ sudo apt-get install libncurses5 ...
- sql无限级树型查询
表结构如下: 表数据如下: 一提到无限级,很容易想到递归,使用sql 的CET语法如下 with menu(Id,Name,ParentId,Level) as ( select Id,Name,Pa ...