题目链接: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. 存储过程Oracle(一)

    一.简介 存储过程:就是在数据库中创建的一段程序,供别人调用 .其实我感觉跟定义一个方法相似 二.无参存储过程 如下,经典的输出"Hello World"来入门存储过程 创建一个存 ...

  2. jstl c:choose>、<c:when>和<c:otherwise>标签

    <c:choose>.<c:when>和<c:otherwise>在一起连用,可以实现Java语言中的if-else语句的功能.例如以下代码根据username请求 ...

  3. Jquery中的prop()方法 全选或全不选

    注意: prop()在高版本才会有效, 低版本用attr(); $(function(){ // 元素checkbox var aChecked = $('.checkGoods'); // 全选 v ...

  4. Ubuntu 14.10 下安装Sublime Text 3,注册码,中文输入法

    1 下载Sublime Text 3,网址http://www.sublimetext.com/3 2 双击deb安装 3 因为需要需要付费,输入下面的注册码,下面的注册码,来自百度,亲测可行 Sub ...

  5. openstack 本地化

    研究了一下 openstack中的本地化:主要使用gettext模块: 其中本地化包括对一般字符串的本地化和log的本地化:   (1) _localedir = os.environ.get('es ...

  6. 【LeetCode OJ】Linked List Cycle

    Problem link: http://oj.leetcode.com/problems/linked-list-cycle/ We set two pointers: the faster poi ...

  7. 【LEETCODE OJ】Binary Tree Preorder Traversal

    Problem Link: http://oj.leetcode.com/problems/binary-tree-preorder-traversal/ Even iterative solutio ...

  8. Windows共享设定-使用net use添加网络盘带上账号密码

    食欲 net use \\10.11.1.2\ipc$ /user:dmnm\usr "pwd"

  9. GIT之二 基础篇(1)

    GIT基础 取得项目的 Git 仓库 有两种取得 Git 项目仓库的方法.第一种是在现存的目录下,通过导入所有文件来创建新的 Git 仓库.第二种是从已有的 Git 仓库克隆出一个新的镜像仓库来. 在 ...

  10. show master status empty解决方案

    The following MySQL error might occur if you are using MySQL replication and binary logs. mysql> ...