HDOJ 5463-Clarke and minecraft【贪心】

来源:互联网 发布:女装品牌 知乎 编辑:程序博客网 时间:2024/04/29 23:52

Clarke and minecraft

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


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
232 333 332 33105 4676 3787 3098 4995 3203 4802 4448 3915 333100 499
 

Sample Output
12Hint: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)
 
解题思路:

一个背包有64层,每一层有36个格,同时每一层只能放相同的物品,问我们需要搬运多少次。

#include<stdio.h>#include<string.h>#include<algorithm>#include<cmath>using namespace std;int wc[100005];int main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);int i,j;memset(wc,0,sizeof(wc));for(i=1;i<=n;i++){int x,y;scanf("%d%d",&x,&y);wc[x]+=y;}int ans=0;double av3344;for(i=1;i<=1000;i++){if(wc[i]!=0){av3344=wc[i]*1.0;av3344=av3344/64.0;ans+=(int)ceil(av3344*1.0);}}printf("%d\n",(int)ceil(ans*1.0/36));}return 0;}



0 0
原创粉丝点击