Gold Rush
2015-07-09 17:14
471 查看
#include<iostream>
#include<math.h>
using namespace std;
main()
{
int t,n;
scanf("%d",&t);
long long a,b,tmp;
while(t--)
{
scanf("%d%lld%lld",&n,&a,&b);
long long sum=1,qun=0;
for(int i=0;i<n;i++)
sum=2*sum;
a=max(a,b);
// printf("%lld %lld\n",a,sum);
if(a==sum)
{
printf("0\n");
continue;
}
while(a>0)
{
tmp=sum/2;
sum=tmp;
if(a>=tmp)
a=a-tmp;
qun++;
}
printf("%lld\n",qun);
}
}
Description
Input
Output
Sample Input
3 2 2 2 2 1 3 10 1000 24
Sample Output
1 2 7
HINT
Source
贪心算法,注意变量在作用域中值的变化#include<iostream>
#include<math.h>
using namespace std;
main()
{
int t,n;
scanf("%d",&t);
long long a,b,tmp;
while(t--)
{
scanf("%d%lld%lld",&n,&a,&b);
long long sum=1,qun=0;
for(int i=0;i<n;i++)
sum=2*sum;
a=max(a,b);
// printf("%lld %lld\n",a,sum);
if(a==sum)
{
printf("0\n");
continue;
}
while(a>0)
{
tmp=sum/2;
sum=tmp;
if(a>=tmp)
a=a-tmp;
qun++;
}
printf("%lld\n",qun);
}
}
相关文章推荐
- Category和extension(扩展类的功能)
- Yusuke Sugomori 的 C 语言 Deep Learning 程序解读
- mongo Aggregation group
- Algorithms—56.Merge Intervals
- Dragon of Loowater
- [Algorithm] 字符串匹配算法——KMP算法
- 使用if和goto语句构造循环
- Algorithms—54.Spiral Matrix
- 你所不知道的Google广告阴暗面
- mongo 中 高级查询之 group
- golang
- POJ2762 Going from u to v or from v to u? 强连通+缩点
- 极课 good
- Algorithms—53.Maximum Subarray
- Google Volley 解析参考文章
- 算法基础:正整数指定规则排序问题(Golang实现)
- win7配置go环境
- iphone 开发Categories 、Extensions 区别 --转
- Algorithms—50.Pow(x, n)
- CodeForces 228E The Road to Berland is Paved With Good Intentions (2-Sat)