hdu5463 Clarke and minecraft(BestCoder Round #56 (div.2) )

Clarke and minecraft

Accepts: 414
Submissions: 738
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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(1T10) , 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(1a,b500) , 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
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;
 
   
题意:给n种材料,每种材料数量为b;一个背包有36个格子,一个格子能装同种类型材料64个;求需要几次才能将材料运完。
分析:按材料种类排序,计算出每种材料需要几个格子就OK了。(之前的代码呗重判WA,很抱歉,很尴尬,不过已经修正了,现在是可以AC的,这里再次说声抱歉)
 
   

<pre name="code" class="cpp">#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a) memset(a,0,sizeof(a))

struct node
{
    int a,b;
}f[110];

int cmp(node c, node d)
{
    return c.a<d.a;
}

int main ()
{
    int T,n;
    cin>>T;
    while (T--)
    {
        cin>>n;
        for (int i=0; i<n; i++)
        {
            cin>>f[i].a>>f[i].b;
        }
        sort(f, f+n, cmp);
        f[n].a=99999;f[n].b=99999;
        int k=f[0].a,sum=0,ans=0;
        for (int i=0; i<=n; i++)
        {
            if (f[i].a==k)
                sum+=f[i].b;
            else
            {
                ans+=sum/64;
                if (sum%64) ans++;

                k=f[i].a;
                sum=f[i].b;
            }
        }
        if (ans%36) ans=ans/36+1;//这里之前忘记判断了,直接输出ans/36是不行的,比如36的倍数
        else ans=ans/36;
        cout<<ans<<endl;
    }
    return 0;
}




 
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值