码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-30 23:13:57      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:acm   算法   编程   哈理工   hust   

             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

*/


版权声明:本文为博主原创文章,未经博主允许不得转载。

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

标签:acm   算法   编程   哈理工   hust   

原文地址:http://blog.csdn.net/lsgqjh/article/details/48109557

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!