标签:size push mice weight algorithm pop temp a10 include
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
struct node{
int weight, index0, index, rank;
};
bool cmp(node a, node b){
return a.index0 < b.index0;
}
int main(){
int n, g, num;
scanf("%d%d", &n, &g);
vector<int> v(n);
vector<node> w(n);
for(int i = 0; i < n; i++){
scanf("%d", &v[i]);
}
for(int i = 0; i < n; i++){
scanf("%d", &num);
w[i].weight = v[num];
w[i].index = i;
w[i].index0 = num;
}
queue<node> q;
for(int i = 0; i < n; i++){
q.push(w[i]);
}
while(!q.empty()){
int size = q.size();
if(size == 1){
node temp = q.front();
w[temp.index].rank = 1;
break;
}
int group = size / g;
if(size % g != 0){
group++;
}
node maxnode;
int cnt = 0, max = -1;
for(int i = 0; i < size; i++){
node temp = q.front();
w[temp.index].rank = group + 1;
q.pop();
cnt++;
if(temp.weight > max){
maxnode = temp;
max = temp.weight;
}
if(cnt == g || i == size - 1){
cnt = 0;
max = -1;
q.push(maxnode);
}
}
}
sort(w.begin(), w.end(), cmp);
for(int i = 0; i < n; i++){
if(i != 0) printf(" ");
printf("%d", w[i].rank);
}
return 0;
}
标签:size push mice weight algorithm pop temp a10 include
原文地址:https://www.cnblogs.com/tsruixi/p/12250845.html