时间限制
30 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a FatMouse.

First the playing order is randomly decided for NP programmers. Then every NG programmers are grouped in a match. The fattest mouse in a group wins and enters the next turn. All the losers in this turn are ranked the same. Every NGwinners are then grouped in the next match until a final winner is determined.

For the sake of simplicity, assume that the weight of each mouse is fixed once the programmer submits his/her code. Given the weights of all the mice and the initial playing order, you are supposed to output the ranks for the programmers.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers: NP and NG (<= 1000), the number of programmers and the maximum number of mice in a group, respectively. If there are less than NG mice at the end of the player's list, then all the mice left will be put into the last group. The second line contains NP distinct non-negative numbers Wi (i=0,...NP-1) where each Wiis the weight of the i-th mouse respectively. The third line gives the initial playing order which is a permutation of 0,...NP-1 (assume that the programmers are numbered from 0 to NP-1). All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the final ranks in a line. The i-th number is the rank of the i-th programmer, and all the numbers must be separated by a space, with no extra space at the end of the line.

Sample Input:

11 3
25 18 0 46 37 3 19 22 57 56 10
6 0 8 7 10 5 9 1 4 2 3

Sample Output:

5 5 5 2 5 5 5 3 1 3 5
 #include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std; struct MyStruct
{
int ID;
int wight;
}; struct MyRank
{
int time;
int ID;
}; vector<MyRank> ranking; void fun(vector<MyStruct> vv ,int Ng)
{
vector<MyStruct> tem;
for(int i = ;i< vv.size(); i++)
{
if( i + Ng - < vv.size())
{
int MAX = -;
int index;
int j;
for(j = i ;j < i + Ng ;j++)
{
if(vv[j].wight > MAX)
{
MAX = vv[j].wight;
index = j;
}
}
i = j-;
tem.push_back(vv[index]);
++ranking[vv[index].ID].time;
}
else
{
int MAX = -;
int index;
int j;
for(j = i ;j < vv.size() ;j++)
{
if(vv[j].wight > MAX)
{
MAX = vv[j].wight;
index = j;
}
}
i = j;
tem.push_back(vv[index]);
++ranking[vv[index].ID].time;
}
} if(tem.size() > )
fun(tem,Ng);
} int cmp(MyRank a,MyRank b)
{
return a.time > b.time ;
} int main()
{
int Np,Ng,i;
MyStruct tem;
MyRank Rtem;
int index;
scanf("%d%d",&Np,&Ng);
vector<MyStruct> v1,v2;
for(i = ;i< Np ;i++)
{
scanf("%d",&tem.wight);
tem.ID = i;
Rtem.ID = i;
Rtem.time = ;
ranking.push_back(Rtem);
v1.push_back(tem);
}
for(i = ;i< Np ;i++)
{
scanf("%d",&index);
v2.push_back(v1[index]);
} fun(v2,Ng); sort(ranking.begin(),ranking.end(),cmp);
int result[];
int j = ;
for(i = ;i <ranking.size();i++)
{
result[ranking[i].ID] = j;
int count = ;
int tem = ranking[i].time;
while(i+ <ranking.size()&&tem == ranking[i+].time)
{
++i;
++ count;
result[ranking[i].ID] = j;
}
j = j+count;
} for(i = ;i < Np ;i++)
{
if(i == ) printf("%d",result[i]);
else printf(" %d",result[i]);
}
printf("\n");
return ;
}

1056. Mice and Rice (25)的更多相关文章

  1. pat 甲级 1056. Mice and Rice (25)

    1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...

  2. PAT 甲级 1056 Mice and Rice (25 分) (队列,读不懂题,读懂了一遍过)

    1056 Mice and Rice (25 分)   Mice and Rice is the name of a programming contest in which each program ...

  3. PAT Advanced 1056 Mice and Rice (25) [queue的⽤法]

    题目 Mice and Rice is the name of a programming contest in which each programmer must write a piece of ...

  4. 1056 Mice and Rice (25分)队列

    1.27刷题2 Mice and Rice is the name of a programming contest in which each programmer must write a pie ...

  5. PAT甲题题解-1056. Mice and Rice (25)-模拟题

    有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...

  6. PAT (Advanced Level) 1056. Mice and Rice (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  7. 【PAT甲级】1056 Mice and Rice (25 分)

    题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...

  8. pat1056. Mice and Rice (25)

    1056. Mice and Rice (25) 时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and ...

  9. PAT 1056 Mice and Rice[难][不理解]

    1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...

随机推荐

  1. Flask与Ajax

    这篇短文使用jquery. Flask提供一个很简单的方法来处理Ajax请求——在视图函数中用request的属性is_xhr来判断,如果是true则是异步请求. Jquery的$.getJSON() ...

  2. Syntax highlighter for CKEditor

    http://www.cnblogs.com/moozi/archive/2010/01/06/1640034.html

  3. Adobe Edge Animate –地球自转动画的实现,类似flash遮罩层的效果

    Adobe Edge Animate –地球自转动画的实现,类似flash遮罩层的效果 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 目前Edge的功能尚 ...

  4. LeetCode 213

    House Robber II Note: This is an extension of House Robber. After robbing those houses on that stree ...

  5. poj 1201 差分约束

    http://www.cnblogs.com/wangfang20/p/3196858.html 题意: 求集合Z中至少要包含多少个元素才能是每个区间[ai,bi]中的元素与Z中的元素重合个数为ci. ...

  6. 在Visual Studio 的 “一般处理程序 ” .ashx 文件中如何创建Session 对象

    只需要继承这个接口即可实现创建Session对象.  IHttpHandler,System.Web.SessionState.IHttpSessionState 代码示例: public class ...

  7. 运用NPOI操作EXCEL

    一.引入NPOI程序集 下载地址:http://pan.baidu.com/s/1qWI3Vgo 二.运用NPOI导出成excel文件 protected void btnOutExcel_Click ...

  8. 晒下自己App广告平台积分墙收入,顺便点评几个广告平台

    这是我之前发在爱开发App源码论坛的文章.分享了我从2011年到现在移动广告方面的收入和一些心得. 产品类型:FC.街机模拟器类App游戏 广告平台:万普世纪 广告形式:积分墙,用户先试玩几次,再玩需 ...

  9. JSP之Cookie

    Cookie是小段的文本信息,在网络服务器上生成,并发送给浏览器,通过使用cookie可以标识用户身份,记录用户名和密码,跟踪重复等. 首先创建index.jsp: <%@page import ...

  10. DOS批处理命令-if语句

    IF语句是批处理中执行的条件分歧处理. 批处理中,IF分歧的写法有好几种,接下来,我们来一个一个的分析IF语法的结构. 1.IF [NOT] ERRORLEVEL 番号 批处理命令 当ERRORLEV ...