Cow Contest

题目链接:

http://acm.hust.edu.cn/vjudge/contest/122685#problem/H

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.

</big>

##Input
<big>
* 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
</big> ##Output
<big>
* Line 1: A single integer representing the number of cows whose ranks can be determined
</big> ##Sample Input
<big>
5 5
4 3
4 2
3 2
1 2
2 5
</big> ##Sample Output
<big>
2
</big> ##Hint
<big>
</big> <br/>
##题意:
<big>
给出N个点,M个点对:
每条点对 A B 意味着A点的权值大于B点.
现在要对这些点进行权值排名,求有多少个点的排名能够确定.
</big> <br/>
##题解:
<big>
将样例画一遍就比较容易看出来:
若某点跟其他n-1个点都联通,则这个点的排名可以确定. 否则不能.
问题就转换为了求n个点之间的联通关系.
而floyd算法正好可以求任意两点的联通关系,只需要把求最短路时的松弛操作修改一下即可.
dis[i][j] = dis[i][j] || (dis[i][k] && dis[k][j]);
</big> <br/>
##代码:
``` cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define mid(a,b) ((a+b)>>1)
#define LL long long
#define maxn 110
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std; int n, m;
bool dis[maxn][maxn]; void floyd() {
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
dis[i][j] = dis[i][j] || (dis[i][k] && dis[k][j]);
} int main(int argc, char const *argv[])
{
//IN; while(scanf("%d %d", &n,&m) != EOF)
{
memset(dis, 0, sizeof(dis));
for(int i=1; i<=n; i++) dis[i][i] = 1; for(int i=1; i<=m; i++) {
int u,v; scanf("%d %d", &u,&v);
dis[u][v] = 1;
} floyd(); int ans = 0;
for(int i=1; i<=n; i++) {
int cnt1=0, cnt2=0;
for(int j=1; j<=n; j++) {
if(i == j) continue;
if(dis[i][j]) cnt1++;
if(dis[j][i]) cnt2++;
}
if(cnt1+cnt2 == n-1) ans++;
} printf("%d\n", ans);
} return 0;
}

POJ 3660 Cow Contest (floyd求联通关系)的更多相关文章

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

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

  2. POJ 3660 Cow Contest (Floyd)

    题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...

  3. POJ 3660 Cow Contest(求图的传递性)

    题意: 给定n头牛, 然后有m个比较, 求出有多少头牛能确定自己的排名. 分析: 假设有一头牛a, 有ki头牛强于自己, kj头牛弱于自己, ki + kj == n-1时, 那么这头牛的排名就确定了 ...

  4. 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 ...

  5. POJ 3660 Cow Contest 传递闭包+Floyd

    原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  6. POJ 3660 Cow Contest

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  7. POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16341   Accepted: 9146 Desc ...

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

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  9. POJ 3660 Cow Contest【Floyd 传递闭包】

    传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...

随机推荐

  1. IOSSelector的用法

    1.首先,@selector 里面的方法不能传参数..不要相信网上的..都是复制粘贴的.2.分三步走:1.设置tag.2.设置btn的调用方法.3.使用参数2.看示例代码把..   UIButton ...

  2. Android XML使用的学习记录

    1. 注释其中一段代码或是一行,可以采用<!-- -->,示例如下 <!--       <EditText         android:layout_width=&quo ...

  3. 【HDOJ】5632 Rikka with Array

    1. 题目描述$A[i]$表示二级制表示的$i$的数字之和.求$1 \le i < j \le n$并且$A[i]>A[j]$的$(i,j)$的总对数. 2. 基本思路$n \le 10^ ...

  4. JAVA中,不同工程间的方法调用

    可以调用, 用配置构建路径的方法:点选工程1, 点击右键, 选择 Build Path(构建路径) - > Configure Build Path...(配置构建路径...)然后在弹出的窗口中 ...

  5. 双方都在线,qq总是离线发文件

    这是qq支持多地登录后出现的问题. 原因:1.当您传文件给对方,对方是多终端登录(或者开通移动在线功能)的情况下,为了保证对方一定能收到该文件,我们会智能的为用户切换到离线文件,对方会相应在所在的终端 ...

  6. 关于BigDecimal的四舍五入和截断 (2007-08-10 15:06:26)

    关于四舍五入:ROUND_HALF_UP: 遇到.5的情况时往上近似,例: 1.5 ->;2ROUND_HALF_DOWN : 遇到.5的情况时往下近似,例: 1.5 ->;1 BigDe ...

  7. poj 3264 Balanced Lineup (RMQ算法 模板题)

    RMQ支持操作: Query(L, R):  计算Min{a[L],a[L+1], a[R]}. 预处理时间是O(nlogn), 查询只需 O(1). RMQ问题 用于求给定区间内的最大值/最小值问题 ...

  8. [反汇编练习] 160个CrackMe之002

    [反汇编练习] 160个CrackMe之002. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  9. Brew 编译mod错误Error: L6265E: Non-RWPI Section libspace.o(.bss) cannot be assigned to PI Exec region ER_ZI

    Error: L6265E: Non-RWPI Section libspace.o(.bss) cannot be assigned to PI Exec region ER_ZI.: Error: ...

  10. 多个SSH key对应多个Host: Github, Bitbucket

    https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-lin ...