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. source insight 中文乱码解决方法

    options->preferences -> Files-> default encoding: 选择 GB2312 CP:936

  2. ActionFilterAttribute 全局记录API日志

    1.API项目下创建MonitorApiAttribute public class MonitorApiAttribute : ActionFilterAttribute { private sta ...

  3. Anaconda安装及配置

    简介 Anaconda(官方网站)指的是一个开源的Python发行版本,可以便捷获取包且对包能够进行管理,同时对环境可以统一管理的发行版本.Anaconda包含了conda.Python在内的超过18 ...

  4. Java 中 Equals和==的区别(转)

    另外一篇参考: https://blog.csdn.net/striverli/article/details/52997927 在谈论equals和==的区别前,我们先简单介绍一下JVM中内存分配的 ...

  5. uva_answers

    uva202: https://blog.csdn.net/lecholin/article/details/70163148 uva1589: https://blog.csdn.net/qq_42 ...

  6. Vue 路由的嵌套

    1.配置路由 const routes = [ { path: '/User', component: User, children: [{ path: 'OP1', component: OP1 } ...

  7. C6.cpp

    可以将 一个array对象赋给另一个对象 对于下标值出现负数的情况下可以解释为在头指针的位置处向前移动对应的字节 可以使用vector.at(n_elem)来获取元素等价于vector[n_elem] ...

  8. Python课程第五天作业

    1.利用字典推导式和列表推导式完成数据的相互转化: dic = {'name': 'Owen', 'age': 18, 'gender': '男'} ls = [('name', 'Owen'), ( ...

  9. 秘制牛肉Alpha阶段项目展示

    秘制牛肉Alpha阶段项目展示 1.团队成员和个人博客 · 左顺:"我是左顺,秘制牛肉队开发人员". · 王尖兵:"C,java,html5都会一点的菜鸡,没做过团队项目 ...

  10. ubuntu下的git版本创建

    一.git的特点 二.gei的安装和配置 1.安装命令如下 sudo apt-get install git 2.安装成功后输入 git 3.创建版本库 git init 4.使用 先创建一个txt文 ...