hdu 5463 Clarke and minecraft

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5463

Clarke and minecraft

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 366    Accepted Submission(s): 193


Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a game player of minecraft. 
On that day, Clarke set up local network and chose create mode for sharing his achievements with others. Unfortunately, a naughty kid came his game. He placed a few creepers in Clarke's castle! When Clarke returned his castle without create mode, creepers suddenly blew(what a amazing scene!). Then Clarke's castle in ruins, the materials scattered over the ground. 
Clark had no choice but to pick up these ruins, ready to rebuild. After Clarke built some chests(boxes), He had to pick up the material and stored them in the chests. Clarke clearly remembered the type and number of each item(each item was made of only one type material) . Now Clarke want to know how many times he have to transport at least. 
Note: Materials which has same type can be stacked, a grid can store 64 materials of same type at most. Different types of materials can be transported together. Clarke's bag has 4*9=36 grids.
 

 

Input
The first line contains a number  T(1T10), the number of test cases. 
For each test case: 
The first line contains a number n, the number of items. 
Then n lines follow, each line contains two integer a,b(1a,b500)a denotes the type of material of this item, b denotes the number of this material.
 

 

Output
For each testcase, print a number, the number of times that Clarke need to transport at least.
 

 

Sample Input
2
3
2 33
3 33
2 33
10
5 467
6 378
7 309
8 499
5 320
3 480
2 444
8 391
5 333
100 499
 

 

Sample Output
1
2
 
Hint: The first sample, we need to use 2 grids to store the materials of type 2 and 1 grid to store the materials of type 3. So we only need to transport once;
 

 

Source
BestCoder Round #56 (div.2)
 
题目大意:
想要和盒子搬运一些物品,每个物品都有材质和数量。,一个盒子有36个格子,每个格子只能装同一种材质的物品,一个格子最多只能装64件物品。最后输出的是需要搬运几次。
 
详见代码。
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int t;
    int sum[510];
    scanf("%d",&t);
    while (t--)
    {
        int n,Max=0,ans=0;
        memset(sum,0,sizeof(sum));
        scanf("%d",&n);
        while (n--)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            sum[a]+=b;//a类有多少个
            if (a>Max)
                Max=a;
        }
        for (int i=0; i<=Max; i++)
        {
            if (sum[i]==0)
                continue;
            if (sum[i]%64==0)
                ans+=sum[i]/64;
            else
                ans+=(sum[i]/64)+1;
        }
        int aans;
        if (ans%36==0)
            aans=ans/36;
        else
            aans=(ans/36)+1;
        printf ("%d\n",aans);
    }
    return 0;
}


你可能感兴趣的:(hdu 5463 Clarke and minecraft)