首页 > 其他分享 >Mice and Rice (25)

Mice and Rice (25)

时间:2022-10-17 01:00:24浏览次数:49  
标签:25 weight temp level int mmax Mice Rice rounds

题目描述

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.

输入描述:

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.


输出描述:

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.

输入例子:

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

输出例子:

5 5 5 2 5 5 5 3 1 3 5

tip:

1.因为数据量小我是直接正向模拟的,相当于暴力了

2.由于反转map的消耗比较大,所以使用反向迭代器reverse_iterator,相应的把头尾指针改为rbegin和rend

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int np,ng;
 4 int weight[1005];
 5 map<int,vector<int>> rounds;
 6 int ranks[1005];
 7 int counts=1;
 8 queue<int> initial;
 9 void match(queue<int> q,int level){ //正向进行比赛,level代表出局轮次
10     if (q.size()==1){ //当队列中只剩下一人时比赛结束
11         rounds[level].push_back(q.front());
12         return;
13     }
14     queue<int> next_turn;
15     while (!q.empty()){
16         int mmax=q.front();
17         for (int i=0;i<ng&&(!q.empty());++i){
18             int temp=q.front();
19             q.pop();
20             if (weight[temp]>=weight[mmax]){
21                 if (temp!=mmax)
22                     rounds[level].push_back(mmax);
23                 mmax=temp;
24             }
25             else
26                 rounds[level].push_back(temp);
27         }
28         next_turn.push(mmax);
29     }
30     return match(next_turn,level+1);
31 }
32 int main(){
33     cin>>np>>ng;
34     memset(weight,0,sizeof(weight));
35     memset(ranks,0,sizeof(ranks));
36     for (int i=0;i<np;++i){
37         cin>>weight[i];
38     }
39     int order;
40     for (int i=0;i<np;++i){
41         cin>>order;
42         initial.push(order);
43     }
44     match(initial,1);
45     //根据每轮淘汰的选手生成名次
46     map<int,vector<int>>::reverse_iterator m_it;
47     vector<int>::iterator v_it;
48     for (m_it=rounds.rbegin();m_it!=rounds.rend();++m_it){
49         vector<int> temp=m_it->second;
50         for (v_it=temp.begin();v_it!=temp.end();++v_it){
51             ranks[*v_it]=counts;
52         }
53         counts+=temp.size();
54     }
55     for (int i=0;i<np;++i){
56         cout<<ranks[i];
57         if (i!=np-1)
58             cout<<" ";
59     }
60 }

 


标签:25,weight,temp,level,int,mmax,Mice,Rice,rounds
From: https://www.cnblogs.com/coderhrz/p/16797733.html

相关文章

  • 爬虫实例——爬取豆瓣网 top250 电影的信息
    本节通过一个具体的实例来看下编写爬虫的具体过程。以爬取豆瓣网top250电影的信息为例,top250电影的网址为:​​https://movie.douban.com/top250​​​。在浏览器的地址栏......
  • 25_H.264编码
    本文主要介绍一种非常流行的视频编码:H.264。计算一下:10秒钟1080p(1920x1080)、30fps的YUV420P原始视频,需要占用多大的存储空间?(10*30)*(1920*1080)*1.5=93312......
  • AcWing1251 打击罪犯--并查集
    #include<bits/stdc++.h>#definepbpush_back#definefifirst#definesesecond#defineall(x)(x).begin(),(x).end()#defineSZ(x)(int)(x).size()usingnam......
  • 2022-2023-1 20221325 《计算机基础与程序设计》第七周学习总结
    作业信息这个作业属于那个班级:https://edu.cnblogs.com/campus/besti/2022-2023-1-CFAP作业要求:https://www.cnblogs.com/rocedu/p/9577842.html#WEEK03作业目标:学习......
  • Qt开发经验小技巧251-255
    今天在一个头文件中,发现#ifdefQ_OS_WIN#ifdefQ_CC_MSVC之类的都失效了,搞得差点怀疑人生了。经历过之前类似的教训后,排查原来是没有提前引入qglobal.h头文件导致的。......
  • 如何解决Navicat连接Mysql数据库时出现1251报错问题
    如何解决Navicat连接Mysql数据库时出现1251报错问题​​一、前言​​​​二、错误信息​​​​三、分析问题​​​​四、解决方法​​一、前言二、错误信息  用Navicat软......
  • 2022-09-25-打个小广告
    layout:postcid:30title:打个小广告slug:30date:2022/09/2519:25:00updated:2022/10/0217:00:07status:publishauthor:admincategories:默认分类tag......
  • 2022-08-25-网络改造寄寄寄
    layout:postcid:18title:网络改造寄寄寄slug:18date:2022/08/2513:49:02updated:2022/08/2513:49:02status:waitingauthor:admincategories:默认分类......
  • 2022-08-25-cdn套中套
    layout:postcid:19title:cdn套中套slug:19date:2022/08/2520:32:00updated:2022/08/2611:20:20status:waitingauthor:admincategories:默认分类tags......
  • 代码随想录训练营|Day 25|216,17
    216.CombinationSumIIIFindallvalidcombinationsof k numbersthatsumupto n suchthatthefollowingconditionsaretrue:Onlynumbers 1 through ......