Cow Contest POJ - 3660
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
有n只奶牛,有n个连续的实力,如果u的实力大于v的实力,就能打赢它,
然后给定m种关系,求最后能确定其排名的奶牛个数。
一个传递闭包问题。头一次解这种题目。谢谢大神的思路。
//Asimple #include <iostream> #include <algorithm> #define mod 100000 #define CLS(a, v) memset(a, v, sizeof(a)) #define debug(a) cout << #a << " = " << a <<endl #define dobug(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; typedef long long ll; const int maxn = 500+5;const int INF = (1 << 16);int n, m, num, T, k, len, ans, sum, x, y, z; int Map[maxn][maxn]; void solve(){for(int k=1; k<=n; k++)for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)if( Map[i][k] && Map[k][j] )Map[i][j] = 1;/*传递闭包 只有这个点和其余所有的点的关系都是确定的这个点才是确定的*/ans = 0;int j;for(int i=1; i<=n; i++) {for(j=1; j<=n; j++) {if( i==j ) continue;if( Map[i][j]==0 && Map[j][i]==0) break;}if( j>n ) ans ++;}cout << ans << endl; }void input() {ios_base::sync_with_stdio(false);while( cin >> n >> k ) {CLS(Map, 0);while( k -- ) {cin >> x >> y;Map[x][y] = 1;}solve();} }int main(){input();return 0; }
转载于:https://www.cnblogs.com/Asimple/p/6915788.html
Cow Contest POJ - 3660相关推荐
- H - Cow Contest POJ - 3660(Floyd 传递闭包)
H - Cow Contest POJ - 3660 题意: 有 n 头牛比赛,边 1 -> 2 代表 1 能赢 2 ,给你 m 条边,问能确定出多少头牛的名次? 思路: 如果 1->2 ...
- Cow Contest POJ - 3660(floyed求传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1-N, are participating in a programming contest. As we a ...
- Cow Contest POJ - 3660 Floyd算法,关系链图
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...
- 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 ...
- Cow Contest【最短路-floyd】
Cow Contest POJ - 3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...
- Cow Contest (传递闭包)
题目链接:https://cn.vjudge.net/problem/POJ-3660#author=freeloop 不懂传递闭包的请戳这:https://blog.csdn.net/acm_136 ...
- POJ 3660 Cow Contest [Floyd]
POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
最新文章
- Caffe源码中layer文件分析
- 插值法在计算机中的应用,常见的插值法及其应用.pdf
- C#写的windows应用程序打包
- python 会计专用格式_python-2.7 – 如何使用xlsxwriter将格式应用为“文本”和“会计”...
- SAP UI5 control focus related research
- 为你的项目启用可空引用类型
- CISA《网络安全事件和漏洞响应手册》提到的SSVC是什么?
- Codeforces Round #309 (Div. 1) A(组合数学)
- 【“新智认知”杯上海大学联赛】D-CSL的字符串(贪心)
- 振型叠加法 matlab,Ansys模态叠加法谐响应分析
- 内存碎片与malloc(转)
- 网络协议 终章 - GTP 协议:复杂的移动网络
- 位移的单位符号_初中物理符号级单位符号公式大全
- Mac上一款简单实用音频剪辑工具——QuickTime Player
- 安卓手机做电脑摄像头(USB连接1080P 60FPS低延迟非常稳定)
- 请编程序将“China”译成密码,密码规律是:用原来的字母后面第四个字母代替原来的字母。
- 【前端——Node.js】:Express、数据库与身份认证
- 爬虫(21)crawlspider讲解古诗文案例补充+小程序社区案例+汽车之家案例+scrapy内置的下载文件的方法
- matlab 冲激响应不变法,matlab实验七冲激响应不变法IIR数字滤波器设计.doc
- vue php聊天室,实时聊天室:基于Laravel+Pusher+Vue通过事件广播实现
热门文章
- Hyperledger Fabric on SAP Cloud Platform(SAP云平台上的超级账本简介)
- 微信小程序开发系列四:微信小程序之控制器的初始化逻辑
- linux未知的类型名 FILE,smb使用 ------转载自http://blog.csdn.net/tlaff/article/details/5463068...
- 动态分区分配的“首次适应算法_kafka集群关于资源分配的手册
- python 三维数据绘图_Python中三维坐标空间绘制的实现
- unity3d 700种 材质球_温度与耐磨钢球的关系
- flex 图片上传并以二进制保存到oracle数据库,flex 加载并显示图片 图片转化成二进制...
- python中start用法_Start Python 学习笔记(琐碎知识,持续更新。。。)
- 批量梯度下降python实现_python实现梯度下降算法的实例详解
- 自由存储区和堆的区别_区块链发展阶段:IPFS和Filecoin赋能分布式存储