POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名。 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为此时该牛排第b+1名。
即推出当一个点的出度和入度的和等于n-1的时候,该点的排名是可以确定的, 即用传递闭包来求两点的连通性,如果d[i][j]==1,那么表示i,j两点相连通,度数都分别加1
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7262 | Accepted: 4020 |
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 ≤ 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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int d[105][105],degree[105];
int main()
{int n,m,i,j,k,ans=0,u,v;while(scanf("%d %d",&n,&m)!=EOF){memset(degree,0,sizeof(degree));memset(d,0,sizeof(d));for(i=1;i<=m;i++){scanf("%d %d",&u,&v);d[u][v]=1;}for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)d[i][j]=d[i][j]||(d[i][k]&&d[k][j]);for(i=1;i<=n;i++){for(j=1;j<=n;j++){if(d[i][j]){degree[i]++;degree[j]++;}} }for(i=1;i<=n;i++)if(degree[i]==n-1)ans++;printf("%d\n",ans); }
}
转载于:https://www.cnblogs.com/wuyuewoniu/p/4254751.html
POJ 3660 Cow Contest【传递闭包】相关推荐
- 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 传递闭包
题目链接: http://poj.org/problem?id=3660 题目大意: 有n头牛,每头牛都有一个战斗值,农夫约翰想给这些牛排名次,但是只有m场比赛,约翰想知道有多少头牛的名次是确定的. ...
- 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
题面 传送门 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24342 Accepted: 13539 ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ 3660 Cow Contest
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ - 3660 Cow Contest(最短路变形+闭包传递)
题目链接:点击查看 题目大意:给定n头牛和m个关系,每个关系表示为两个整数a与b,其意义为a牛能打败b牛,问可以确定排名的牛的数量. 题目分析: 在这里先说一下关系闭包: 关系闭包有三种: 自反闭包( ...
- POJ - 3660 Cow Contest(flod)
题意:有N头牛,M个关系,每个关系A B表示编号为A的牛比编号为B的牛强,问若想将N头牛按能力排名,有多少头牛的名次是确定的. 分析: 1.a[u][v]=1表示牛u比牛v强,flod扫一遍,可以将所 ...
最新文章
- 七八年级计算机教案,八年级信息技术教案第七章 特殊成员----字符串
- Linux SPI总线和设备驱动架构之二:SPI通用接口层
- 3DMax的OFusion插件的使用问题
- 关于onload的事件权柄以及踩过的坑
- js match()方法
- 浏览器解析jsx_简单理解JavaScript,TypeScript和JSX
- STM32学习:按键控制LED
- 集体智慧编程(5)——优化
- html5 预览dwg,哪个企业网盘可以实现dwg在线预览?
- jenkins调用VS201X
- TestCenter测试管理工具功能详解十二(Q)
- JavaFx教程-01初识javaFX
- JavaScript学习(七)——对象与数组、内部对象(1)
- mac mi 芯片 安装ps
- 后台用户角色权限管理设计
- 优步北京B组奖励政策
- magic4.0什么时候升级鸿蒙,科技知识:magic4.0什么时候更新 magic4.0更新时间介绍...
- Jav环境下shell脚本的调用
- Js(三)将es6语法转换成es5语法
- python houdini_Houdini的python教程
热门文章
- 四、PHP基础——会话技术Cookie 和 Session
- 天池 在线编程 双向取数(博弈DP)
- [scikit-learn 机器学习] 8. 非线性分类和决策树
- 图Graph--拓扑排序(Topological Sorting)
- 数据结构--图 Graph
- python 类继承 父类初始化_python之子类继承父类时进行初始化的一些问题
- 【机器学习】sclearn分类算法-决策树、随机森林
- matlab处理亮度不均匀,校正亮度不均匀问题并分析前景对象
- python实现两张图片横向和纵向拼接
- Django完成异步工具——celery