ACM: POJ 3660 Cow Contest - Floyd算法
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
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轮比较后,能够知道多少只牛具体的排名。 用Floyd算法去判断n只牛相互的关系,如果某一只牛和另外n-1只牛都建成了关系,就说明这只牛已经嫩排除顺序了。 AC代码:
/*/
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"queue"
#include"cmath"
using namespace std;
typedef long long LL ;
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define FK(x) cout<<"["<<x<<"]\n" int cow[105][105]; void Floyd(int n) {
for(int k=1; k<=n; k++) {
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cow[i][j]=cow[i][j]||(cow[i][k]&&cow[k][j]); //如果两头牛本身关系已经确定或者两头牛和某一头牛同时形成顺序关系,这两头牛的关系就被了确定。
// cout<<"["<<cow[i][j]<<"]";
}
// puts("");
}
// puts("");
}
} int main() {
int n,m,w,l,num,ans;
while(~scanf("%d%d",&n,&m)) {
memset(cow,0);
for(int i=0; i<m; i++) {
scanf("%d%d",&w,&l);
cow[w][l]=1;
}
Floyd(n);
ans=0;
for(int i=1; i<=n; i++) {
num=0;
for(int j=1; j<=n; j++) {
if(cow[i][j]||cow[j][i])num++;//如果这头牛和其他牛的关系被确定就计数 。
}
if(num==n-1)ans++;//如果该牛和其他所有的牛关系都确定了,这头牛的位置就已经找到了。
}
printf("%d\n",ans);
}
return 0;
}
ACM: POJ 3660 Cow Contest - Floyd算法的更多相关文章
- 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 题目链接: 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:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- (中等) POJ 3660 Cow Contest,Floyd。
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
随机推荐
- jquery学习笔记----元素筛选
1.eq() 筛选指定索引号的元素2.first() 筛选出第一个匹配的元素3.last() 筛选出最后一个匹配的元素4.hasClass() 检查匹配的元素是否含有指定的类5.filter() 筛 ...
- ASP.NET MVC 使用带有短横线的html Attributes(转载)
转载地址:http://www.nmtree.net/2013/10/25/asp-net-mvc-use-dash-in-html-attributes.html 情景再现 我们常常需要一个文本框来 ...
- 【翻译二十】-java线程池
Thread Pools Most of the executor implementations in java.util.concurrent use thread pools, which co ...
- phpcms调用一级栏目和二级栏目
{loop subcat(,,,$siteid) $r} {php $num++} <strong><a href=} <br /> {elseif $n!=$c} | ...
- LIS的nlogn
nlogn老忘,开个帖记录一下 开一个栈,每次取栈顶元素top和读到的元素temp做比较,如果temp > top 则将temp入栈:如果temp < top则二分查找栈中的比temp大的 ...
- 11g新特性-如何禁用自动统计信息收集作业
一.11g中auto stats gather job被集成到了auto task中. SQL> select client_name,status from DBA_AUTOTASK_CLIE ...
- Asp.Net MVC中DropDownListFor的用法
在Asp.Net MVC中可以用DropDownListFor的方式来让用户选择已定列表中的一个数值.用法不复杂,这里简单做一个记录. 首先我们要定义一个 Model ,用户在 DropDownLis ...
- BZOJ 2152: 聪聪可可 树分治
2152: 聪聪可可 Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一 ...
- loj 1036(dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25913 思路:易证存在一条从左上角到右下角的折线,沿着格子边缘的. ...
- Socket 通讯
#import "ViewController.h" #import <sys/socket.h> #import <netinet/in.h> #impo ...