HUST 1341 A - A Simple Task(哈理工 亚洲区选拔赛练习赛)

             A - A Simple Task
Time Limit:1000MS    Memory Limit:131072KB    64bit IO Format:%lld & %llu

Description

As is known to all, lots of birds are living in HUST. A bird has s units of food on the first day, and eats k units of food each day. So they must find food in school or they will die. Because food is not that easy to find, birds store it home on the tree. If one bird runs out of food some day, he just dies. (It means that if the bird doesn't have enough food stored and can't find enough food that day, he will die.) A professor is researching on the birds. He has got some records of the birds' everyday life. And you, as his student, are to tell him the birds' state after the last day on the records of the bird.

Input

The first line is an integer, representing the number of test cases. In each case, the first line contains one integer n representing the number of records. The next line contains two integers -- s and k, representing the unit of food on the first day and the number of unit a bird needs each day. The next n lines, each contains a piece of record. The first word of each record is the name of a bird. You can assume that every bird has a distinct name and the name has no white space. The name has only alphabetical letters, i.e. A-Z and a-z. The following two integers is the date and the unit of food that the bird found on that day. (1<= n <=100000, the other integers are all greater than or equal to 1 and less than or equal to 10000.) Hint: the date of records may be disordered, but a bird's name will only appear once on each day. And the bird's name may appear even if he died before, so you can assume its the error in the records and just ignore it.

Output

Output "Case # t:" before each test case on a single line. For each test case, print out the name of all the birds and his food store, each bird a line. The output should be in alphabet order. If a bird died some day, you just tell the professor the bird was dead. The format is as the sample output. And you should check sample output for details. Output a blank line after each case.

Sample Input

3
3
100 3
Gaewah 4 3
Gaewah 10 5
Gaewah 100 1
1
5 10
Smith 1 3
4
10 5
peterpan 7 3
Oxford 3 5
Scheme 2 100
Regexp 1 10

Sample Output

Case #1:
Gaewah died.

Case #2:
Smith died.

Case #3:
Oxford 0
Regexp 15
Scheme 100
peterpan died.


这题目 细节上特别恶心人挂2发。

/*=============================================================================
#
#      Author: liangshu - cbam 
#
#      QQ : 756029571 
#
#      School : 哈尔滨理工大学 
#
#      Last modified: 2015-08-30 21:48
#
#     Filename: A.cpp
#
#     Description: 
#        The people who are crazy enough to think they can change the world, are the ones who do ! 
=============================================================================*/
#
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int INF = 100003;
struct A
{
    string str;
    int d, f;

} E[INF];

bool cmp(A a, A b)
{
    if(a.str == b.str)
        return a.d < b.d;
    return a.str < b.str;
}
int main()
{
    int t;
    cin>>t;
    int cs = 1;
    while(t--)
    {

        map<string,int>cnt;
        map<string,int >dict;
        int n, s, k;
        int dd,ff;
        string str;
        scanf("%d",&n);
        scanf("%d%d",&s, &k);
        for(int i = 0; i < n; i++)
        {
            cin>>str>>dd>>ff;
            E[i].str = str;
            E[i].d = dd;
            E[i].f = ff;
            cnt[str] = s;
            dict[str]++;
            //cout<<"E = "<<E[0].str<<endl;
        }
        sort(E, E + n, cmp);
        int i;
        for( i = 0; i < n; i++)
        {
            cnt[E[i].str] -= (E[i].d - 1) * k;
            if(cnt[E[i].str] >= 0)
            {
                cnt[E[i].str] += E[i].f;
                cnt[E[i].str] -= k;

                for(int j = 1; j < dict[E[i].str]; j++)
                {
                    int m = (E[i + j].d - E[i + j - 1].d - 1);

                    cnt[E[i].str] -=   m* k;


                    if(cnt[E[i].str]>= 0)
                    {

                        cnt[E[i].str] +=  E[i + j].f;
                        cnt[E[i].str] -= k;//cout<<"x =  "<<cnt[E[i].str]<<endl;

                    }
                }
            }
            i += dict[E[i].str];
        i -= 1;
        }

        printf("Case #%d:\n",cs++);
        for(int i =  0; i < n; i++)
        {
            //  cout<<"E[i].str = "<<E[i].str<<endl;
            if(cnt[E[i].str] < 0)
            {
                cout<<E[i].str<<" "<<"died."<<endl;
                cnt[E[i].str] = 1000000004;
            }
            else if(cnt[E[i].str] != 1000000004 )
            {
                cout<<E[i].str<<" "<<cnt[E[i].str]<<endl;
                cnt[E[i].str] = 1000000004;
            }
        }
        cout<<endl;
    }
    return 0;
}
/*
234
8
10 5
A 3 5
B 2 20
B 5 5
B 6 0
B 7 5
C 1 5
C 3 5
C 4 10

*/


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值