Effect:
There are n only bird each bird initial s food, every day eat K food
And I'm telling you, M Records represent some bird to find x food one day.
Analysis:
The simulation is a bit disgusting, so be careful.
Code:
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>Ten#include <map> One#include <vector> A#include <Set> -#include <sstream> - the using namespacestd; - - Const intMAXN =100005; - structB { + stringname; - intx, y; + }B[MAXN]; A BOOLCMP (b A, b b) { at if(A.name! =b.name) { - returnA.name <B.name; - } - if(a.x! = b.x)returnA.x <b.x; - } - in intMain () - { to intT, N, S, K; + //freopen ("A.txt", "R", stdin); -scanf"%d",&t); the for(intKase =1; Kase <= t; kase++) { *scanf"%d",&n); $scanf"%d%d", &s, &k);Panax Notoginseng for(inti =0; I < n; i++) { -CIN >> B[i].name >> b[i].x >>b[i].y; the } +Sort (b, B +N, CMP); A the //for (int i = 0; i < n; i++) { + //cout << b[i].name << "<< b[i].x <<" << b[i].y << Endl; - //}puts (""); $ $printf"Case #%d:\n", Kase); - BOOLFlag =true; - stringNA = b[0].name; the intZong =s; - intShang =1;Wuyi for(inti =0; I <= N; i++){ the if(b[i].name! = NA | | i = =N) { - if(Flag = =false) { Wucout << B[i-1].name <<"died."<<Endl; -}Else { Aboutcout << B[i-1].name <<" "<< Zong <<Endl; $ } -Flag =true; -Zong =s; -Shang =1; AZong = Zong-(b[i].x-shang) *K; + if(Zong <0) { theFlag =false; -}Else { $Zong + =b[i].y; theZong-=K; the if(Zong <0) { theFlag =false; the } - } inShang = b[i].x +1; theNa =B[i].name; the if(Zong <0) { AboutFlag =false; the } the}Else { the if(I >0&& B[i].name = = B[i-1].name && b[i].x = = B[i-1].x) { +Zong + =b[i].y; - } theZong = Zong-(b[i].x-shang) *K;Bayi if(Zong <0) { theFlag =false; the}Else { -Zong + =b[i].y; -Zong-=K; the if(Zong <0) { theFlag =false; the } the } -Shang = b[i].x +1; the } the}puts (""); the }94 return 0; the}View Code
hust1341a simple Task "simulation"