题意:给出饭店来人的顺序与人数,按照三种类型去坐,如果等待时间超过半个小时,客人就会走,问最后能接待多少客人。
题解:大模拟!
View Code
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<queue> 5 using namespace std; 6 struct data 7 { 8 int t; 9 bool operator<(const data &ne)const 10 { 11 return t>ne.t; 12 } 13 data(){} 14 data(int _t){t=_t;} 15 }; 16 priority_queue<data> QA,QB,QC; 17 int main() 18 { 19 int A,B,C; 20 while(scanf("%d%d%d ",&A,&B,&C),A||B||C) 21 { 22 char s[100]; 23 int ans=0; 24 while(!QA.empty()) 25 QA.pop(); 26 while(!QB.empty()) 27 QB.pop(); 28 while(!QC.empty()) 29 QC.pop(); 30 while(gets(s),strcmp(s,"#")) 31 { 32 int t,n,k; 33 t=((s[0]-'0')*10+s[1]-'0')*60+(s[3]-'0')*10+s[4]-'0'; 34 n=s[6]-'0'; 35 if(n<3) 36 k=1; 37 else if(n<5) 38 k=2; 39 else 40 k=3; 41 switch(k) 42 { 43 case 1: 44 if(A) 45 { 46 A--; 47 ans+=n; 48 QA.push(data(t)); 49 } 50 else 51 { 52 data q=QA.top(); 53 if(q.t<=t) 54 { 55 ans+=n; 56 QA.pop(); 57 QA.push(data(max(q.t+30,t))); 58 } 59 } 60 break; 61 case 2: 62 if(B) 63 { 64 B--; 65 ans+=n; 66 QB.push(data(t)); 67 } 68 else 69 { 70 data q=QB.top(); 71 if(q.t<=t) 72 { 73 ans+=n; 74 QB.pop(); 75 QB.push(data(max(q.t+30,t))); 76 } 77 } 78 break; 79 case 3: 80 if(C) 81 { 82 C--; 83 ans+=n; 84 QC.push(data(t)); 85 } 86 else 87 { 88 data q=QC.top(); 89 if(q.t<=t) 90 { 91 ans+=n; 92 QC.pop(); 93 QC.push(data(max(q.t+30,t))); 94 } 95 } 96 break; 97 } 98 } 99 printf("%d\n",ans); 100 } 101 return 0; 102 }