CSP-J 2020 T2求助
查看原帖
CSP-J 2020 T2求助
781241
Purrbyte楼主2023/10/13 22:31

各位大佬,我的代码得了0分,但是看了半天不知道哪里错了,请各位大佬帮我一下吧。

#include <iostream>
#include <queue>
using namespace std;
struct ticket
{
	int price,time;
};
queue <ticket> subway;
queue <ticket> bus;
int main()
{
	int n,ans = 0;
	cin >> n;
	while(n--)
	{
		int f,p,t;
		cin>>f>>p>>t;
		ticket now;
		now.price = p;
		now.time = t;
		if(f == '0')
		{
			subway.push(now);
			ans += now.price;
		}
		else
		{
			bus.push(now);
			ticket after;
			bool free = false;
			while(!subway.empty())
			{
				after = subway.front();
				subway.pop();
				if(now.time - after.time <= 45 && now.price <= after.price)
				{
					free = true;
					break;
				}
			}
			if(!free)
				ans += now.price;
		}
	}
	cout << ans;
	return 0;
}
2023/10/13 22:31
加载中...