题意:每个人有2种排名,对于A只要有一种排名高于B,那么A就能赢B,再如果B能赢C,那么A也能赢C,要求输出每个人分别能赢多少个人

析:首先把题意先读对了,然后我们可以建立一个图,先按第一种排名排序,然后从高的向向低的连一条边,然后再按第二种排序,同理连线。

最后dfs一次,要先从排名低的开始遍历,不用清0,因为是从排名低的开始的。也可以用强连通分量或者线段树。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
vector<int> G[maxn];
struct Node{
int x, y, id;
};
Node a[maxn]; bool cmp1(const Node &lhs, const Node &rhs){
return lhs.x < rhs.x;
} bool cmp2(const Node &lhs, const Node &rhs){
return lhs.y < rhs.y;
}
int cnt;
int ans[maxn];
bool vis[maxn]; void dfs(int u){
if(vis[u]) return ;
++cnt;
vis[u] = true;
for(int i = 0; i < G[u].size(); ++i) dfs(G[u][i]);
} int main(){
freopen("codecoder.in", "r", stdin);
freopen("codecoder.out", "w", stdout);
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d %d", &a[i].x, &a[i].y);
a[i].id = i;
}
sort(a, a + n, cmp1);
for(int i = n-1; i > 0; --i) G[a[i].id].push_back(a[i-1].id);
sort(a, a + n, cmp2);
for(int i = n-1; i > 0; --i) G[a[i].id].push_back(a[i-1].id);
cnt = 0;
for(int i = 0; i < n; ++i){
dfs(a[i].id);
ans[a[i].id] = cnt - 1;
}
for(int i = 0; i < n; ++i) printf("%d\n", ans[i]);
return 0;
}

  

Gym 101142C CodeCoder vs TopForces (搜索)的更多相关文章

  1. Gym - 101142C CodeCoder vs TopForces(搜索)

    题意:给定n个人在两个网站上的得分,一个人若能在任意一个网站里战胜另一个人,则认为这个人能战胜那个人.问每个人都能战胜多少人. 分析: 1.战胜具有传递性. 例如: 4 5 2 7 3 3 因为第三个 ...

  2. 【DFS】Gym - 101142C - CodeCoder vs TopForces

    就按照题意建出有向图来(n个点,2n-2条边),然后从按随便一个rating排序,从最后一个开始dfs,用vis数组防止重复访问,因为每次之前的肯定能访问之后的(及之后的能访问的),所以不会有重复.就 ...

  3. C - CodeCoder vs TopForces Gym - 101142C (连通块+思维)

    题目链接: C - CodeCoder vs TopForces Gym - 101142C 题目大意:给你n个人的信息,每一个人的信息包括两个.t1和t2.A>B的前提是A的t1和t2至少有一 ...

  4. Codeforces Gym 101142C:CodeCoder vs TopForces(搜索)

    http://codeforces.com/gym/101142/attachments 题意:每个人在TC和CF上分别有两个排名,如果有一个人在任意一个网站上大于另一个人的排名,那么这个人可以打败另 ...

  5. Gym 101142C :CodeCoder vs TopForces(强连通算法)

    题意:N个人,每个人有a属性和b属性,如果一个人的a或者b大于另外一个人,我们说这个人可以打败那个人.且这种关系可以传递.对于每个人,输出他可以打败多少人.(保证每个a不相同,保证每个b不相同. 思路 ...

  6. Codeforces Gym 101142 C. CodeCoder vs TopForces(思维+图论)

    题意: 每个人有两个积分CC和TF 第i个人能战胜第j个人的条件满足下面两个条件中的一个即可 1.CCi > CCj 或 TFi > TFj 2.i能战胜k,k能战胜j. 题解: 先按CC ...

  7. Gym - 100625J Jailbreak 最短路+搜索

    http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...

  8. GYM 101933E(记忆化搜索)

    用每个人的血量作为状态去搜索T飞,考虑题解中更好的搜索方式:每种血量有多少个人作为状态.这样会减去很多重复的状态,因为只要乘一下就得到了所有相同情况的和. 虽然我不会算,但是直观感受起来复杂度比较优秀 ...

  9. Loppinha, the boy who likes sopinha Gym - 101875E (dp,记忆化搜索)

    https://vjudge.net/contest/299302#problem/E 题意:给出一个01 0101串,然后能量计算是连续的1就按1, 2, 3的能量加起来.然后给出起始的能量,求最少 ...

随机推荐

  1. 九度OJ 1165:字符串匹配 (模式匹配)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3219 解决:1149 题目描述: 读入数据string[ ],然后读入一个短字符串.要求查找string[ ]中和短字符串的所有匹配,输出 ...

  2. 如果这种方式导致程序明显变慢或者引起其他问题,我们要重新思考来通过 goroutines 和 channels 来解决问题

    https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/09.3.md 9.3 锁和 sync 包 在一些复杂的程序中,通常通 ...

  3. jquery .html(),.text(),.val()用法

    .html()用为读取和修改元素的HTML标签 .text()用来读取或修改元素的纯文本内容 .val()用来读取或修改表单元素的value值. 这三个方法功能上的对比 .html(),.text() ...

  4. P3231 [HNOI2013]消毒

    P3231 [HNOI2013]消毒 二维覆盖我们已经很熟悉了 扩展到三维,枚举其中较小的一维,这里定义为$a$ 以$a$为关键字状压,$1$表示该面全选 剩下的面和二维覆盖一样二分图匹配 如果还没接 ...

  5. 20145239 《Java程序设计》第5周学习总结

    20145239 <Java程序设计>第5周学习总结 教材学习内容总结 (一)掌握try...catch...finally处理异常的方法: 程序中有许多意想不到的错误,所以我们要学会一些 ...

  6. Codeforces Round #551 (Div. 2) A~E题解

    突然发现上一场没有写,那就补补吧 本来这场应该5题的,结果一念之差E fail了 A. Serval and Bus 基本数学不解释,假如你没有+1 -1真的不好意思见人了 #include<c ...

  7. BZOJ 3043 IncDec Sequence:反向差分

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3043 题意: 给定一个长度为n的数列a[i],每次可以选择一个区间[l,r],使这个区间内 ...

  8. LightOJ 1132 Summing up Powers:矩阵快速幂 + 二项式定理

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1132 题意: 给定n.k,求(1K + 2K + 3K + ... + NK) % 2 ...

  9. JS工具函数汇总

    备注:http://phpjs.org/  这个站点把PHP常用的方法用js实现了,推荐一下 1.从数组中随机获取几个不重复项 //从一个给定的数组arr中,随机返回num个不重复项 function ...

  10. 【Lintcode】075.Find Peak Element

    题目: There is an integer array which has the following features: The numbers in adjacent positions ar ...