GCPC2014 G Gold Rush

题意:有一块2^n大的金块,你每一次只能把一块变成相同的两快(当然大小是原来的1/2),问你现在有容量a,b,a+b = 2^n的背包,多少次能够使得a,b把这所有的金块都装下去。

解题思路:递归。

解题代码:

 1 // File Name: f.cpp
 2 // Author: darkdream
 3 // Created Time: 2015年03月15日 星期日 12时19分58秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 
26 using namespace std;
27 LL a, b ;
28 LL  p(int n)
29 {
30   LL sum = 1; 
31   for(int i=  1;i <= n;i ++)
32       sum *=2 ;
33   return sum; 
34 }
35 int solve(LL t, LL now)
36 {
37     //printf("%lld %lld\n",t,now);
38     if(t == now)
39         return 0; 
40     return 1 + solve(t/2,abs(now-t/2));
41 }
42 int main(){
43    int  t ;
44    scanf("%d",&t);
45    while(t--)
46    {
47        int n ;
48        scanf("%d %lld %lld",&n,&a,&b);
49        printf("%d\n",solve(p(n),a)-1); 
50    }
51 return 0;
52 }
View Code

 

转载于:https://www.cnblogs.com/zyue/p/4340558.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值