题解
2025-07-20 19:36:14
发布于:上海
11阅读
0回复
0点赞
这题一看就是模拟,用结构体数组存每个优惠券是否有效,对应的地铁价格以及获得时间
乘坐公交车时更新结构体数组,还有一定记得用完的优惠券要改成无效!!!
(我因为没改无效全wa找了半天)
#include<iostream>
using namespace std;
struct node{
int time,pr;
bool is;
}o[100005];
int n;
int opt,p,t,cnt,ans;
int main(){
cin>>n;
while(n--){
cin>>opt>>p>>t;
if(opt==0){
ans+=p;
o[++cnt].is=true;
o[cnt].time=t;
o[cnt].pr=p;
}
else{
if(cnt!=0){
for(int i=1;i<=cnt;i++){
if(t-o[i].time>45) o[i].is=false;
}
bool flag=true;
for(int i=1;i<=cnt;i++){
if(o[i].is&&o[i].pr>=p){
o[i].is=false;
flag=false;
break;
}
}
if(flag) ans+=p;
}
}
//cout<<ans<<"\n";
}
cout<<ans;
}
这里空空如也
有帮助,赞一个