(中等) POJ 3660 Cow Contest,Floyd。
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.
题目就是求有几头牛的排名确定了,用Floyd算法,如果a胜了b,就建边a->b,然后Floyd,然后枚举每一个点,对于这个点,如果所有其余的点与他的位置都确定了的话(也就是两点之间的最短路不为INF),那么这个点就是位置确定的点。
代码如下:
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std; const int INF=10e8; int N,M;
int map1[][]; int main()
{
int a,b;
int ans;
bool ok; while(cin>>N>>M)
{
for(int i=;i<=N;++i)
for(int j=;j<=N;++j)
map1[i][j]= i==j ? : INF; for(int i=;i<=M;++i)
{
cin>>a>>b;
map1[a][b]=;
} for(int k=;k<=N;++k)
for(int i=;i<=N;++i)
for(int j=;j<=N;++j)
map1[i][j]=min(map1[i][j],map1[i][k]+map1[k][j]); ans=N; for(int i=;i<=N;++i)
{
ok=; for(int j=;j<=N;++j)
if(map1[i][j]==INF && map1[j][i]==INF)
{
ok=;
break;
} if(!ok)
--ans;
} cout<<ans<<endl;
} return ;
}
(中等) POJ 3660 Cow Contest,Floyd。的更多相关文章
- 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)
题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...
- 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 传递闭包+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 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
- POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
随机推荐
- Day02——widow对象
window - 计时器 1、setTimeout()可以用来在指定的时间之后单次调用函数. setTimeount(f,1000);//一秒后调用函数f clearTimeout();取消函数的执行 ...
- php过滤HTML标签、属性等正则表达式汇总
$str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...
- NSIndexPath 延伸
转载自:http://my.oschina.net/u/2560887/blog/602095?fromerr=Dy4vj5Jd 这个类的实例描述了一个嵌套数组中特定节点的路径,一般叫做索引路径.1. ...
- AutoTile 自动拼接(六 大结局) 学习与实践
昨天在网上找了一些资源图片,这回就不用担心 背景资源不多的问题了,现在我一边 制作,一边发布文章. 各种各样,500多个,这里还是特别感谢 ,万恶的资本主义,不设密码就给我分享. 在制作前,大家看下这 ...
- android 去掉listview之间的黑线
方法1:listView.setDividerHeight(0);方法2:this.getListView().setDivider(null);方法3:android:divider="@ ...
- hdu_2222_Keywords Search(AC自动机板子)
题目连接:hdu_2222_Keywords Search 存个自己写的AC自动机 #include<cstdio> #include<cstring> #define F(i ...
- 改MAC地址
Google TMAC v6. Or click here
- OSPF的基本配置及DR /BDR选举的实验
OSPF的基本配置及DR /BDR选举的实验 实验拓扑: 实验目的:掌握OSPF的基本配置 掌握手工指定RID 掌握如何修改OSPF的接口优先级 观察DR BDR选举的过程 实验要求:R3当选为DR ...
- 8、代理模式(Proxy)
其实每个模式名称就表明了该模式的作用,代理模式就是多一个代理类出来,替原对象进行一些操作,比如我们在租房子的时候回去找中介,为什么呢?因为你对该地区房屋的信息掌握的不够全面,希望找一个更熟悉的人去帮你 ...
- gen_compile.sql
set echo off pagesize 0 feedback off define v_input_un = &1define v_input_pw = & ...