HDU5463 Clarke and minecraft

解题思路:此题刚开始,觉得好繁琐,好混乱,理清思路后,发现很简单。

       具体见代码分析。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn = 505;
 6 int hash1[maxn]; //标记对应类型总共出现了多少个。
 7 int main()
 8 {
 9     int t, n, a, b, sum, cnt;
10     scanf("%d", &t);
11     while(t--)
12     {
13         scanf("%d", &n);
14         memset(hash1, 0, sizeof(hash1));
15         while(n--)
16         {
17             scanf("%d %d", &a, &b);
18             hash1[a] += b; //hash1标记对应类型共出现多少个
19         }
20         sum = cnt = 0;
21         for(int i = 0; i <= 505; i++) //因为a和b的取值范围都为500
22         {
23             if(hash1[i]) //如果出现过
24             {
25                 sum += hash1[i]/64; //sum记录总共要装多少个格子
26                 if(hash1[i]%64) sum ++; //如果不能整除,则要多放一个格子
27                 cnt += sum/36, sum %= 36;//cnt记录总共要运多少次
28             }
29         }
30         if(sum) cnt ++; //如果sum没有整除,则要多运一次
31         printf("%d
", cnt);
32     }
33     return 0;
34 }
View Code
原文地址:https://www.cnblogs.com/loveprincess/p/4825209.html