1 条题解
-
0
Guest
-
1
思路
模拟题,定义一个结构体。 如果是地铁,直接加费用,把最晚使用时间设置成当前时间 。 否则从头开始,扫描可用的:
- 如果有可用的,已使用标记为 ,免票。
- 否则该花多少钱还是多少钱。
其实没必要从头枚举,因为有太多无用的。可以模拟队列,过期的直接扔掉。
code
#include<bits/stdc++.h> using namespace std; struct ticket{ int price; int Lastttime; bool BeUsed;/赠票的价格,最晚使用时间和是否用过 }; int cost,type,ttime,n,tot; ticket q[100005]; int l,r; int main(){ ios::sync_with_stdio(0);//加快输入输出 cin.tie(0); cin>>n; for(int i=0;i<n;i++){ cin>>type>>cost>>ttime; if(type==0){//如果地铁,直接加 tot+=cost; q[r].Lastttime=ttime+45; q[r].price=cost; r++; }else{ while(l<r&&q[l].Lastttime<ttime) l++;//模拟队列,过期了就扔掉 bool pay=1;//是不是要花钱 for(int j=l;j<r;j++){ if(q[j].price<cost==0&&!q[j].BeUsed){//符合条件 pay=0;//不用花钱 q[j].BeUsed=1;//已使用 break; } } tot+=pay*cost; } } cout<<tot; return 0; }
- 1
信息
- ID
- 515
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 2
- 已通过
- 2
- 上传者