POJ 3660 Cow Contest [Floyd]
POJ - 3660 Cow Contest
http://poj.org/problem?id=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
这题就是给m个有序对,问这些有序对构成的有向图能确定排名位置的点有几个。
这题用floyd的最短路去做又快又方便,但是我一直用拓扑排序在写所以就一直在WA。补题后看了网上用拓扑排序的题解,原理就是每次拓扑排序以后将未处理的连在同一点边合并,其实也是用了floyd的思想,但是没有直接用最短路思路清晰,而且要多一步并查集去判断是否是一个联通块。
最短路做法:
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <string> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #define INF 0x3f3f3f3f #define lowbit(x) (x&(-x)) using namespace std; typedef long long ll;int w[105][105];int main() {int n,m,a,b;scanf("%d%d",&n,&m);while(m--){scanf("%d%d",&a,&b);w[a][b] = 1;}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)w[j][k] = (w[j][k] > 0 || w[j][i] + w[i][k] == 2);int res = 0;for(int i=1;i<=n;i++){int tp = 0;for(int j=1;j<=n;j++)if(w[i][j] || w[j][i]) tp++;if(tp == n-1) res++;}printf("%d\n",res);}
转载于:https://www.cnblogs.com/HazelNut/p/7821069.html
POJ 3660 Cow Contest [Floyd]相关推荐
- 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 (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- [传递闭包]POJ#3660 Cow Contest
题面 传送门 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24342 Accepted: 13539 ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- poj 3660 Cow Contest 传递闭包
题目链接: http://poj.org/problem?id=3660 题目大意: 有n头牛,每头牛都有一个战斗值,农夫约翰想给这些牛排名次,但是只有m场比赛,约翰想知道有多少头牛的名次是确定的. ...
- 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
dp,图论 题意:输入n和m表示n个牛(从1到n标号),下面m个信息,A B,表示A牛能打赢B牛.现在要给所有的牛排名(按实力从高到低),问哪些牛的排名是可以确定的 如果知道由l个人能打赢自己,自己能 ...
- POJ - 3660 Cow Contest(最短路变形+闭包传递)
题目链接:点击查看 题目大意:给定n头牛和m个关系,每个关系表示为两个整数a与b,其意义为a牛能打败b牛,问可以确定排名的牛的数量. 题目分析: 在这里先说一下关系闭包: 关系闭包有三种: 自反闭包( ...
最新文章
- mac java web_mac os安装java web开发环境配置
- C# 时间格式(血淋淋的教训啊。。。)
- 生活随笔:大学需要确立自己的方向
- Java易混小知识——equals方法和==的区别
- LeetCode 58. Length of Last Word
- 为Pokémon Go而生的聊天软件GoChat,坐拥百万用户却快要破产
- 中国分省市地图导航-SVG格式(基于Raphaël)
- BIM族库下载——塔吊等垂直运输设备族库
- Nginx支持ipv6
- 新西兰 计算机 转专业,想去新西兰留学读硕士,但又想转专业
- 专科学习计算机应用需要学的课本,计算机应用技术
- 孟庭苇---经典精选怀旧金曲
- 操作系统——吸烟者问题
- 牛客小白月赛65个人题解A-E
- 嵌入式linux内核启动过程,嵌入式Linux:ARM Linux启动流程
- linux下ffmpeg库 ARM交叉编译
- FFplay文档解读-39-视频过滤器十四
- 崇启大桥崇明段发生重大交通事故致5人死亡-重大交通事故-崇启大桥
- 高性能计算在石油物探中的应用现状与前景
- 【django】settings.py配置文件内容详细介绍
热门文章
- SQL Server事务的隔离级别
- 发现一款绿色toolbar工具
- Google使用人工智能压缩图片,效果优于JPEG
- Python 2.7.10安装pycurl遇到的问题汇总
- 【移动开发】Android中三种超实用的滑屏方式汇总(ViewPager、ViewFlipper、ViewFlow)...
- 展望企业级移动设备的操作系统
- Hive Fetch Task
- ORA-25153: Temporary Tablespace is Empty
- lvs在nat dr tun 模型的实现
- 解决MySQL server has gone away