TLE90
查看原帖
TLE90
507892
fwl43223j楼主2021/5/16 18:53
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct p{
	int ID, score, ability;
};
int n, r, q;
vector<p> ps, win, lost;
bool cmp (p x, p y){
	if(x.score==y.score)
		return x.ID<y.ID;
	return x.score>y.score;
}
void merge(){
	ps.clear();
//	for(int i=0; i<win.size(); i++)
//		ps.push_back(win[i]), ps.push_back(lost[i]);
//	sort(ps.begin(), ps.end(), cmp);
	
	
	int w1=0, l1=0, wlen=win.size(), llen=lost.size();
	while(w1<wlen||l1<llen){
		if(w1>=wlen||l1<llen&&(lost[l1].score>win[w1].score||lost[l1].score==win[w1].score&&lost[l1].ID<win[w1].ID)) {
			ps.push_back(lost[l1]);
			l1++;
		}else{
			ps.push_back(win[w1]);
			w1++;
		}
	}
}
int main(){
	p t;
	cin>>n>>r>>q;
	for(int i=0; i<2*n; i++){
		cin>>t.score;
		t.ID=i+1;
		ps.push_back(t);
	}
	for(int i=0; i<2*n; i++)
		cin>>ps[i].ability;
	sort(ps.begin(), ps.end(), cmp);
	for(int i=1; i<=r; i++){
		win.clear(), lost.clear();
		for(int j=0; j<2*n; j+=2){
			if(ps[j].ability>ps[j+1].ability)
			{
				ps[j].score++;
				win.push_back(ps[j]);
				lost.push_back(ps[j+1]);
			}else{
				ps[j+1].score++;
				win.push_back(ps[j+1]);
				lost.push_back(ps[j]);
			}
		}
		merge();
	}
	cout<<ps[q-1].ID;
}

90分,哪里错了

2021/5/16 18:53
加载中...