hdu5463(基礎)

Clarke and minecraft

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


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
//hdu5463(基礎)
//題目大意:有n件物品,(可能有種類相同的物品)現在有一個揹包,其內部有36個單元,每個單元可以放同類型
//的物品64個,問將所有物品從一處運到另一處需要多少次?
//解題思路:定義一個數組,將同類的物品歸到一起.先求出每種物品需要多少個單元的總和,然後因爲運一次也就是
//36個單元,所以除以36就是需要運的次數,不過需要注意物品不足放滿36個單元,也需要一次. 
#include<stdio.h>
#include<string.h>
int main()
{
   int a[510],t,n,i,u,v,k;
   scanf("%d",&t);
   while(t--)
   {
   	  memset(a,0,sizeof(a));
      scanf("%d",&n);	
      for(i=0;i<n;i++)
      {
      	scanf("%d%d",&u,&v);
      	a[u]+=v;
	  }
	  k=0;
	  for(i=1;i<=500;i++)
	  {
	  	if(a[i]>0)
	  	{
	  	  if(a[i]%64>0) k+=a[i]/64+1;
		  else          k+=a[i]/64;
		}
	  }
	  if(k%36>0) k=k/36+1;
	  else       k=k/36;
	  printf("%d\n",k);
   }
   return 0;	
} 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章