标签:include false scanf empty weight cst lse 等于 int
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int N = 1010;
queue<int> q;
int w[N];
int result[N];
int main(){
int np,ng;
scanf("%d%d",&np,&ng);
int weight;
int candidate;
for(int i = 0;i<np;i++){
scanf("%d",&weight);
w[i]=weight;
}
for(int i = 0;i<np;i++){
scanf("%d",&candidate);
q.push(candidate);
}
//contest
int tnp = np;
while(tnp!=1){//最后一场比赛就1人直接胜出
int time = tnp/ng;
int maxid;
if(tnp%ng!=0) time++;
for(int i = 0;i< time;i++ ){
if(q.empty()==false){
if(tnp%ng==0||i!=time-1){//可以整除+不能整除且i不等于最后一次contest
maxid = q.front();
q.pop();
for(int j = 1;j<ng;j++){
int temp = q.front();
q.pop();
if(w[temp] > w[maxid]){
result[maxid] = time+1;//失败者直接计分
maxid = temp;
}else{
result[temp] = time+1;//失败者直接计分
}
}
q.push(maxid);
}else{//不能整除且i等于最后一次contest
maxid = q.front();
q.pop();
for(int j = 1;j<tnp%ng;j++){
int temp = q.front();
q.pop();
if(w[temp] > w[maxid]){
result[maxid] = time+1;//失败者直接计分
maxid = temp;
}else{
result[temp] = time+1;//失败者直接计分
}
}
q.push(maxid);
}
}
}
tnp = time;//下轮比赛人数
}
//胜者记为1
result[q.front()] = 1;
//print
for(int i = 0;i<np;i++){
printf("%d",result[i]);
if(i!=np-1) printf(" ");
}
return 0;
}
标签:include false scanf empty weight cst lse 等于 int
原文地址:https://www.cnblogs.com/shuibeng/p/13593836.html