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

Cow Contest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10066   Accepted: 5682

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

题目大意:有n头牛,然后有m个条件 每个条件有两个整数a,b表示a能打败b  然后问你有多少头牛能够确定名次。
解题思路:考虑到能够确定名次的牛需要满足一个条件(打败他的牛的个数加上他打败的牛的个数为n-1)
AC代码:
 #include <stdio.h>
#include <string.h>
int p[][];
int n,m;
void floyd()
{
int i,j,k;
for (k = ; k <= n; k ++)
{
for (i = ; i <= n; i ++)
{
for (j = ; j <= n; j ++)
{
if (p[i][k] && p[k][j]) //间接相连也表示能够打败
p[i][j] = ;
}
}
}
}
int main ()
{
int i,j,a,b;
while (~scanf("%d%d",&n,&m))
{
memset(p,,sizeof(p)); for (i = ; i < m; i ++)
{
scanf("%d%d",&a,&b);
p[a][b] = ;
}
floyd();
int ans,sum = ;
for (i = ; i <= n; i ++)
{
ans = ;
for (j = ; j <= n; j ++)
{
ans += p[i][j]; //他打败的牛的个数
ans += p[j][i]; //打败他的牛的个数
}
if (ans == n-)
sum ++;
}
printf("%d\n",sum);
}
return ;
}
												

POJ 3660 Cow Contest的更多相关文章

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

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

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

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

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

  4. POJ - 3660 Cow Contest 传递闭包floyed算法

    Cow Contest POJ - 3660 :http://poj.org/problem?id=3660   参考:https://www.cnblogs.com/kuangbin/p/31408 ...

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

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

  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(传递闭包 Floyd)

    链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...

  8. POJ 3660 Cow Contest (闭包传递)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7690   Accepted: 4288 Descr ...

  9. POJ 3660 Cow Contest (floyd求联通关系)

    Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...

随机推荐

  1. 北邮新生排位赛1解题报告d-e

    话说cdsn要是前面插入源代码又什么都不放就会出现奇怪的源代码?不知道是哪个网页的 407. BLOCKS 时间限制 1000 ms 内存限制 65536 KB 题目描述 给定一个N∗M的矩阵,求问里 ...

  2. winform的comboBox使鼠标滑轮修改值失效

    目标: winform窗体很多combobox下拉框,当他们其中的一个获得焦点的时候,如果滚动鼠标就会改变下拉框的值,要实现让鼠标滚轮不对下拉框的值造成影响 如下代码直接拷贝粘贴,不用修改 方法一: ...

  3. ubuntu php.ini文件位置

    mc@XJ > locate php.ini/etc/php5/cli/php.ini/etc/php5/fpm/php.ini

  4. BPM的四大主要类型

    随着网络的发展,移动BPM.社交BPM.云端BPM将顺应市场需求,成为BPM发展的新趋势,最终成为企业即时管控有效工具.BPM将不断促进制造业信息化的转型与发展.所以很少人会否认业务流程管理(BPM) ...

  5. Vi不显示insert

    edit file :/etc/vim/vimrc.tiny set compatible -> set nocompatible or install vim

  6. SharePoint 2013 Nintex Workflow 工作流帮助(十)

    博客地址 http://blog.csdn.net/foxdave 工作流动作 23. Create appointment(企业版才有) 该操作用于在Microsoft Exchange中创建一个商 ...

  7. 分享Windows Server 2012 R2的获取正版密钥方法

    然后使用“我有ISIC卡”验证,目前可用号码:S420546009858. 分享Windows Server 2012 R2的获取正版密钥方法. 首先登陆dreamspark注册一个账号https:/ ...

  8. IntelliJ IDEA 12.0

    User name:JavaDeveloper Serial number:92547-KY2BB-QZ0S1-PEZCV-HUT8Q-6RYY4

  9. win10 mac地址修改器

    NoVirus Thanks MAC Address Changer NoVirus Thanks MAC Address Changer is yet another simple MAC addr ...

  10. MyEclipse 安装目录下找不到Common目录

    最近在安装了MyEclipse,由于是自己指定的安装目录,在成功安装后要破解的时候却发现找不到安装目录下的Common目录,很是郁闷,后来发现如下: MyEclipse启动后的上方导航中找到MyEcl ...