题意:
给出第一天的时候鸟拥有的食物储量,给出鸟每天要吃的食物量,接下来有m组数据,每一行代表某只鸟在第几天的时候收获了多少食物,输出所有鸟在最后一次收获食物之后一天的状况(死了或者剩多少食物)。
思路:
模拟就好,队友打的,具体的细节看代码。
代码:
#include<cstdio>
#include<cstring>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<sstream>
using namespace std;
const int maxn = 100005;
struct B {
string name;
int x, y;
}b[maxn];
bool cmp(B a, B b) {
if(a.name != b.name) {
return a.name < b.name;
}
if(a.x != b.x) return a.x < b.x;
}
int main()
{
int t, n, s, k;
// freopen("a.txt","r",stdin);
scanf("%d",&t);
for(int kase = 1; kase <= t; kase++) {
scanf("%d",&n);
scanf("%d %d",&s, &k);
for(int i = 0; i < n; i++) {
cin >> b[i].name >> b[i].x >> b[i].y;
}
sort(b, b + n, cmp);
// for(int i = 0; i < n; i++) {
// cout << b[i].name << " " << b[i].x << " " << b[i].y << endl;
// }puts("");
printf("Case #%d:\n", kase);
bool flag = true;
string na = b[0].name;
int zong = s;
int shang = 1;
for(int i = 0; i <= n; i++){
if(b[i].name != na || i == n) {
if(flag == false) {
cout << b[i - 1].name << " died." << endl;
} else {
cout << b[i - 1].name << " " << zong << endl;
}
flag = true;
zong = s;
shang = 1;
zong = zong - (b[i].x - shang) * k;
if(zong < 0) {
flag = false;
} else {
zong += b[i].y;
zong -= k;
if(zong < 0) {
flag = false;
}
}
shang = b[i].x + 1;
na = b[i].name;
if(zong < 0) {
flag = false;
}
} else {
if(i > 0 && b[i].name == b[i - 1].name && b[i].x == b[i - 1].x) {
zong += b[i].y;
}
zong = zong - (b[i].x - shang) * k;
if(zong < 0) {
flag = false;
} else {
zong += b[i].y;
zong -= k;
if(zong < 0) {
flag = false;
}
}
shang = b[i].x + 1;
}
}puts("");
}
return 0;
}