hdu 6501 Problem B. Memory Banks

Problem Description

We have purchased 60 different types of memory banks, typed as 0 to 59, A bank of type i has 2^i memory capacity. We have Xi memory banks of type i.
We also have n workstations numbered from 1 to n. The ith workstation needs exactly (no more and no less) Wi memory capacity to work.
Each workstation can use unlimited amount of memory banks, Total memory capacity of this workstation is the sum of capacity of all memory banks it used.
We need to make all workstations work and calculate the total capacity of unused memory banks, can you help us?

 

 

Input

Input is given from Standard Input in the following format:
X0 ... X59
n
W1 ... Wn
Constraints
0 ≤ Xi ≤ 2^60
1 ≤ n ≤ 100000
0 ≤ Wi ≤ 2^60
All of them are integers.

 

 

Output

Print one line denotes the answer.
If it is possible to make all workstations work, output a single number represents the total capacity of unused memory banks. It maybe very large, you should modulo 1000000007(10^9 + 7)
Otherwise output -1

 

 

Sample Input

 

4 2 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3

10 8 16

2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4

2 4 8 1

 

 

Sample Output

 

6

-1

题意:对于第i个库,给定ai个银行,且每个库i 里的银行有2的i 次方个容量。

然后给定一个数n,问这60个库是否能存得下这bi。。。。bn个容量的车间。必须是小的银行放到大的车间里,大的银行无法分割进小的车间。

这题就是大数模拟,说来惭愧我提交了4次,当时脑子感觉是短路了,结束以后冷静下来才发现忘了取膜而且还提前跳出循环忘了要算剩余的银行容量总数。aaaa啊啊啊啊啊啊aaaa,最后才发现是取膜的时候没取好,不仅sum要取膜,k和a【i 】也要取膜,要是我最后没有放弃,再认认真真的检查一下不就过了吗,不就过了吗。愧对队友系列,aaaaaaaaaaaaa,大数取膜大数取膜默念100遍

这个故事告诉我们一个道理,不要放弃debug

#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
using namespace std;
const int maxn=1e9+7;
long long  a[64],b[100064],need[64];

int main()
{
    int i,n,j;
    long long  k;
   long long p, sum;
    while(scanf("%lld",&k)!=EOF){
           memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            a[0]=k;
        for(i=1;i<60;i++)
        {
           scanf("%lld",&a[i]);
        }

        scanf("%d",&n);int l=n;
        for(i=0;i<l;i++)
        {
            scanf("%lld",&b[i]);

        }
        int flag=0;
        sort(b,b+n);
        for(i=n-1;i>=0;i--){
           // if(flag) break;
           // printf("i1=%d b=%lld\n",i,b[i]);
            for(j=59;j>=0;j--){
                if(a[j]){
                        //printf("a[%d]=%lld\n",j,a[j]);
                    k=pow(2,j);
                    if(b[i]>=k){
                       int  p=b[i]/k;
                        if(p>a[j]){
                           b[i]-=k*a[j]; a[j]=0;
                        }
                        else {
                          b[i]-=p*k; a[j]-=p;
                        }
                    }
                // printf("a[%d]=%lld b%d=%lld\n",j,a[j],i,b[i]);
                }
            }
            if(b[i]) flag=1;
           //  printf("i2=%d b=%lld\n",i,b[i]);
        }
        if(flag) printf("-1\n");
        else {
            sum=a[0];k=1;//printf("a[o]=%d  ",a[0]);
            for(i=1;i<60;i++){
                   // printf("i=%d  a=%lld\n",i,a[i]);
                k=k*2;k%=maxn;a[i]%=maxn;
                sum+=(a[i]*k%maxn);
                sum%=maxn;
            }
            printf("%lld\n",sum);
        }

    }


    return 0;
}

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值