Galactic Collegiate Programming Contest(结构体运算符重载,set)

13人阅读 评论(0) 收藏 举报
分类:

Galactic Collegiate Programming Contest
Problem ID: gcpc
Time limit: 6 seconds
Picture by GuillaumePreat on Pixabay, cc0
One hundred years from now, in 2117, the International
Collegiate Programming Contest
(of which the NCPC is a part) has expanded
significantly and it is now the Galactic Collegiate
Programming Contest (GCPC).
This year there are n teams in the contest.
The teams are numbered 1, 2, … , n, and your
favorite team has number 1.
Like today, the score of a team is a pair of
integers (a, b) where a is the number of solved
problems and b is the total penalty of that team.
When a team solves a problem there is some associated penalty (not necessarily calculated in
the same way as in the NCPC – the precise details are not important in this problem). The total
penalty of a team is the sum of the penalties for the solved problems of the team.
Consider two teams t1 and t2 whose scores are (a1, b1) and (a2, b2). The score of team t1 is
better than that of t2 if either a1 > a2, or if a1 = a2 and b1 < b2. The rank of a team is k + 1
where k is the number of teams whose score is better.
You would like to follow the performance of your favorite team. Unfortunately, the organizers
of GCPC do not provide a scoreboard. Instead, they send a message immediately whenever a
team solves a problem.
Input
The first line of input contains two integers n and m, where 1 ≤ n ≤ 105
is the number of teams,
and 1 ≤ m ≤ 105
is the number of events.
Then follow m lines that describe the events. Each line contains two integers t and p
(1 ≤ t ≤ n and 1 ≤ p ≤ 1000), meaning that team t has solved a problem with penalty p. The
events are ordered by the time when they happen.
Output
Output m lines. On the i’th line, output the rank of your favorite team after the first i events
have happened.
Sample Input 1 Sample Output 1
3 4
2 7
3 5
1 6
1 9
2
3
2
1
题目大意:
给出n个队伍,m次提交ac,每次有队伍名和罚时,问一号队伍排在第几名。注意:1, 2, 2, 2, 5也就是说,有队伍和题数和罚时一样的情况下,看id号。

思路:
用set存储排在1之前的队伍id,然后每次更新,如果是1队,则遍历一遍set,删除排在其之后的,如果是其他队伍,更新之后大于一队,直接insert队伍的id(set,不存在重复元素)

一:set < int >

#include <bits/stdc++.h>
using namespace std;
struct node
{
    int id;
    int t;
    int p;
    bool operator <(const node &a)const
    {
        if(t==a.t)
        {
            if(p==a.p)
            {
                return id>a.id;
            }
            else
            return p>a.p;
        }
        else
        return t<a.t;
    }
} w[123123];
set<int>q;
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    q.clear();
    for(int i=0; i<=n; i++)
    {
        w[i].p = 0;
        w[i].t = 0;
        w[i].id = i;
    }
    for(int i=0; i<m; i++)
    {
        int t, p;
        scanf("%d %d", &t, &p);
        w[t].t++;
        w[t].p+=p;
        if(t!=1)
        {
            if(w[1]<w[t])
            {
                q.insert(t);
            }
            cout<<q.size()+1<<endl;
        }
        else
        {
            set<int>::iterator it;
            for(it = q.begin();it!=q.end();)
            {
                if(w[*it]<w[1])
                {
                    q.erase(it++);
                }
                else
                    ++it;
            }
            cout<<q.size()+1<<endl;
        }
    }
    return 0;
}

二:set < node >

#include <bits/stdc++.h>
using namespace std;
struct node
{
    int id;
    int t;
    int p;
    bool operator == (const node &a)const
    {
        return id==a.id&&t==a.t&&p==a.p;
    }
    bool operator <(const node &a)const
    {
        if(t==a.t)
        {
            if(p==a.p)
                return id>a.id;
            else
                return p>a.p;
        }
        else
            return t<a.t;
    }
} w[123123];
set<node>q;
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    q.clear();
    for(int i=0; i<=n; i++)
    {
        w[i].p = 0;
        w[i].t = 0;
        w[i].id = i;
    }
    for(int i=0; i<m; i++)
    {
        int t, p;
        scanf("%d %d", &t, &p);
        set<node>::iterator it;
        if(t!=1)
        {
            if(q.find(w[t])!=q.end())
                q.erase(w[t]);
            w[t].t++;
            w[t].p+=p;
            if(w[1]<w[t])
                q.insert(w[t]);
            cout<<q.size()+1<<endl;
        }
        else
        {
              w[t].t++;
              w[t].p+=p;
              for(it=q.begin();it!=q.end();)
              {
                  if(*it<w[1])
                    q.erase(it++);
                  else
                    ++it;
              }
              cout<<q.size()+1<<endl;
        }
    }
    return 0;
}
查看评论

SpriteKit Programming Guide手游开发之(FAKE STICK HERO)

-
  • 1970年01月01日 08:00

2016 ACM Amman Collegiate Programming Contest 训练赛部分题解

【题目】题目可以在这里看:http://codeforces.com/gym/101102/problem/A 【A】Coins 【题意】在A,B两个大集合里面选子集使得他们的和为W,并且两个...
  • just_sort
  • just_sort
  • 2016-09-30 21:11:09
  • 1435

Gym 101572G Galactic Collegiate Programming Contest(离线 树状数组)

题意:ACM比赛每个队伍的分数由(a, b)组成, a是做出题数, b是总罚时, 出题多的排名前, 相同题量罚时少排名前, 如果题量罚时都相同, 排名一样, 例如, (1, 1), (1, 1), (...
  • CillyB
  • CillyB
  • 2017-10-19 22:35:04
  • 194

TOJ 3858 Home & GCPC 2015 D Carpets 小规模平铺类搜索

这里讨论一下小规模平铺类搜索的一种写法。 说明一下讨论的范围: 平铺:不允许重叠,将给出的一些方块(最容易处理的是长方形了)放置在一个目标区域内 小规模:要放置的方块数量...
  • fcxxzux
  • fcxxzux
  • 2015-09-27 01:11:18
  • 967

2015-2016 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2015) Goblin Garden Guards (数论)

题目大意:在第一象限内存在着n个黑点,然后同时存在着圆,求出不在圆内的个数 解题思路:本来这道题在数据很小的时候可以暴力去判,但是发现这个数据太大,所以需要进行优化和处理,我们枚举每个圆,找出这个圆...
  • qq_34826781
  • qq_34826781
  • 2017-08-02 17:03:44
  • 399

The 13th Zhejiang Provincial Collegiate Programming Contest - I People Counting

People Counting Time Limit: 2 Seconds      Memory Limit: 65536 KB In a BG (dinner gathering) for Z...
  • Turne
  • Turne
  • 2016-04-23 22:01:55
  • 453

2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16)

我带了大表(哥)? 两人组帮集训队测比赛,这场三星GYM做挂了。。。 GG然后看到q AK了。。。 当时熊神过了一大堆题,我才把A 过了。。。 然后熊神又过了一大堆题,我还没有做出J 。。。...
  • qq_24664053
  • qq_24664053
  • 2016-11-17 16:47:48
  • 750

2017 ACM Amman Collegiate Programming Contest

~这个队伍第一次组队赛是ccpc网赛,我全场梦游,由于我菜得抠脚,so导致打得跟什么一样,。。 然后这波cf是第二次组队赛,感觉还可以,虽然我...再次全场梦游,感觉自己一打组队赛就很迷,总是会想跟队...
  • qq_36124802
  • qq_36124802
  • 2017-08-26 23:24:18
  • 237

2015 ACM Amman Collegiate Programming Contest 简要题解。

抱LF巨巨和LC巨巨的大腿打了一场康复性训练。12题做了10题。。。然而水题一大堆。 讲讲简要题解。 A:两个关键字的结构体排序。 B:N^2的枚举,O(N)的计数,最后再加上前缀和的思想(N^2...
  • u011481752
  • u011481752
  • 2015-09-19 02:01:56
  • 538

2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16)【solved:9 / 11】

A - The game of Osho(SG函数) 题意:   有m堆石子,每堆有对应一个(Bi,Ni),表示这堆有Ni个石子,每次可以拿Bi^x个石子(1 思路:   请看Gym 101147A...
  • qq_29556211
  • qq_29556211
  • 2017-04-15 12:29:40
  • 804
    个人资料
    持之以恒
    等级:
    访问量: 5万+
    积分: 4003
    排名: 9741