题目链接:http://poj.org/problem?id=3660

Cow Contest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13085   Accepted: 7289

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 ≤ NA ≠ 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

Source

 
 
 
题解:
1.建图:如果A>B,则A—>B建一条边(B—>A也可以,但只能规定方向地建一条边)。
2.用Floyd求出传递闭包。
3.对于当前点X,如果与剩下的n-1个点都有联系,那么X的位置是可以确定的。
 
 
 
 
代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++)
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e2+; int n, m;
bool gra[MAXN][MAXN]; int main()
{
while(scanf("%d%d", &n,&m)!=EOF)
{
memset(gra, false, sizeof(gra));
for(int i = ; i<=m; i++)
{
int u, v;
scanf("%d%d", &u,&v);
gra[u][v] = true;
} for(int k = ; k<=n; k++) //求传递闭包
for(int i = ; i<=n; i++)
for(int j = ; j<=n; j++)
gra[i][j] = gra[i][j] || (gra[i][k]&&gra[k][j]); int ans = ;
for(int i = ; i<=n; i++)
{
int cnt = ;
for(int j = ; j<=n; j++)
if( gra[i][j] || gra[j][i] )
cnt++;
if(cnt==n-) //i与剩下的n-1个数都能确定关系,则i的位置确定
ans++;
} printf("%d\n", ans);
}
}

POJ3660 Cow Contest —— Floyd 传递闭包的更多相关文章

  1. POJ3660——Cow Contest(Floyd+传递闭包)

    Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...

  2. POJ-3660 Cow Contest Floyd传递闭包的应用

    题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...

  3. POJ3660 Cow Contest floyd传递闭包

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  4. POJ3660:Cow Contest(Floyd传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16941   Accepted: 9447 题目链接 ...

  5. POJ-3660.Cow Contest(有向图的传递闭包)

      Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17797   Accepted: 9893 De ...

  6. ACM: POJ 3660 Cow Contest - Floyd算法

    链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Descri ...

  7. POJ 3660 Cow Contest(传递闭包floyed算法)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  8. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  9. poj 3660 Cow Contest (传递闭包)

    /* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...

随机推荐

  1. Spoj-BITDIFF Bit Difference

    Given an integer array of N integers, find the sum of bit differences in all the pairs that can be f ...

  2. linux虚拟机无法上网 Network is unreachable

    系统centos 安装ftp时报错 Couldn't resolve host 'mirrorlist.centos.org [root@wulihua bin]#  yum install vsft ...

  3. Java面试题集(一)

    作为一名java开发软件工程,一定要记住,基础非常重要,往往就是一些基础,很简单,但是你就是不知道实现原理,为什么使用,有没有自己去发现,对比,差异从而总结,有些东西看似简单,但是不一定你描述清楚,直 ...

  4. 安卓解析JSON文件

    安卓解析JSON文件 根据JOSN文件的格式,文件只有两种数据,一是对象数据,以 {}为分隔,二是数组,以[]分隔 以下介绍安卓如何解析一个JSON文件,该文件存放在assets目录下,即:asset ...

  5. Mongodb报错:ERROR: child process failed, exited with error number 1

    Mongodb在启动时报错: 2018-10-16T11:18:54.533+0800 I CONTROL [main] Automatically disabling TLS 1.0, to for ...

  6. Mybatis resultMap空值映射问题

    参考博客:https://www.oschina.net/question/1032714_224673 http://stackoverflow.com/questions/22852383/how ...

  7. HDU 4341 Gold miner(分组背包)

    题目链接 Gold miner 目标是要在规定时间内获得的价值总和要尽可能大. 我们先用并查集把斜率相同的物品分在同一个组. 这些组里的物品按照y坐标的大小升序排序. 如果组内的一个物品被选取了,那该 ...

  8. Python种使用Excel

    今天用到Excel的相关操作,看了一些资料,借此为自己保存一些用法. 参考资料: python excel 的相关操作 python操作excel之xlrd python操作Excel读写--使用xl ...

  9. Spring 详解(一)------- AOP前序

    目录 1. AOP 简介 2. 示例需求 3. 解决方法一:使用静态代理 4. 解决方法二:使用动态代理 1. AOP 简介 ​ AOP(Aspect Oriented Programming),通常 ...

  10. 【Java TCP/IP Socket】深入剖析socket——TCP通信中由于底层队列填满而造成的死锁问题(含代码)

    基础准备 首先需要明白数据传输的底层实现机制,在http://blog.csdn.net/ns_code/article/details/15813809这篇博客中有详细的介绍,在上面的博客中,我们提 ...