满江红求条
查看原帖
满江红求条
1260978
xycsc23楼主2025/1/22 15:25

rt,所有数据都显示Wrong Answer.wrong answer Too short on line 1.,代码如下

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pr pair<int,int>
#define mr(x, y) make_pair((x), (y))
#define fi first
#define se second
inline int read(){
	int f=1, s=0;
	char c=getchar();
	while((c<'0' || c>'9') && c!='-')c=getchar();
	if(c=='-')
		f=-1, c=getchar();
	while(c>='0' && c<='9')s=s*10+c-'0', c=getchar();
	return f*s;
}
inline void pu(int x){
	if(x<0){
		putchar('-');
	    pu(-x);
	}
	else if(x<10)
		putchar(x+'0');
	else{
		pu(x/10);
		putchar(x%10+'0');
	}
}
struct cmd{
	int a;//进程号
	int b;//到达时间
	int c;//执行时间
	int d;//优先级
	bool operator()(cmd& x, cmd& y){
		if(x.d!=y.d)
			return x.d<y.d;
		return x.b>y.b;
	}
};
priority_queue<cmd, vector<cmd>, cmd> q;
signed main(){
	freopen("cin.txt", "r", stdin);
	int a, b, c, d, s=0;
	while(cin>>a>>b>>c>>d){
		priority_queue<cmd, vector<cmd>, cmd> q2;
		while(!q.empty()){
			int l=max(q.top().b, s)+q.top().c;
			if(l<=b){
				s=l;
				pu(q.top().a);putchar(' ');pu(s);putchar('\n');
			}
			else{
				q2.push((cmd){q.top().a, q.top().b, l-b, q.top().d});
				s=b;
			}
			q.pop();
		}
		q=q2;
		q.push((cmd){a, b, c, d});
	}
	while(!q.empty()){
		s=max(q.top().b, s)+q.top().c;
		pu(q.top().a);putchar(' ');pu(s);putchar('\n');
		q.pop();
	}
	return 0;
}
2025/1/22 15:25
加载中...