PAT A1056. Mice and Rice (25)
来源:互联网 发布:程序员去汽车厂 编辑:程序博客网 时间:2024/06/05 20:16
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 Wi is 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 325 18 0 46 37 3 19 22 57 56 106 0 8 7 10 5 9 1 4 2 3Sample Output:
5 5 5 2 5 5 5 3 1 3 5
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <queue>#define Max 1111using namespace std;struct mouse{int Weight;int rank;}S[Max];int main(){int n,m;scanf("%d%d",&n,&m);for(int i=0;i<n;i++){scanf("%d",&S[i].Weight);}queue<int> q;int k;for(int i=0;i<n;i++){scanf("%d",&k);q.push(k);}k=n;while(q.size()!=1){int gr;if(k%m==0) gr=k/m;else gr=(k/m)+1;for(int i=0;i<gr;i++){int max = S[q.front()].Weight;int f=q.front();for(int j=0;j<m;j++){if(i*m+j>=k){break;}if(S[q.front()].Weight>max){max=S[q.front()].Weight;f=q.front();}S[q.front()].rank=gr+1;q.pop();}q.push(f);}k=gr;}S[q.front()].rank=1;for(int i=0;i<n;i++){printf("%d",S[i].rank);if(i<n-1) printf(" ");else printf("\n");}system("pause");return 0;}
- 【PAT】A1056. Mice and Rice (25)
- pat-a1056. Mice and Rice (25)
- PAT A1056. Mice and Rice (25)
- A1056. Mice and Rice (25)
- A1056. Mice and Rice (25)
- A1056. Mice and Rice (25)
- PAT A1056 Mice an Rice
- 1056. Mice and Rice (25)-PAT
- PAT 1056. Mice and Rice (25)
- PAT A 1056. Mice and Rice (25)
- PAT 1056. Mice and Rice (25)
- PAT 1056. Mice and Rice (25)
- 【PAT】1056. Mice and Rice (25)
- PAT 1016Mice and Rice (25)
- PAT(A) - 1056. Mice and Rice (25)
- 【PAT甲级】1056. Mice and Rice (25)
- 1056. Mice and Rice (25)PAT甲级
- PAT甲级1056. Mice and Rice (25)
- MDK环境下stm32实现printf函数
- 面试题16:反转链表
- [POJ]2739-Sum of Consecutive Prime Numbers
- ural1014 Product of Digits (枚举)
- 最小生成树---->prim算法的应用 hdu1863
- PAT A1056. Mice and Rice (25)
- ubuntu16.04忘记密码处理方法
- Codeforces Round #399 (Div. 1 + Div. 2, combined)C. Jon Snow and his Favourite Number
- 各项知识链接集合(比较杂)
- [HTC Vive + Unity开发]——VRTK的研究——用手柄旋转物体(使用VRTK_Knob脚本)
- TCP/IP 多播和多播路由
- bootstrap折叠调用collapse()后data-parent不生效问题
- csdn上第一篇博客
- 划重点