Sample Input
2 3 2 33 3 33 2 33 10 5 467 6 378 7 309 8 499 5 320 3 480 2 444 8 391 5 333 100 499
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;
题意:有一个背包有36个格子 每个格子只能放一种物品,且最多只能放64个 问要多少次才能将物品运完
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
int p[1000];
const int inf = 0x3f3f3f3f;
int main()
{
int T,n,a,b;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(p,0,sizeof(p));
int tmax = 0;
for(int i = 1;i <= n;i++)
{
scanf("%d%d",&a,&b);
p[a] += b;
if(tmax < a)
tmax = a;
}
int ans = 0;
for(int i = 1;i <= tmax;i++)
{
if(p[i])
{
ans += p[i]/64;
if(p[i] % 64)
ans++;
}
}
if(ans % 36)
printf("%d\n",ans/36 + 1);
else
printf("%d\n",ans/36);
}
return 0;
}