Description
Input
Output
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(哈理工 亚洲区选拔赛练习赛)
原文地址:http://blog.csdn.net/lsgqjh/article/details/48109557