您的位置:首页 > 产品设计 > UI/UE

1056.Mice and Rice (25)...to be continued...

2017-02-27 22:34 351 查看
1056.Mice and Rice (25)…to be continued…

pat-al-1056

2017-02-27

对于每个小组选出最大的那个,注意判断一轮的结束

用结构体保存rank

/**
* pat-al-1056
* 2017-02-27
* Cpp version
* Author: fengLian_s
*/
#include<stdio.h>
#include<queue>
#define MAX 1010
using namespace std;
struct MOUSE
{
int weight;
int rank;
}mouse[MAX];
int main()
{
freopen("in.txt", "r", stdin);
int np, ng;
scanf("%d%d", &np, &ng);
for(int i = 0;i < np;i++)
{
scanf("%d", &mouse[i].weight);
}
int index;
queue<int> q;
for(int i = 0;i < np;i++)
{
scanf("%d", &index);
q.push(index);
}
int tmp = np, group;
while(q.size() != 1)
{
if(tmp % ng == 0)
group = tmp / ng;
else
group = tmp / ng + 1;
for(int i = 0;i < group;i++)
{
int max = q.front();
for(int j = 0;j < ng;j++)
{
if(i * ng + j >= tmp)
break;
int front = q.front();
if(mouse[front].weight > mouse[max].weight)
max = front;
mouse[front].rank = group + 1;
q.pop();
}
q.push(max);
}
tmp = group;
}
mouse[q.front()].rank = 1;
printf("%d", mouse[0].rank);
for(int i = 1;i < np;i++)
{
printf(" %d", mouse[i].rank);
}
putchar('\n');
return 0;
}


-TBC-
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: