Clarke and minecraftTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 534 Accepted Submission(s): 276
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
Sample Output
|
题意:有N份物品,每组输入两个数a和b,a表示物品类型,b表示件数。已知同一类的物品才可以堆在一起。每个格子最多可以堆放64件同一类型的物品,每一次搬运可以携带36个格子,问你运完N份物品需要的最少次数。
思路:建立一个map映射,设置一个变量用作下标来存储类型,统计每个类型的数目,最后贪心的模拟一次就ok了。
AC代码:
#include <cstdio> #include <cstring> #include <algorithm> #include <map> using namespace std; int type[510]; map<int, int> fp; int main() { int t, N; scanf("%d", &t); while(t--) { scanf("%d", &N); memset(type, 0, sizeof(type)); fp.clear(); int cnt = 0; for(int i = 1; i <= N; i++) { int a, b; scanf("%d%d", &a, &b); if(!fp[a]) { fp[a] = ++cnt; type[fp[a]] = b; } else type[fp[a]] += b; } int ans = 0; for(int i = 1; i <= cnt; i++) { ans += type[i] / 64; if(type[i] % 64) ans++;//总格数 } printf("%d\n", ans % 36 == 0 ? ans / 36 : (ans / 36 + 1)); } return 0; }