POJ3660 Cow Contest【最短路-floyd】
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
思路:原来是觉得像昨天写的那题一样用bellman判断一下能不能成环
但是这道题问的不只是一只牛 而是所有牛 而且成环不成环并不能判断他的排名能不能确定
对于一头牛 如果我们知道有x只牛能赢他 他能赢y只牛 并且x+y=n-1的话 那么他的排名是可以确定的
所以就用floyd跑一遍 就可以把传递的关系建立起来了
emmmm传递闭包?题解上有这么说 但是不是很理解有什么关系......因为用了floyd???
唉离散学了都忘光了 感觉之前学的真的都忘了
然后遍历每一头牛看看行不行
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
#include<queue>
#include<stack>
#define inf 0x3f3f3f3f
using namespace std;
int n, m, d[105][105];
void floyd()
{
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(d[i][k] && d[k][j]){
d[i][j] = 1;
}
}
}
}
}
int main()
{
while(cin>>n>>m){
for(int i = 0; i < m; i++){
int a, b;
cin>>a>>b;
d[a][b] = 1;
}
floyd();
int ans = 0;
for(int i = 1; i <= n; i++){
int num = 0;
for(int j = 1; j <= n; j++){
if(d[i][j] || d[j][i]){
num++;
}
}
if(num == n - 1){
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
POJ3660 Cow Contest【最短路-floyd】的更多相关文章
- POJ-3660 Cow Contest( 最短路 )
题目链接:http://poj.org/problem?id=3660 Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, ar ...
- POJ3660——Cow Contest(Floyd+传递闭包)
Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...
- POJ3660:Cow Contest(Floyd传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16941 Accepted: 9447 题目链接 ...
- POJ3660 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: 17797 Accepted: 9893 De ...
- POJ3660 Cow Contest floyd传递闭包
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ-3660 Cow Contest Floyd传递闭包的应用
题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...
- POJ 3660 Cow Contest ( 最短路松弛思想应用 && Floyd求传递闭包 )
题意 : 给出 N 头奶牛在比赛的结果,问你最多的能根据给出结果确定其名次的奶牛头数.结果给出的形式为 A B 代表在比赛当中 A 战胜了 B 分析 : 对于一头奶牛来说,如果我们能确定其他 N - ...
- poj3660 Cow Contest(Floyd-Warshall方法求有向图的传递闭包)
poj3660 题意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 分析: 在这呢先说一下关系闭包: 关系闭包有三种: 自反闭包(r), 对 ...
随机推荐
- Android 程序打包及签名(转)
为什么要签名??? 开发Android的人这么多,完全有可能大家都把类名,包名起成了一个同样的名字,这时候如何区分?签名这时候就是起区分作用的. 由于开发商可能通过使用相同的Package Name来 ...
- 8 -- 深入使用Spring -- 2...3 使用@Resource配置依赖
8.2.3 使用@Resource配置依赖 @Resource 位于javax.annotation包下,是来自Java EE规范的一个Annotation,Spring直接借鉴了该Annotatio ...
- 基础SELECT实例
SELECT查询语句 ---进行单条记录.多条记录.单表.多表.子查询…… SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [MAX_ST ...
- 【GIS】地球经纬度和米换算(转)
经度的定义是过某点的经线面和本初子午面之间的夹角.纬度的定义是过某点的球面切面垂线与赤道平面之间的线面角.可见,如果不加限定,1"之间的距离没有意义. 假设地球为一半径为R的表面光滑圆球体, ...
- 【代码审计】iCMS_v7.0.7 search.admincp.php页面存在SQL注入漏洞
0x00 环境准备 iCMS官网:https://www.icmsdev.com 网站源码版本:iCMS-v7.0.7 程序源码下载:https://www.icmsdev.com/downloa ...
- HTML 样式
style 属性用于改变 HTML 元素的样式,常见的样式如下: 定义字体颜色:style="color:red"定义字体大小:style="font-size:20px ...
- C语言结构体和指针
指针也可以指向一个结构体,定义的形式一般为: struct 结构体名 *变量名; 下面是一个定义结构体指针的实例: struct stu{ char *name; //姓名 int num; //学号 ...
- windows下nodejs与coffeeScript环境搭建
[本文档摘抄自网上资料] 安装NodeJS和CoffeeScript方法 首先安装Node(因为nodeJs是服务器端javascript运行环境),到http://nodejs.org/下载对应格式 ...
- codeforces水题100道 第九题 Codeforces Beta Round #63 (Div. 2) Young Physicist (math)
题目链接:http://www.codeforces.com/problemset/problem/69/A题意:给你n个三维空间矢量,求这n个矢量的矢量和是否为零.C++代码: #include & ...
- 【cs229-Lecture12】K-means算法
上课内容: 无监督学习: K-means聚类算法 混合高斯模型 jensen不等式(用于推导出EM算法的一般形式) EM(Expectation Maximization)算法(最大期望算法) K-m ...