(中等) 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 ...
随机推荐
- 转 [分享一个SQL] 查会话阻塞关系,层次关系.
with ash as (select /*+ materialize*/* from DBA_HIST_ACTIVE_SESS_HISTORY where sample_time between ...
- 转 Oracle 12c 使用scott等普通用户的方法
一.前言 最近电脑上安装了oracle 12c数据库,想体验下新特性.安装完后,便像11g一样在dos窗口进行下面的操作: SQL*Plus: Release 12.1.0.2.0 Productio ...
- Java中的一些术语的解释
一 API(Application Programming Interface,应用程序编程接口) 简单来说,就是其他人开发出来一块程序,你想用,他会告诉你调用哪个函数,给这个函数传什么参数,然后又 ...
- GCD is Funny
GCD is Funny Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- linux命令chown和chmod什么区别
chown一般用来 更改属主.也就是文件所属用户.chmod功能要比chown要强大.可更改文件所有属性和权限.只有管理员账户才有权限用此命令. chown 是修改文件的所有者(owner),和所属组 ...
- 自动打开notepad 并写入数据
import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; import java.io. ...
- 学习笔记——Windows下cocos2d-x,eclipse中自编译
cocos2d-x创建的安卓项目导入eclipse后. 在项目属性中配置Builders. 在eclipse编译还需要配置相应的变量,即后面提到的cygwin编译中要添加的变量. D:/cygdriv ...
- Chapter 1 First Sight——18
But at least he sent me to an empty desk at the back without introducing me to the class. 但是最后他给我最后面 ...
- JSP标签编程--简单标签
javax.servlet.jsp.tagext里的类SimpleTagSupport 使用SimpleTagSupport类一网打尽以往复杂的标签开发,直接使用doTag()方法 java文件: p ...
- Servlet程序开发-- servlet跳转
跳转:服务器端,客户端 客户端跳转:<response.sendRedirect>地址栏跳转之后改变,无法传递request范围的属性 服务器端跳转:<jsp:forward> ...