UVa - 12450 - SpaceRecon Tournament

先上題目:ios

Problem G: SpaceRecon Tournament

SpaceRecon, the hottest game of 2011, is a real-time strategy thriller where players control your armies to destroy their opponent. Players may choose from one of the three available races -- Xurks (biological), Protoast (technological), and Earthians (humanoids) -- to build their respective armies by collecting resources from the land and spending them on army units, upgrades, and infrastructure. The player who destroys or outlasts their opponent is victorious.web

The game has an intricate single-player story mode where players recreate scenes of the survival of Earthian Commander John Rainard's travels through the Xurkling planet, and also the charades of once-Earthian-now-Xurkling Queen Stephanie Karpenter. After completing the 15 hours of single player gameplay, most users try their hand at multiplayer head-to-head battles online using Actionweb, the number one SpaceRecon game matching hub.ide

Actionweb hosts tournaments of 2^M players and publishes the results of each tournament by listing each player handle and the number of match victories in the tournament. Tournaments are series of head-to-head matches between two players, the winner of the round advancing to the next round. The first R rounds are best of three (i.e., win two matches to win the round, any unnecessary games are not played), the remaining rounds are best of five (i.e., win three matches to win the round, any unnecessary games are not played). Each tournament has a different value of R, but is not published.ui

Input Format

The first line is an integer N (1 <= N <= 100), the number of test cases, which follow. Each test case begins with a line containing an integer M (1 <= M <= 10). The following 2^M lines are of format "player_handle number_of_match_victories". Player handles are alphanumeric and between 1 and 16 characters long.spa

You may assume that the data provided describes a valid tournament.code

Output Format

Print the player handles sorted in descending order of which round they survived to. For players who survived the same number of rounds, sort them lexicographically by player handle.orm

Sample Input

1
2
John 1
Jake 5
Joe 4
Jane 0

Sample Output

Jake
Joe
Jane
John

  題意:給你2^m個選手的比賽勝利狀況,這2^m個選手進行挑戰賽,問最終按照進行比賽的round數來排序輸出,若是round數相同的就按照字典序輸出。其中一個round有可能三局兩勝有可能五局三勝。(前R場三局兩勝,剩下的五局三勝)
  說實話第一次讀題意的時候徹底看不懂,看了好幾回纔看懂,比賽的時候以爲應該枚舉R,由於m最大隻有10,換而言之挑戰賽構成的樹最深只有10層,因此直接枚舉R,若是有合法的狀態就輸出。結果不夠時間敲,賽後聽題解說的是R實際上是肯定的不須要枚舉。
  剛纔用本身的想法實現了一下,WA了主要仍是沒有肯定R。其實分析一下能夠發現,對於全部的人,明顯勝利場數最多的人一定是冠軍(樹根)他的round數絕對是最多的,而後就是勝利場數稍微少一點的絕對是比冠軍少一round,而後繼續這樣推下去就能夠發現若是咱們先按照勝利場數推下去的話咱們能夠發現,場數多的絕對是round數多,每一次咱們能夠肯定2^i我的排在前面,最後就能將2^m的人都排好。

上代碼:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 #include <cstring>
 5 #include <utility>
 6 #include <vector>
 7 #include <queue>
 8 #include <algorithm>
 9 #define MAX 102
10 using namespace std;
11 
12 typedef pair<int,string> pii;
13 pii p;
14 vector<pii> u;
15 int m;
16 
17 bool cmp0(pii x,pii y){
18     return x.first==y.first ? x.second<y.second : x.first>y.first;
19 }
20 
21 bool cmp1(pii x,pii y){
22     return x.second<y.second;
23 }
24 
25 int main()
26 {
27     int t,n;
28     //freopen("data.txt","r",stdin);
29     ios::sync_with_stdio(false);
30     cin>>t;
31     while(t--){
32       cin>>m;
33       n=1<<m;
34       u.clear();
35       for(int i=0;i<n;i++){
36         cin>>p.second>>p.first;
37         u.push_back(p);
38       }
39       sort(u.begin(),u.end(),cmp0);
40       int bound=1;
41       for(vector<pii>::iterator it=u.begin()+1;it!=u.end();bound<<=1){
42             sort(it,it+bound,cmp1);
43             it=it+bound;
44       }
45       for(vector<pii>::iterator it=u.begin();it!=u.end();it++){
46           cout<<(*it).second<<endl;
47       }
48     }
49     return 0;
50 }
/*12450*/
相關文章
相關標籤/搜索