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
附上中文题目:
克拉克是一名人格分裂患者。某一天,克拉克分裂成了一个学生,在做题。 突然一道难题难到了克拉克,这道题是这样的: 给你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