【set】Gym - 101572G Galactic Collegiate Programming Contest

Step1 Problem:

n个队伍,m个时刻。
每个时刻给你两个数 t p。该时刻 t 队伍AC一道题 罚时 p。
按解题数越高越前,解题数一样罚时越少越前,都一样的情况下1队伍一定是第一。
输出各个时刻1队伍的排名
例:
3 4
2 7
3 5
1 6
1 9
输出:
2
3
2
1
数据范围:
1<=n, m<=1e5, 1<=t<=n, 1<=p<=1000.

Step2 Involving algorithms:

STL set

Step3 Ideas:

set维护排名在1前面的队伍
该时刻其他队伍AC,如果该队伍在set里,删除。更新后如果比1排名前,插入
该时刻1队伍AC,将比1队伍排名后的全删除。
对于每个时刻输出set的大小。

Step4 Code:

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
struct node
{
    int id, data, num;
    bool operator < (const node &b) const {
        if(num == b.num && data == b.data) return id < b.id;
        else if(num == b.num)
        return data < b.data;
        else return num > b.num;
    }
//    bool operator == (const node &b) const {
//        if(id == b.id && data == b.data && num == b.num) return 1;
//        else return 0;
//    }
};
int vis[N], sol[N];
int main()
{
    int n, m;
    while(~scanf("%d %d", &n, &m))
    {
        memset(vis, 0, sizeof(vis));
        memset(sol, 0, sizeof(sol));
        set<node> q;
        set<node>::iterator it;
        int team, num;
        while(m--)
        {
            scanf("%d %d", &team, &num);
            it = q.find((node){team, vis[team], sol[team]});
            if(it != q.end())
                q.erase(it);
            vis[team] += num;
            sol[team]++;
            node t1 = (node){1, vis[1], sol[1]};
            node t2 = (node){team, vis[team], sol[team]};
            if(team != 1)
            {
                if(t2 < t1)
                q.insert((node){team, vis[team], sol[team]});
            }
            else
            {
                while(!q.empty() && (t1 < *(--q.end())))
                {
                    q.erase(--q.end());
                }
            }
            printf("%d\n", q.size()+1);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Combining knowledge with strategies, Data Structure Practice for Collegiate Programming Contests and Education presents the first comprehensive book on data structure in programming contests. This book is designed for training collegiate programming contest teams in the nuances of data structure and for helping college students in computer-related majors to gain deeper understanding of data structure. Based on successful experiences in many world-level contests, the book includes 204 typical problems and detailed analyses selected from the ACM International Collegiate Programming Contest and other major programming contests since 1990. It is divided into four sections that focus on: Fundamental programming skills Experiments for linear lists Experiments for trees Experiments for graphs Each chapter contains a set of problems and includes hints. The book also provides test data for most problems as well as sources and IDs for online judgments that help with improving programming skills. Introducing a multi-options model and considerations of context, Data Structure Practice for Collegiate Programming Contests and Education encourages students to think creatively in solving programming problems. By taking readers through practical contest problems from analysis to implementation, it provides a complete source for enhancing understanding and polishing skills in programming. Table of Contents Section I: Fundamental Programming Skills Chapter 1: Practice for Simple Computing Chapter 2: Simple Simulation Chapter 3: Simple Recursion Section II: Experiments for Linear Lists Chapter 4: Linear Lists Accessed Directly Chapter 5: Applications of Linear Lists for Sequential Access Chapter 6: Generalized List Using Indexes Chapter 7: Sort of Linear Lists Section III: Experiments for Trees Chapter 8: Programming by Tree Structure Chapter 9: Applications of Binary Trees Chapter 10: Applications of Classical Trees Section IV: Experiments for Graphs Chapter 11: Applications of Graph Traversal Chapter 12: Algorithms of Minimum Spanning Trees Chapter 13: Algorithms of Best Paths Chapter 14: Algorithms of Bipartite Graphs and Flow Networks

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值