zoukankan      html  css  js  c++  java
  • 1056 Mice and Rice (25 分)

    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 NG​​winners 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​​ (≤), 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​​ (,) 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 (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 <bits/stdc++.h>
     2 using namespace std;
     3 int n, m;
     4 struct Node
     5 {
     6     int val, pai, pos, pre;
     7     friend bool operator < (const Node &a,const Node &b){
     8         return a.pre < b.pre;
     9     }
    10 }node[1005];
    11 deque<Node> dq;
    12 vector<Node> v;
    13 int an[1005];
    14 
    15 int main(){
    16     cin >> n >> m;
    17     for(int i = 0; i < n; i++){
    18         cin >> an[i];
    19     }
    20     int x;
    21     for(int i = 0; i < n ; i++){
    22         cin >> x;
    23         node[i].val = an[x];
    24         node[i].pos = i;
    25         node[i].pre = x;
    26         dq.push_back(node[i]);
    27     }
    28     while(dq.size() != 1){
    29         int len = dq.size();
    30         int group = len/m + (len%m == 0?0:1) + 1;
    31         for(int i = 0; i < n&&i < len; i=i+m){
    32             int ma = -1, id = -1;
    33             v.clear();
    34             for(int j = i; j < n&&j < len&&j < i+m; j++){
    35                 if(ma < dq.front().val){
    36                     ma = dq.front().val;
    37                     id = dq.front().pos;
    38                 }
    39                 v.push_back(dq.front());
    40                 dq.pop_front();
    41             }
    42             for(int j = 0; j < v.size(); j++){
    43                 if(v[j].pos == id){
    44                     dq.push_back(v[j]);
    45                 }else{
    46                     node[v[j].pos].pai = group;
    47                 }
    48             }
    49         }
    50     }
    51     if(dq.size()==1)
    52         node[dq.front().pos].pai = 1;
    53     sort(node, node+n);
    54     for(int i = 0 ; i < n; i++)
    55         printf("%d%c", node[i].pai, i == n-1?'
    ':' ');
    56     return 0;
    57 }



  • 相关阅读:
    Android 按键消息处理Android 按键消息处理
    objcopy
    SQLite多线程读写实践及常见问题总结
    android动画坐标定义
    Android动画效果translate、scale、alpha、rotate
    Android公共库(缓存 下拉ListView 下载管理Pro 静默安装 root运行 Java公共类)
    Flatten Binary Tree to Linked List
    Distinct Subsequences
    Populating Next Right Pointers in Each Node II
    Populating Next Right Pointers in Each Node
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11187268.html
Copyright © 2011-2022 走看看