标签:color print ace _for pac long hdu lag --
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\n"); 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\n",rnt); 77 } 78 return 0; 79 }
HDU-6501 Problem B. Memory Banks
标签:color print ace _for pac long hdu lag --
原文地址:https://www.cnblogs.com/Asurudo/p/10743767.html