HDU5463 Clarke and minecraft

时间:2023-03-09 16:54:08
HDU5463 Clarke and minecraft

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

       具体见代码分析。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
int hash1[maxn]; //标记对应类型总共出现了多少个。
int main()
{
int t, n, a, b, sum, cnt;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(hash1, , sizeof(hash1));
while(n--)
{
scanf("%d %d", &a, &b);
hash1[a] += b; //hash1标记对应类型共出现多少个
}
sum = cnt = ;
for(int i = ; i <= ; i++) //因为a和b的取值范围都为500
{
if(hash1[i]) //如果出现过
{
sum += hash1[i]/; //sum记录总共要装多少个格子
if(hash1[i]%) sum ++; //如果不能整除,则要多放一个格子
cnt += sum/, sum %= ;//cnt记录总共要运多少次
}
}
if(sum) cnt ++; //如果sum没有整除,则要多运一次
printf("%d\n", cnt);
}
return ;
}