PAT (Advanced Level) Practise 1056 Mice and Rice (25)
来源:互联网 发布:剑灵天族女捏脸数据库 编辑:程序博客网 时间:2024/06/09 16:24
1056. Mice and Rice (25)
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 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
题意:给你n只老鼠的重量和它们的顺序,每轮m只一组,最后若有少于m只的也为一组,每组最重的进入下一轮,若有k只进入下一轮,则淘汰的都为k+1名,输出n只老鼠的排名
解题思路:用两个数组,一个用来记录老鼠进入下一轮前的顺序,一个用来记录老鼠进入下一轮后的顺序,然后每次进行交替即可
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int n, m;int a[1005],x1[1005],x2[1005],Rank[1005];int main(){while (~scanf("%d%d", &n, &m)){memset(Rank, 0, sizeof Rank);for (int i = 0; i < n; i++) scanf("%d", &a[i]);for (int i = 0; i < n; i++) scanf("%d", &x1[i]);int nn = n;while (n > 1){int k = n / m + ((n%m) ? 1 : 0),ma=-1,p=-1,cnt=0;for (int i = 0; i < n; i++){if (ma < a[x1[i]]) ma = a[x1[i]], p = i;if ((i%m == m - 1) || (i == n - 1)){x2[cnt++] = x1[p];int x = (i == n - 1 && i%m != m - 1) ? n - (k - 1)*m : m;for (int j = i; j >= i - x + 1; j--)if(j!=p) Rank[x1[j]] = k + 1;ma = -1, p = -1;}}n = k;for (int i = 0; i < n; i++) x1[i] = x2[i];}for (int i = 0; i < nn; i++)if (!Rank[i]) Rank[i] = 1;printf("%d", Rank[0]);for(int i=1;i<nn;i++) printf(" %d", Rank[i]);printf("\n");}return 0;}
- PAT (Advanced Level) Practise 1056 Mice and Rice (25)
- PAT (Advanced Level) Practise 1056 Mice and Rice (25)
- 1056. Mice and Rice (25)【模拟】——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1056(Mice and Rice)
- 【C++】PAT(advanced level)1056. Mice and Rice (25)
- 【PAT】【Advanced Level】1056. Mice and Rice (25)
- PAT (Advanced Level) 1056. Mice and Rice (25) 模拟比赛,用queue辅助
- PAT 1056-Mice and Rice (25)
- pat 1056 Mice and 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)
- jzoj 高中 3505——积木
- callback 回调
- 一些困惑和迷茫
- POJ 3121 The SetStack Computer 笔记
- Git版本控制详解
- PAT (Advanced Level) Practise 1056 Mice and Rice (25)
- Java 中 FileReader FileInputStream InputStreamReader BufferedReader之间的区别与作用
- MySQL数据库安装及配置详解
- mysql 5.7 主从配置实例
- Spring Batch 例子: 导入分隔符文件到数据库
- easyui edatagrid属性使用方法
- 【JZOJ2701】【GDKOI2012模拟02.01】矩阵
- HDU 1102 Constructing Roads 最小生成树
- 简单的计算器