• Codeforces Round #113 (Div. 2) 166A. Rank List(二级排序)


    编辑器加载中...

    A. Rank List

    2 seconds

    256 megabytes

    Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.

    You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty timeta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb.

    It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that yteams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.

    Your task is to count what number of teams from the given list shared the k-th place.

    Input

    The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces.

    Output

    In the only line print the sought number of teams that got the k-th place in the final results' table.

    Sample test(s)

    input

    7 2
    4 10
    4 10
    4 10
    3 20
    2 1
    2 1
    1 10

    output

    3

    input

    5 4
    3 1
    3 1
    5 3
    3 1
    3 1

    output

    4

    Note

    The final results' table for the first sample is:

    • 1-3 places — 4 solved problems, the penalty time equals 10
    • 4 place — 3 solved problems, the penalty time equals 20
    • 5-6 places — 2 solved problems, the penalty time equals 1
    • 7 place — 1 solved problem, the penalty time equals 10

    The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.

    The final table for the second sample is:

    • 1 place — 5 solved problems, the penalty time equals 3
    • 2-5 places — 3 solved problems, the penalty time equals 1

    The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.

     解题报告:昨天晚上没有做这个比赛,现在做了一下,哎!还是自己的英语差呀!k是排完序以后的编号,题意就是统计一下排完序和第k个分数和时间一样的个数,先按p从大到小排序再t从小到大排序,最后再统计即可!

    代码如下:

    #include <iostream>
    #include <cstdio>
    using namespace std;
    const int MAX = 110;
    struct node
    {
    int p;
    int t;
    }a[MAX];
    int cmp(const void *a, const void *b)//先按p从大小排序,p相同时按t从小到大排序
    {
    struct node *c = (struct node *)a;
    struct node *d = (struct node *)b;
    if (c->p != d->p) return d->p - c->p;
    else return c->t - d->t;
    }
    int main()
    {
    int k, n, i, ans;
    scanf("%d%d", &n, &k);
    for (i = 0; i < n; ++i)
    {
    scanf("%d%d", &a[i].p, &a[i].t);
    }
    qsort(a, n, sizeof(a[0]), cmp);
    ans = 0;
    int flag1 = a[k - 1].p;//注意这儿是k-1,因为是从零开始存的
    int flag2 = a[k - 1].t;
    for (i = 0; i < n; ++i)
    {
    if (a[i].p == flag1 && a[i].t == flag2)
    {
    ans ++;
    }
    }
    printf("%d\n", ans);
    return 0;
    }



  • 相关阅读:
    Three.js中引入dat.gui库实现界面组件控制动画速度变量
    Three.js中使用requestAnimationFrame方法实现立方体转动和小球跳动的动画
    Windows下使用Java API操作HDFS的常用方法
    Windows下配置Hadoop的Java开发环境以及用Java API操作HDFS
    HDFS的访问方式之HDFS shell的常用命令
    CentOS7上搭建Hadoop集群(入门级)
    CentOS7中怎样安装JDK与配置环境变量
    【2021-08-05】哪怕天踏下来,也要当被子盖
    【2021-08-04】连岳摘抄
    【2021-08-03】里程碑
  • 原文地址:https://www.cnblogs.com/lidaojian/p/2416301.html
Copyright © 2020-2023  润新知