考点:模拟
注意:
1.测试用例的问题:该题不太好
若:
1 S 10:00
1 S 12:00
该如何处理?(是认为1 S 12:00为无效数据,还是为最新的有效数据?)
若:
1 S 10:00
1 E 12:00
1 E 13:00
该如何处理?(正常认为1 E 13:00为无效数据)
题目没有说清楚。
2.平均租船时间是四舍五入,而是始终上取整?
3.可能同一辆船多次借还。
网友讨论的结果中该题的样例测试:这个题AC的代码,S的时候不考虑该船的状态,两次S直接按最新的更新信息,只要S过,连续几次E都是有效的,完全没考虑船可不可借可不可换的状态。
#include<bits/stdc++.h>
using namespace std;
const int MAXSIZE=101;
struct E {
int start,end;
int s,e;
E() {
}
E(int start,int end,int s,int e):start(start),end(end),s(s),e(e) {
}
} boat[101];
set<int> ids;
int main() {
int id,h,min;
int cnt=0, sum=0;
char ch;
fill(boat,boat+101,E(0,0,0,0));
while(scanf("%d",&id)!=EOF) {
if(id==-1) {
break;
}
getchar();
scanf("%c",&ch);
scanf("%d:%d",&h,&min);
if(id==0) {
if(cnt!=0) {
cout<<cnt<<" "<<(int)(sum/(cnt*1.0)+0.5)<<endl;
} else {
cout<<"0 0"<<endl;
}
fill(boat,boat+101,E(0,0,0,0));
continue;
}
int t=h*60+min;
if(ch=='S') {
boat[id].s=1;
boat[id].start=t;
} else {
if(boat[id].s==1){
cnt++;
sum+=t-boat[id].start;
}
}
}
return 0;
}