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 ≤ N; A ≠ 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
思路:很少写floyed,但是这个算法解决这种所有顶点之间的关系很容易理解。在数据量不大的情况下是可以接受的。
该题思路:
①对于a胜于b,我们使得mp[a][b]=1.
②floyed更新各个点之间的关系。
③遍历每两对点,如果mp[i][j]==1或者mp[j][i]==1的话(i>j或者j>i的个数),计数加一。最后如果计数总数为n-1的话,就代表它和其他n-1个点的关系都确定,那么它的排名就确定。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;const int maxx=1e2+10;
int mp[maxx][maxx];
int n,m;inline void floyed()
{for(int k=1;k<=n;k++)//循环顺序!!!{for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(mp[i][k]&&mp[k][j]) mp[i][j]=1;}}}
}
inline void solve()
{int sum=0,ans=0;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(mp[i][j]||mp[j][i]) sum++;}if(sum==n-1) ans++;sum=0;}cout<<ans<<endl;
}
int main()
{memset(mp,0,sizeof(mp));scanf("%d%d",&n,&m);int x,y;while(m--){scanf("%d%d",&x,&y);mp[x][y]=1;}floyed();solve();return 0;
}

努力加油a啊,(o)/~

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

  1. H - Cow Contest POJ - 3660(Floyd 传递闭包)

    H - Cow Contest POJ - 3660 题意: 有 n 头牛比赛,边 1 -> 2 代表 1 能赢 2 ,给你 m 条边,问能确定出多少头牛的名次? 思路: 如果 1->2 ...

  2. poj 3660(Floyd求传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9317   Accepted: 5249 Descr ...

  3. Cow Contest POJ - 3660

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

  4. Cow Contest POJ - 3660 Floyd算法,关系链图

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

  5. Cow Contest POJ - 3660 And Longest Paths UVA - 10000(弗洛伊德的应用)

    Problem Description N ( 1 ≤ N ≤ 100 ) N (1 ≤ N ≤ 100) N(1≤N≤100) cows, conveniently numbered 1.. N 1 ...

  6. Cow Contest (传递闭包)

    题目链接:https://cn.vjudge.net/problem/POJ-3660#author=freeloop 不懂传递闭包的请戳这:https://blog.csdn.net/acm_136 ...

  7. Cow Contest【最短路-floyd】

    Cow Contest POJ - 3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...

  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 传递闭包

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

最新文章

  1. Galgame研发日志:预算爆炸,问题不大
  2. 2场直播丨Oracle数据库SQL执行计划的取得和解析、一次特殊的 Oralce 硬解析性能问题的技术分享...
  3. 解决django前端使用iframe标签报错127.0.0.1 refused to connect.
  4. rhel5 安装Oracle Database 10g Release 2(II)
  5. jQuery length和size()区别总结如下:
  6. 【转】MySQL日期时间函数大全
  7. 程序员需知的 58 个网站
  8. python爬取网易付费音乐包_爬取网易云音乐“三部曲”(三):轻松下载网易音乐歌曲!...
  9. P2525 Uim的情人节礼物·其之壱 prev_permutaion
  10. 计算机桌面桌面设置动态视频教程,电脑怎么设置动态桌面?电脑设置动态视频桌面教程...
  11. 微信聊天记录做成词云~
  12. JavaScript --------WebS APIs学习之DOM(一)
  13. openstack源码架构_openstack创建虚拟机源码阅读
  14. 玲珑杯计算机大赛得奖作品,信阳师范学院学子在第14届中国大学生计算机设计大赛“玲珑杯”省级赛中获奖...
  15. Salesforce中国区或将解散!一代CRM巨头退出中国市场?
  16. 联想G40重装linux系统,联想G40笔记本重装XP系统教程
  17. IDEA 依赖自动导入,不用每次手动点击Load Maven Changes图标
  18. 仙人掌圆方树学习笔记
  19. 2019.10.15
  20. 打印菱形图案用java如何做_Java打印出菱形图案

热门文章

  1. C#调用C++的dll文件方法
  2. c++调用dll动态链接库历程
  3. php 单例模式原理,PHP单例模式demo详解
  4. java日期格式精确到分_详解Java日期格式化及其使用例子
  5. Linux安装宝塔面板
  6. SwipeRefreshLayout里面需要注意的Api
  7. excel中怎样用公式获取表单控件_老会计不愿教的工资表汇总公式,真是太好用了...
  8. c++11 thread类的简单使用
  9. iOS重绘机制drawRect
  10. 200(强缓存)和304(协商缓存)的区别