Cow Contest

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17797   Accepted: 9893

Description

N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.

The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ NA ≠ B), then cow A will always beat cow B.

Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.

Input

* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B

Output

* Line 1: A single integer representing the number of cows whose ranks can be determined
 

Sample Input

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

Sample Output

2

Source

本题思路:将题目给出的已知边都存入图中,利用传递性求出可能存在的每条边,对于一个学生,用i -> j表示 i 比 j 强,那么对于所有学生,他的排名被确定的条件就是确定他与其它所有同学的排名情况,即Bigger[ i ] + Smaller[ i ] == n - 1。

参考代码:(不建议看,按照上面的思路实现一波就行了)

 #include <cstdio>
#include <cstring>
#include <queue>
using namespace std; const int maxn = + , INF = 0x3f3f3f3f;
int n, m, a, b;
bool G[maxn][maxn]; int Floyd_Warshall() {
int num = ;
for(int k = ; k <= n; k ++) {
for(int i = ; i <= n; i ++) {
for(int j = ; j <= n; j ++) {
G[i][j] = G[i][j] || (G[i][k] && G[k][j]);
}
}
}
for(int i = ; i <= n; i ++) {
int temp = ;
for(int j = ; j <= n; j ++)
if(G[i][j] || G[j][i]) temp ++;
if(temp == n - ) num ++;
}
return num;
} int main () {
scanf("%d %d", &n, &m);
int x, y;
for(int i = ; i < m; i ++) {
scanf("%d %d", &x, &y);
G[x][y] = true;
}
int ans = Floyd_Warshall();
printf("%d\n", ans);
return ;
}

POJ-3660.Cow Contest(有向图的传递闭包)的更多相关文章

  1. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  2. POJ 3660 Cow Contest【Floyd 传递闭包】

    传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...

  3. poj 3660 Cow Contest (bitset+floyd传递闭包)

    传送门 解题思路 考试题,想到传递闭包了,写了个O(n^3)的,T了7个点...后来看题解是tm的bitset优化???以前好像没听过诶(我太菜了),其实也不难,时间复杂度O(n^3/32) #inc ...

  4. POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)

    POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...

  5. POJ 3660 Cow Contest 传递闭包+Floyd

    原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  6. POJ 3660 Cow Contest

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  7. POJ - 3660 Cow Contest 传递闭包floyed算法

    Cow Contest POJ - 3660 :http://poj.org/problem?id=3660   参考:https://www.cnblogs.com/kuangbin/p/31408 ...

  8. POJ 3660 Cow Contest(传递闭包floyed算法)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  9. POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16341   Accepted: 9146 Desc ...

  10. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

随机推荐

  1. Linux基础上

    文件操作                                                                                                 ...

  2. Django字符串翻译

    文章出处:https://www.jb51.net/article/70077.htm Django模板使用两种模板标签,且语法格式与Python代码有些许不同. 为了使得模板访问到标签,需要将 {% ...

  3. 简单Hash函数LongHash

    import java.security.SecureRandom; import java.util.Random; public class LongHash { private static l ...

  4. MemCache在网站中的使用

    MemCache安装好后,网站一直没法使用,后来查找资料,发现需要在配置文件里写几行代码,如下所示 <enyim.com> <memcached protocol="Tex ...

  5. Hello_Git!!!(Git的安装)

    Install_Git&Say Hello! Mac与Linux平台  ||最近的Mac平台中都预装了Git,而各个版本的Linux中也都以软件包(Package)的形式提供给了用户,详细请参 ...

  6. 解决wxParse空格不解析的问题

    遇到的问题: 相似问题:https://blog.csdn.net/qq_41619741/article/details/85774865 http://html51.com/info-41786- ...

  7. 提取和匹配线特征的一个demo

    一.代码来源: https://github.com/drozdvadym/opencv_line_descriptor 二.依赖包:OpenCV 2.4.9 三.Matching的运行结果截图: 四 ...

  8. <iframe width="250" height="250" src="http://www.baidu.com"></iframe>

     <iframe width="250" height="250" src="http://www.baidu.com">< ...

  9. django 加载css、js和图片记载不上

    在django的setting里加以下配置 STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), 'Djago/static/',)

  10. 在引用阿里云库或其他库的时候,经常发生框架不兼容(原因是系统采用:Microsoft .NET Framework 4 Client Profile ),请改为Microsoft .NET Framework 4

    在引用阿里云库或其他库的时候,经常发生框架不兼容(原因是系统采用:Microsoft .NET Framework 4 Client Profile ),请改为Microsoft .NET Frame ...