zoukankan      html  css  js  c++  java
  • Codeforces Round #346 (Div. 2)B. Qualifying Contest

    地址:http://codeforces.com/problemset/problem/659/B

    题目:

    B. Qualifying Contest
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.

    The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.

    Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.

    Input

    The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 10 000, n ≥ 2m) — the number of participants of the qualifying contest and the number of regions in Berland.

    Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).

    It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.

    Output

    Print m lines. On the i-th line print the team of the i-th region — the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.

    Examples
    input
    5 2
    Ivanov 1 763
    Andreev 2 800
    Petrov 1 595
    Sidorov 1 790
    Semenov 2 503
    output
    Sidorov Ivanov
    Andreev Semenov
    input
    5 2
    Ivanov 1 800
    Andreev 2 763
    Petrov 1 800
    Sidorov 1 800
    Semenov 2 503
    output
    ?
    Andreev Semenov
    Note

    In the first sample region teams are uniquely determined.

    In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.

     思路:其实就是考排序,先对区域排序,每一区域内对成绩排序;只要第二名和第三名(第三名存在)分数不同就可以选出来

      此题有cha点,第三名可能不存在,,,比赛时被hack了,还好又马上改对了==

      上代码:

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 #include <cmath>
     5 #include <cstring>
     6 #include <queue>
     7 #include <stack>
     8 #include <map>
     9 #include <vector>
    10 
    11 using namespace std;
    12 struct stu
    13 {
    14         char name[12];
    15         int team;
    16         int score;
    17 };
    18 bool cmp (stu a, stu b)
    19 {
    20         if (a.team == b.team)
    21         {
    22                 return a.score > b.score;
    23         }
    24         return a.team < b.team;
    25 }
    26 struct stu st[100010];
    27 int main (void)
    28 {
    29         int n, m;
    30         cin >> n >> m;
    31         for (int i = 0; i < n; i++)
    32         {
    33                 scanf("%s %d %d", st[i].name, &st[i].team, &st[i].score);
    34         }
    35         sort(st, st + n, cmp);
    36         for (int i = 0; i < n; i++)
    37         {
    38                 if (i + 2 < n)
    39                 {
    40                         if (st[i + 1].score != st[i + 2].score || st[i+1].team != st[i+2].team)
    41                         {
    42                                 printf("%s %s
    ", st[i].name, st[i + 1].name);
    43                         }
    44                         else
    45                         {
    46                                 cout << "?" << endl;
    47                         }
    48                 }
    49                 else
    50                 {
    51                         printf("%s %s
    ", st[i].name, st[i + 1].name);
    52                 }
    53                 while (st[i].team == st[i + 1].team && i < n-1)
    54                 {
    55                         i++;
    56                 }
    57         }
    58         return 0;
    59 }
    View Code
  • 相关阅读:
    什么是Spring的IOC和DI
    2021年ACP考试复习笔记-云服务器ECS知识点及练习
    个人站点搭建完成啦,欢迎前来参观~
    准备一台标准服务器(模版机)!
    正则表达式几个常用的特殊字符!
    Shell的几个重点工具
    Shell入门,关于语法的一些简单玩意儿
    Mysql for Linux的安装以及远程访问
    在学到MySQL索引时,涉及到了B树和B+树.聊一聊
    Linux的一些问题的处理(重要目录,/配置静态IP/主机名/hosts映射)
  • 原文地址:https://www.cnblogs.com/weeping/p/5352168.html
Copyright © 2011-2022 走看看