Cow Contest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7690   Accepted: 4288

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

刚才学了下闭包传递,简单来说就是用Floyd来求两点是否连通。这题里,如果一点的入度加上出度等于N-1,那么就可确定这点的等级,因为除了它自己之外的所有节点要么在它之前要么在它之后,不管它前面的节点后后面的节点怎么排序,都不会影响到它。
 1 #include <iostream>
 2 #include <cstdio>
 3 using    namespace    std;
 4
 5 const    int    SIZE = 105;
 6 int    N,M;
 7 int    IN[SIZE],OUT[SIZE];
 8 bool    G[SIZE][SIZE];
 9
10 int    main(void)
11 {
12     int    from,to;
13     int    ans;
14
15     while(scanf("%d%d",&N,&M) != EOF)
16     {
17         fill(&G[0][0],&G[N][N],false);
18         for(int i = 0;i <= N;i ++)
19             IN[i] = OUT[i] = 0;
20
21         for(int i = 0;i < M;i ++)
22         {
23             scanf("%d%d",&from,&to);
24             G[from][to] = true;
25         }
26
27         for(int k = 1;k <= N;k ++)
28             for(int i = 1;i <= N;i ++)
29                 for(int j = 1;j <= N;j ++)
30                     G[i][j] = G[i][j] || G[i][k] && G[k][j];
31         for(int i = 1;i <= N;i ++)
32             for(int j = 1;j <= N;j ++)
33                 if(G[i][j])
34                 {
35                     IN[j] ++;
36                     OUT[i] ++;
37                 }
38
39         ans = 0;
40         for(int i = 1;i <= N;i ++)
41             if(IN[i] + OUT[i] == N - 1)
42                 ans ++;
43         printf("%d\n",ans);
44     }
45
46     return    0;
47 }

转载于:https://www.cnblogs.com/xz816111/p/4514960.html

POJ 3660 Cow Contest (闭包传递)相关推荐

  1. POJ 3660 Cow Contest [Floyd]

    POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...

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

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

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

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

  4. [传递闭包]POJ#3660 Cow Contest

    题面 传送门 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24342 Accepted: 13539 ...

  5. POJ - 3660 Cow Contest(最短路变形+闭包传递)

    题目链接:点击查看 题目大意:给定n头牛和m个关系,每个关系表示为两个整数a与b,其意义为a牛能打败b牛,问可以确定排名的牛的数量. 题目分析: 在这里先说一下关系闭包: 关系闭包有三种: 自反闭包( ...

  6. POJ 3660 Cow Contest

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  7. poj 3660 Cow Contest 传递闭包

    题目链接: http://poj.org/problem?id=3660 题目大意: 有n头牛,每头牛都有一个战斗值,农夫约翰想给这些牛排名次,但是只有m场比赛,约翰想知道有多少头牛的名次是确定的. ...

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

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  9. POJ - 3660 Cow Contest(flod)

    题意:有N头牛,M个关系,每个关系A B表示编号为A的牛比编号为B的牛强,问若想将N头牛按能力排名,有多少头牛的名次是确定的. 分析: 1.a[u][v]=1表示牛u比牛v强,flod扫一遍,可以将所 ...

最新文章

  1. Rhel6.0升级内核到3.0.4
  2. logback的简单使用
  3. win7开机动画_优化win7系统 让系统运行更顺畅
  4. python爬取股票实时价格_【美股量化00篇】Python获取新浪接口美股实时数据
  5. 線陣相機處理時間計算方法
  6. 澳网:公茂鑫/张择创历史 中国男网夺大满贯首胜
  7. 北大OJ(POJ 2795)金银岛
  8. CentOS7文本模式下配置及安装KVM虚拟机
  9. (四)Linux 安装 jdk
  10. HTML是由____构成的____文件,JSP填空题
  11. CMOS和TTL电路区别
  12. 山东轻工业学院CSDN高校俱乐部参加“新一代语音云发布暨语音开发者大会”与“2012百度开发者大会”体会心得
  13. c语言三角函数乘法怎么表示,C语言实现三角函数表
  14. Machine learning techniques to enable closed-loop control in anesthesia-笔记
  15. 2021年汽车驾驶员(技师)考试题及汽车驾驶员(技师)找解析
  16. linux ps查看完整时间,Linux ps 命令查看进程启动及运行时间
  17. SVN conflict的解决办法
  18. 电子学:第009课——实验 7:研究继电器
  19. leetcode中等之1709.访问日期之间最大的空档期
  20. 简历中写工作经历,应该注意哪些方面?

热门文章

  1. Java基础篇:什么是线程优先级?
  2. http协议、cookie与session介绍
  3. 闭包和高阶函数-函数式编程的基本特征
  4. centos7 安装 php7
  5. https://docs.python.org/3/
  6. Outlook 2013中 IMAP配置
  7. Windows 下Temp帐号处理
  8. Java学习笔记1:Java中有关print、println、printf的用法和区别
  9. Rust常用编程概念之变量和可变性
  10. 【深度学习基础】张量的描述与深度学习常见张量