POJ 3660 Cow Contest(floyed运用)
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 题目大意:有n头奶牛,奶牛之间有m个关系,每次输入的x,y代表x胜过y,求出能够确定当前奶牛和其他所有奶牛的关系的奶牛有几头。
思路:对于每两个奶牛之间有三种关系, 1.没关系 2. a胜过b 3. a输给b,我们用dis[i][j] 代表第i只奶牛和第j只奶牛的关系。我们首先可以对开始输入的奶牛的关系建图,之后用floyed跑一遍图,遍历完所有点点之间的关系,最后判断每一个点,若与其他n-1个点都有关系则ans++
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue> using namespace std;
const int INF = 0x3f3f3f3f;
int dis[][];
int n, m;
void floyed()
{
for (int k = ; k <= n; k++)
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++) {
if ((dis[i][k] == && dis[k][j] == ) || (dis[i][k] == && dis[k][j] == ))
dis[i][j] = dis[i][k]; //判断ij之间的关系
}
}
int main()
{
ios::sync_with_stdio(false);
while (cin >> n >> m) {
memset(dis, , sizeof(dis));
for (int a, b, i = ; i <= m; i++) {
cin >> a >> b;
dis[a][b] = ;//a胜b
dis[b][a] = ;//a输给b
}
floyed();
int ans = ;
for (int i = ; i <= n; i++) {
int cnt = ;
for (int j = ; j <= n; j++) {
if (i == j)continue;
if (dis[i][j])cnt++;
}
if (cnt == (n - ))ans++;
}
cout << ans << endl;
}
return ;
}
POJ 3660 Cow Contest(floyed运用)的更多相关文章
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- POJ 3660 Cow Contest
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- 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 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- POJ 3660 Cow Contest (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
随机推荐
- day13 memcache,redis上篇
memcache memcache简介 Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached是以LiveJournal旗下Danga Interactive公司的B ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试 代码工程地址: https://github.co ...
- 解决PowerDesigner中DBMS选项卡为空白
点击DBMS后面的黄色(浏览)文件图标, 找到安装目录里面PowerDesigner \Resource Files\DBMS,就可以了.
- iOS @IBDesignable和@IBInspectable
http://www.tuicool.com/articles/JVNRBjY @IBDesignable和@IBInspectable 时间 2014-10-08 11:02:03 CSDN博客 ...
- MaxCompute 图计算开发指南
快速入门step by step MaxCompute Studio 创建完成 MaxCompute Java Module后,即可以开始开发Graph了. 代码示例 在examples目录下有gra ...
- GIT 用RSA加密方式来记住密码
ssh-kegen -t rsa -C "你的帐号";//生成rsa的公钥和密钥 当然这个要在GNU环境下来执行,要是用Windows的CMD是不可以的(不输入DIR时),感觉是因 ...
- mysql 查询当天、昨天、本周、上周、本月、上月、今年、去年数据
mysql查询今天.昨天.7天.近30天.本月.上一月 数据 今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT ...
- Gym - 101617D_Jumping Haybales(BFS)
Sample Input 4 2 .### #... .#.. #.#. 3 1 .#. .#. .#. Sample Output 4 -1 题意:给一个n*n的图,每次最多能跳k个格子,只能向南( ...
- 根据花瓶的侧面投影图,用Matlab绘制花瓶的三维立体图
现有一花瓶侧面投影如图 问题: 1) 做出该花瓶三维立体图: 2) 计算其表面积: 计算其体积. 第一次参加数学建模,从来没有接触过Matlab语言,一上来就碰到这种数字图像处理的问题就 ...
- @总结 - 7@ 生成树计数 —— matrix - tree 定理(矩阵树定理)与 prüfer 序列
目录 @0 - 参考资料@ @0.5 - 你所需要了解的线性代数知识@ @1 - 矩阵树定理主体@ @证明 part - 1@ @证明 part - 2@ @证明 part - 3@ @证明 part ...