马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
传送门:https://pintia.cn/problem-sets/994805342720868352/problems/994805419468242944
解:
队列#include<cstdio>
#include<queue>
using namespace std;
struct{
int weight, rank;
}mouse[1010];
int main(void)
{
int np, ng;
scanf("%d %d", &np, &ng);
queue<int> q;
for (int i = 0; i < np; i++)
scanf("%d", &mouse[i].weight);
for (int i = 0; i < np; i++)
{
int order;
scanf("%d", &order);
q.push(order);
}
int len;
while ((len = q.size()) > 1)
{
int group = (len % ng) ? (len / ng + 1) : (len / ng);
// printf("group = %d, ", group);
for (int i = 0; i < group; i++)
{
int winer = q.front();
for (int j = 0; j < ng && (i * ng + j) < len; j++)
{
mouse[q.front()].rank = group + 1;
if (mouse[q.front()].weight > mouse[winer].weight)
winer = q.front();
// printf("%d ", mouse[q.front()].weight);
q.pop();
}
q.push(winer);
}
// putchar('\n');
}
mouse[q.front()].rank = 1;
for (int i = 0; i < np; i++)
{
printf("%d", mouse[i].rank);
if (i < np - 1)
putchar(' ');
}
return 0;
}
|