Problem-solving ideas: This problem just beginning, feel good cumbersome, good confusion, clear ideas, found very simple.
See Code Analysis for details.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN =505;6 intHASH1[MAXN];//the total number of tokens corresponding to the type. 7 intMain ()8 {9 intT, N, a, B, sum, CNT;Tenscanf"%d", &t); One while(t--) A { -scanf"%d", &n); -memset (HASH1,0,sizeof(HASH1)); the while(n--) - { -scanf"%d%d", &a, &b); -Hash1[a] + = b;//hash1 Tag corresponding type total number of occurrences + } -sum = CNT =0; + for(inti =0; I <=505; i++)//because both A and B have a value range of A { at if(Hash1[i])//If there has been - { -Sum + = hash1[i]/ -;//sum records how many squares to put in total - if(hash1[i]% -) sum + +;//if it is not divisible, put one more lattice -CNT + = sum/ $, Sum%= $;//The total number of CNT records to be shipped - } in } - if(sum) CNT + +;//if sum is not divisible, it will be shipped one more time toprintf"%d\n", CNT); + } - return 0; the}
View Code
HDU5463 Clarke and Minecraft