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
  • 相关阅读:
    mac安装protobuf2.4.1时报错./include/gtest/internal/gtest-port.h:428:10: fatal error: 'tr1/tuple' file not found和google/protobuf/message.cc:175:16: error: implicit instantiation of undefined template
    java基础六 [异常处理](阅读Head First Java记录)
    安装和使用iOS的包管理工具CocoaPods
    Node.js的知识点框架整理
    java基础五 [数字与静态](阅读Head First Java记录)
    java基础四 [构造器和垃圾回收](阅读Head First Java记录)
    Appium学习路-安装篇
    Dell笔记本Ubuntu无线网卡驱动安装
    Ubuntu系统使用命令禁用触摸板等输入设备
    linux(ubuntu) 查看系统设备信息
  • 原文地址:https://www.cnblogs.com/weeping/p/5352168.html
Copyright © 2011-2022 走看看