标签:
大意:
有n只bird 每只bird初始有s个食物,每只每天吃k个食物
然后告诉你m条记录 代表某个bird某天找到x个食物
分析:
模拟 就是有点恶心,细心点就好了
代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<climits> 4 #include<cmath> 5 #include<cstdlib> 6 #include<iostream> 7 #include<algorithm> 8 #include<string> 9 #include<queue> 10 #include<map> 11 #include<vector> 12 #include<set> 13 #include<sstream> 14 15 using namespace std; 16 17 const int maxn = 100005; 18 struct B { 19 string name; 20 int x, y; 21 }b[maxn]; 22 bool cmp(B a, B b) { 23 if(a.name != b.name) { 24 return a.name < b.name; 25 } 26 if(a.x != b.x) return a.x < b.x; 27 } 28 29 int main() 30 { 31 int t, n, s, k; 32 // freopen("a.txt","r",stdin); 33 scanf("%d",&t); 34 for(int kase = 1; kase <= t; kase++) { 35 scanf("%d",&n); 36 scanf("%d %d",&s, &k); 37 for(int i = 0; i < n; i++) { 38 cin >> b[i].name >> b[i].x >> b[i].y; 39 } 40 sort(b, b + n, cmp); 41 42 // for(int i = 0; i < n; i++) { 43 // cout << b[i].name << " " << b[i].x << " " << b[i].y << endl; 44 // }puts(""); 45 46 printf("Case #%d:\n", kase); 47 bool flag = true; 48 string na = b[0].name; 49 int zong = s; 50 int shang = 1; 51 for(int i = 0; i <= n; i++){ 52 if(b[i].name != na || i == n) { 53 if(flag == false) { 54 cout << b[i - 1].name << " died." << endl; 55 } else { 56 cout << b[i - 1].name << " " << zong << endl; 57 } 58 flag = true; 59 zong = s; 60 shang = 1; 61 zong = zong - (b[i].x - shang) * k; 62 if(zong < 0) { 63 flag = false; 64 } else { 65 zong += b[i].y; 66 zong -= k; 67 if(zong < 0) { 68 flag = false; 69 } 70 } 71 shang = b[i].x + 1; 72 na = b[i].name; 73 if(zong < 0) { 74 flag = false; 75 } 76 } else { 77 if(i > 0 && b[i].name == b[i - 1].name && b[i].x == b[i - 1].x) { 78 zong += b[i].y; 79 } 80 zong = zong - (b[i].x - shang) * k; 81 if(zong < 0) { 82 flag = false; 83 } else { 84 zong += b[i].y; 85 zong -= k; 86 if(zong < 0) { 87 flag = false; 88 } 89 } 90 shang = b[i].x + 1; 91 } 92 }puts(""); 93 } 94 return 0; 95 }
标签:
原文地址:http://www.cnblogs.com/zhanzhao/p/4774026.html