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

USACO 2008 January Silver

题目大意:给定N个人,然后知道这N个人的两两对决的情况,前一个为胜者,问M个对决情况中最多能确定几个人的名次.

思路:想到了Floyd算法,可是怎么来关联还是不知所以然,网上查了资料后,才明白用Floy求传递闭包,只要该人的关系和其他人的关系确定,那么他的名次就是确定的。

Code

#include <iostream>#include <cstring>#include <algorithm>using namespace std;

const int N=110;int mp[N][N];

int main(){    int n,m;    while (cin>>n>>m)    {        int i,j,k;        int u,v;        memset(mp,0,sizeof(mp));        for (i=0;i<m;i++)        {            cin>>u>>v;            mp[u][v]=1;        }       for(k=1;k<=n;k++)          for(i=1;i<=n;i++)              for(j=1;j<=n;j++)                if(mp[i][k]==1&&mp[k][j]==1)  //A和B有关,B和C有关,则Ac有关,不等号的传递性                    mp[i][j]=1;        //Floyd();        int ans=0;        for (i=1;i<=n;i++)        {            for (j=1;j<=n;j++)            {                if (j==i) continue;            if (mp[i][j]==0&&mp[j][i]==0) break;            }            if (j>n) ans++;        }        cout<<ans<<endl;    }}

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

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

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

  2. poj 3660 Cow Contest 传递闭包

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

  3. POJ 3660 Cow Contest [Floyd]

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

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

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

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

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

  6. POJ 3660 Cow Contest (闭包传递)

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

  7. POJ 3660 Cow Contest

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

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

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

  9. POJ - 3660 Cow Contest(flod)

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

最新文章

  1. ROS中RVIS导入机器人模型,添加摄像头,雷达,Kinect
  2. php 变量输入,PHP-输入变量
  3. CentOS通过DNSpod实现动态域名
  4. React 18 带给我们的惊喜
  5. python可以自动写文章吗_让python来告诉你神奇的操作,如何实现文章自动化
  6. 程序包android.support.annotation不存在_efcore技巧贴也许有你不知道的使用技巧
  7. IT管理人才必备的十大能力(转)
  8. 密码必须至少为6个字符_1081 检查密码 (15分)
  9. protobuf协议_gRPC 使用 protobuf 构建微服务
  10. 安装过程中检测数据库是否已经存在
  11. php和python-什么是Python和php?Python与PHP有什么区别
  12. 主机甲采用停等协议向主机乙_TCP/IP 协议——详解篇
  13. 台式计算机的cpu,台式电脑处理器(CPU)性能排行榜
  14. 张轩睿和Selina要复合?任家萱的粉丝们会同意吗
  15. element-ui版本更新兼容问题
  16. 香帅的北大金融学课笔记13 -- 投资决策
  17. 安能辨龟是雄雌---巴西龟的雌雄辨别方法
  18. 无线局域网CSMA/CA协议
  19. linux系统下如何修改开机图片,Ubuntu Kylin下修改登录背景,用户头像,开机动画及自动更换壁纸...
  20. 【论文投稿】Hindawi旗下4区Mobile Information Systems(misy)投稿详细步骤

热门文章

  1. 完全CSS实现鼠标移上出现层的效果(超简单)
  2. 前端学习笔记--HTTP缓存
  3. 响应式框架Bootstrap栅格系统
  4. 【转】utf-8的中文是一个汉字占三个字节长度
  5. 如何让浮动的元素换行??css
  6. Redis---概述
  7. Sum of Even Numbers After Queries
  8. 分布式Session框架
  9. Linux 文件属性
  10. bzoj4152: [AMPPZ2014]The Captain