Codeforces Gym 101142 C. CodeCoder vs TopForces(思维+图论)
题意:
每个人有两个积分CC和TF
第i个人能战胜第j个人的条件满足下面两个条件中的一个即可
1、CCi > CCj 或 TFi > TFj
2、i能战胜k,k能战胜j。
题解:
先按CCi的积分排序,然后连接相邻的两个人a->b,代表a能战胜b
再按TFi的积分排序,做同样的处理。
最后我们按TFi的排序做dfs,只需要dfs一遍就可以得到所有的答案
#include <algorithm> #include <iostream> #include <vector> #include <cstdio> using namespace std; const int maxn = 1e5 + 100; struct Data{int x, y, id, ans; }a[maxn]; bool cmp1(const Data& A, const Data& B) { return A.x < B.x; } bool cmp2(const Data& A, const Data& B) { return A.y < B.y; } bool cmp3(const Data& A, const Data& B) { return A.id < B.id; } int vis[maxn]; vector<int> G[maxn]; int n, ans; void dfs(int x){if(!vis[x]) ans++;vis[x] = 1;for(int i = 0; i < G[x].size(); i++){if(vis[G[x][i]]) continue;dfs(G[x][i]);} }int main(){freopen("codecoder.in", "r", stdin);freopen("codecoder.out", "w", stdout);cin>>n;for(int i = 1; i <= n; i++){cin>>a[i].x>>a[i].y;a[i].id = i;}sort(a+1, a+1+n, cmp1);for(int i = 2; i <= n; i++) G[a[i].id].push_back(a[i-1].id);sort(a+1, a+1+n, cmp2);for(int i = 2; i <= n; i++) G[a[i].id].push_back(a[i-1].id);ans = 0;for(int i = 1; i <= n; i++){dfs(a[i].id);a[i].ans = ans-1;}sort(a+1, a+1+n, cmp3);for(int i = 1; i <= n; i++) cout<<a[i].ans<<endl; }
转载于:https://www.cnblogs.com/Saurus/p/7637391.html
Codeforces Gym 101142 C. CodeCoder vs TopForces(思维+图论)相关推荐
- Codeforces Gym 101142C:CodeCoder vs TopForces(搜索)
http://codeforces.com/gym/101142/attachments 题意:每个人在TC和CF上分别有两个排名,如果有一个人在任意一个网站上大于另一个人的排名,那么这个人可以打败另 ...
- Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)
题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, -, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...
- Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks
Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...
- Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)
Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven) 题目来源: Codeforces 题意: 给出一些比赛, ...
- [Codeforces Gym 101651/100725B] Banal Tickets
Codeforces Gym 100725 题解: 先分两种情况, 积为000与积非0" role="presentation" style="position ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100269 Dwarf Tower (最短路)
题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game na ...
- Codeforces Gym 100676G Training Camp 状压dp
http://codeforces.com/gym/100676 题目大意是告诉你要修n门课,每门课有一个权值w[i], 在第k天修该课程讲获得k*w[i]的学习点数,给出了课程与先修课程的关系,要修 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
最新文章
- android工程中让人很不爽的“×××警告”
- phalcon:跟踪sql语句
- PAT_B_1013_Java(20分)
- 用CPLEX写个数学模型就这么难?
- Oracle MySQL sql 列转行 union all 实现
- win10下LPT并口打印失败和POS打印机的钱箱不能打开,win10的坑
- c语言旋转led时钟设计报告,基于POV原理的LED旋转时钟的设计与制作
- ElementUI Collapse 折叠面板
- 小虾米的求助Massage
- Octet string 解析
- outlook技巧-常用email账号设置
- 计算机报名照片最小像素高宽,网上报名照片如何确定大小
- 【USACO 2020 January Silver】Loan Repayment 题解
- 渗透测试-微信刷票漏洞(IP伪造)
- 算术编码、译码以及matlab实现
- plsql无法连接oracle,报错:ORA-12514
- Baseline Wander Correction: 基线漂移补偿
- “百度杯”CTF比赛 九月场Upload 之菜刀的使用
- 我博士科研经历中的经验和教训——朱亮
- pythonmysql数据处理_Python之MySQL数据操作
热门文章
- 从滴滴亏109亿说起
- 【2015 SACC】 架构之手机淘宝性能优化全记录
- html代码中如何将浏览器的菜单栏,状态栏,地址栏,工具栏等隐藏,标题栏html代码 HTML中怎么设置标题居中...
- python函数编写_Python函数(二)如何编写函数
- Valine+Leancloud搭建评论模块
- Linux 理解平均负载
- IIS 配置 url 重写...
- HDU2449 Gauss Elimination 高斯消元 高精度 (C++ AC代码)
- 双系统Ubuntu 无 启用wifi选项
- 贝叶斯思维 统计建模的Python学习法