社区讨论
20分求助 #1 3AC
P2278[HNOI2003] 操作系统参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lo9jppvb
- 此快照首次捕获于
- 2023/10/28 12:32 2 年前
- 此快照最后确认于
- 2023/10/28 12:32 2 年前
貌似是 t 出问题了
CPP#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
struct node
{
int num;
int st;
int nt;
int u;
friend bool operator < (const node x,const node y)
{
if(x.u != y.u)
return x.u < y.u;
else
return x.st > y.st;
}
};
node x;
priority_queue<node> q;
signed main()
{
cin>>x.num >>x.st >> x.nt >> x.u;
// cout<<x.num<<" "<<x.st << " "<<x.u<<"\n";
q.push(x);
t = x.st;
while(cin>>x.num>>x.st>>x.nt>>x.u)
{
if(q.top().nt+t <= x.st)
{
cout<<q.top().num<<" "<<q.top().nt+t<<endl;
t +=q.top().nt;
q.pop();
}
if(!q.empty())
{
node y =q.top();
q.pop();
y.nt =y.nt - x.st + t;
y.nt = max(0LL , y.nt);
q.push(y);
}
// cout<<"time:"<<t;
q.push(x);
t = x.st;
// cout<<"->"<<t<<endl;
}
while(!q.empty())
{
node y = q.top();
// cout<<"time:"<<t;
t+=y.nt;
// cout<<"->"<<t<<endl;
cout<<y.num <<" "<<t<<"\n";
q.pop();
}
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...