HDU-6501 Problem B. Memory Banks

Posted asurudo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU-6501 Problem B. Memory Banks相关的知识,希望对你有一定的参考价值。

 1 #include <bits/stdc++.h>
 2 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
 3 const int maxn = 100000 + 10;
 4 const int mod=1000000007;
 5 using namespace std;
 6 typedef long long ll;
 7 
 8 ll station[maxn];
 9 ll qa(ll a,ll b)
10 {
11     ll ans=0;
12     while(b)
13     {
14         if(b&1)ans=(ans+a)%mod;
15         a=(a+a)%mod;
16         b>>=1;
17     }
18     return ans;
19 }
20 int main()
21 {
22     ll liusi[70];
23     while(~scanf("%lld",&liusi[0]))
24     {
25         _for(i,1,60)
26             scanf("%lld",&liusi[i]);
27         
28         int n;
29         scanf("%d",&n);
30         _for(i,0,n)
31         scanf("%lld",&station[i]);
32 
33         sort(station,station+n,greater<ll>());
34         int flag = 0;
35         for(int i = 0;i < n;i ++)
36         {
37             int j;
38             for(j = 59;j >= 0;j --)
39             {
40                 if(!liusi[j])
41                     continue;
42                 ll a = ((ll)1<<j);
43                 if(a>station[i])
44                     continue;
45                 
46                 ll b = station[i]/a;
47                 if(b>=liusi[j])
48                 {
49                     station[i] -= liusi[j]*a;
50                     liusi[j] = 0;
51                 }
52                 else
53                 {
54                     station[i] -= b*a;
55                     liusi[j] -= b;
56                 }
57             }
58             if(station[i])
59             {
60                 flag = 1;
61                 break;
62             }
63         }
64         if(flag)
65         {
66             printf("-1
");
67             continue;
68         }
69         
70         ll rnt = 0;
71         for(int i = 59; i >= 0; i --)
72         {
73             if(liusi[i])
74                 rnt = (rnt + qa(liusi[i],1LL<<i)) % mod;
75         }
76         printf("%lld
",rnt);
77     }
78     return 0;
79 }

 

以上是关于HDU-6501 Problem B. Memory Banks的主要内容,如果未能解决你的问题,请参考以下文章

Problem B. Harvest of Apples

2017ccpc杭州站 Problem B. Master of Phi

Codeforces Round #343 (Div. 2) B. Far Relative’s Problem

The 17th Zhejiang Provincial Contest B. Bin Packing Problem(线段树+map)

http://codeforces.com/problemset/problem/768/B B. Code For 1

HDU-6333 Problem B. Harvest of Apples 莫队