Clarke and minecraft
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 291 Accepted Submission(s): 150
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(1≤T≤10) , 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(1≤a,b≤500) ,
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)
题目大意:一个游戏,有很多种物品,不同的物品有各自的数量,Clarke有一个背包,背包有36个格子,
一个格子能放下64个物品,一次运一个背包,问需要运几次。
思路:记录每一种 物品的数量sum,然后查看每种物品要占用的格子数,注意一个格子未必要装满,也就
是说一个格子能装64个物品,但是不能是不同的,只能装相同的物品,所以未满的一个格子也算占用了一个
格子,背包也是同理,但是背包能装不同类型的物品,只要注意向上取整就行了。
ac代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define INF 0xfffffff
#define MAXN 550
using namespace std;
int sum[MAXN];
int main()
{
int a,b,t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(sum,0,sizeof(sum));
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
sum[a]+=b;
}
int ans=0;
for(i=0;i<MAXN;i++)
{
if(sum[i])
{
ans+=(int)ceil(1.0*sum[i]/64);
}
}
printf("%d\n",(int)ceil(1.0*ans/36));
}
return 0;
}