zoukankan      html  css  js  c++  java
  • A1056. 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 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
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <string>
     8 #include <stack> 
     9 #include <queue>
    10 using namespace std;
    11 const int maxn=1010;
    12 struct mouse{
    13     int weight;
    14     int r;
    15 }mouse[maxn];
    16 
    17 
    18 
    19 int main(){
    20     int np,ng,order;
    21     scanf("%d %d",&np,&ng);
    22     for(int i=0;i<np;i++)
    23     {
    24         scanf("%d",&mouse[i].weight);
    25     }
    26     queue<int> q;
    27     for(int i=0;i<np;i++)
    28     {
    29         scanf("%d",&order);
    30         q.push(order);
    31     }
    32     int rnum=np,group;
    33     while(q.size()!=1)
    34     {
    35         if(rnum%ng==0)group=rnum/ng;
    36         else group=rnum/ng+1;
    37         for(int i=0;i<group;i++)
    38         {
    39             int k=q.front();
    40             for(int j=0;j<ng;j++)
    41             {
    42                 if(i*ng+j>=rnum)break;
    43                 int front=q.front();
    44                 if(mouse[k].weight<mouse[front].weight)
    45                 {
    46                     k=front;
    47                 }
    48                 mouse[front].r=group+1;
    49                 q.pop();
    50             }
    51             q.push(k);
    52         }
    53         rnum=group; 
    54     }
    55     mouse[q.front()].r=1;
    56     for(int i=0;i<np;i++)
    57     {
    58         printf("%d",mouse[i].r);
    59         if(i<np-1)printf(" ");
    60     }
    61     return 0;
    62 }
  • 相关阅读:
    Flask目录结构
    RHSA-2019:1880-低危: curl 安全和BUG修复更新 及 RHSA-2019:1884-中危: libssh2 安全更新
    ELK+Logback进行业务日志分析查看
    Maven编译过程中出现的问题
    Zabbix监控服务器磁盘I/O
    创建readonly只读用户脚本
    Zabbix监控多个JVM进程
    redis命令
    docker配置Nginx
    docker基本命令
  • 原文地址:https://www.cnblogs.com/ligen/p/4313685.html
Copyright © 2011-2022 走看看