hdu 5463 Clarke and minecraft(贪心)

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

1
2 3
1 2

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)

附上中文题目:

克拉克是一名人格分裂患者。某一天,克拉克分裂成了一个学生,在做题。
突然一道难题难到了克拉克,这道题是这样的:
给你n个数,要求选一些数(可以不选),把它们加起来,使得和恰好是p的倍数(0也是p的倍数),求方案数。
对于n很小的时候,克拉克是能轻易找到的。然而对于n很大的时候,克拉克没有办法了,所以来求助于你。  

附上官方题解:

贪心,将同样材料堆到一格里,然后每一次都装满36个格子,装满就运即可。注意取上界操作。

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<math.h>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 #include <stack>
15 using namespace std;
16 int dirx[]={0,0,-1,1};
17 int diry[]={-1,1,0,0};
18 #define PI acos(-1.0)
19 #define max(a,b) (a) > (b) ? (a) : (b)
20 #define min(a,b) (a) < (b) ? (a) : (b)
21 #define ll long long
22 #define eps 1e-10
23 #define MOD 1000000007
24 #define N 1000000
25 #define inf 1e12
26 int n;
27 map<int,int>mp;
28
29 int main()
30 {
31     int t;
32     scanf("%d",&t);
33     while(t--){
34         mp.clear();
35         scanf("%d",&n);
36         for(int i=0;i<n;i++){
37             int x,y;
38             scanf("%d%d",&x,&y);
39             mp[x]+=y;
40         }
41
42         int ans=0;
43         int g=0;
44         for(int i=1;i<=506;i++){
45             if(mp[i]){
46                 g+=mp[i]/64;
47                 if(mp[i]%64!=0){
48                     g++;
49                 }
50             }
51         }
52
53         ans=ans+g/36;
54
55         if(g%36!=0){
56             ans++;
57         }
58         printf("%d\n",ans);
59
60     }
61     return 0;
62 }

时间: 2024-10-29 19:06:59

hdu 5463 Clarke and minecraft(贪心)的相关文章

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 patien

hdu 4825 Xor Sum(trie+贪心)

hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #define CLR(a,b) memset((a)

【贪心专题】HDU 1009 FatMouse&#39; Trade (贪心选取)

链接:click here~~ 题意:老鼠准备了M磅猫食,准备拿这些猫食跟猫交换自己喜欢的食物.有N个房间,每个房间里面都有食物.你可以得到J[i]单位的食物,但你需要付出F[i]单位的的猫食. 计算M磅猫食可以获得最多食物的重量. [解题思路]贪心算法,求最优解.将J[i]/F[i]的值从大到小排列,每次取最大的,局部最优,达到全局最优,从而获得最大值. 代码: // 贪心策略,优先选择投资最大的房间,每选择一次,交换次数依次减少,最后的次数用于价值最小的 //注意精度转化:1.0*(int

HDU 4952 Poor Mitsui(贪心)

HDU 4957 Poor Mitsui 题目链接 思路:利用相邻交换法去贪心即可,注意容积为0的情况,这是个坑点 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 45; struct SB { int a, b; } sb[N]; bool cmp(SB x, SB y) { return x.b * y.a < x.

hdu 3650 Hot Expo(贪心)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3650 --------------------------------------------------------------------------------------------------------------------------------------------

HDU 4803 Poor Warehouse Keeper(贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=4803 贪心的策略是,每次尽量加价格,加到能满足条件的最大值,然后加一下数量,这样反复直到到达答案. 然后加到满足条件最大值一步不能模拟,可以推一下公式就能直接算出来了 代码: #include <stdio.h> #include <string.h> const double eps = 1e-9; double x, y; int main() { while (~scanf("%

HDU 1051 并查集+贪心

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11694    Accepted Submission(s): 4837 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar

hdu 4882 ZCC Loves Codefires(贪心)

题目链接:hdu 4882 ZCC Loves Codefires 题目大意:就是CF的比赛,根据时间的推迟会相应的扣掉题目的分数,问说最少扣几分. 解题思路:相邻交换法,判断两个题目之间的比率确定前后位置. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1e5+5; typedef __int64 ll; struct st

hdu 4803 Poor Warehouse Keeper(贪心+数学)

题目链接:hdu 4803 Poor Warehouse Keeper 题目大意:有以个屏幕可以显示两个值,一个是数量x,一个是总价y.有两种操作,一种是加一次总价,变成x,x+y:一种是加一个数量,这要的话总价也会相应加上一个的价钱,变成x+1,y+y/x.总价显示的为取整后的整数,小数部分忽略.给定一个目标x,y,初始状态为1,1,求最少需要多少次可以目标状态,不可以达到的话输出-1. 解题思路:如果是加一次总价的话,单价就在变大:如果是加一次数量的话,单价是不变的.总而言之,单价是只会往上