Cow Contest

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述

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.

 
输入
* 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

There are multi test cases.The input is terminated by two zeros.The number of test cases is no more than 20.

输出
For every case:
* Line 1: A single integer representing the number of cows whose ranks can be determined
样例输入
5 5
4 3
4 2
3 2
1 2
2 5
0 0
样例输出
2

题目大意:给你n,m表示n位大牛,有m对能力比较关系,表示a能打败b。问你最后几个人的排名可以确定。

解题思路:首先用floyd传递闭包,然后枚举统计排名可以确定的人数。某大牛的排名确定,则应该有他与其他n-1个人关系确定,败或赢。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=120;
int d[maxn][maxn];
void floy(int n){
int i,j,k;
for(k=1;k<=n;k++){
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
d[i][j]=d[i][j]||(d[i][k]&&d[k][j]);
}
}
}
}
int work(int n){
int ret=0,sum,k,i,j;
for(k=1;k<=n;k++){
sum=0;
for(i=1;i<=n;i++){
if(i==k) continue;
if(d[k][i]){
sum++;
}
if(d[i][k]){
sum++;
}
}
if(sum==n-1)
ret++;
}
return ret;
}
int main(){
int n,m,i,j,k,a,b;
while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
memset(d,0,sizeof(d));
for(i=0;i<m;i++){
scanf("%d%d",&a,&b);
d[a][b]=1;
}
floy(n);
printf("%d\n",work(n)) ;
}
return 0;
}

  

nyoj 211——Cow Contest——————【floyd传递闭包】的更多相关文章

  1. NYOJ 211 Cow Contest (弗洛伊德+传递闭包 )

    title: Cow Contest 弗洛伊德+传递闭包 nyoj211 tags: [弗洛伊德,传递闭包] 题目链接 描述 N (1 ≤ N ≤ 100) cows, conveniently nu ...

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

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

  3. POJ3660 Cow Contest —— Floyd 传递闭包

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

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

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

  5. POJ3660 Cow Contest floyd传递闭包

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

  6. nyoj 211 Cow Contest

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=211 思路:我的思路是对每一个点,向上广搜,向下广搜,看总共能不能搜到n-1个结点,能,表 ...

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

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

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

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

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

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

随机推荐

  1. ECS服务里或者阿里云服务器的二级域名设置方法

    我们要实现的效果是,xuxinshuai.abc.com ,具体怎么实现,看下面的流程 第一步:备案域名要有,假如就是www.abc.com 第二步:网站的服务器是IIS的情况下,在部署网站时,需要设 ...

  2. JavaScript中事件冒泡之实例理解

    此#btnComfirmChooseCompany是Bootstrap模态弹层上的按钮,但点击后,点击事件被Bootstrap外层监听到了, 效果就是模态弹出层被关闭了,所以,我不想这个点击事件被&q ...

  3. Codeforces Round #549 (Div. 2)A. The Doors

    A. The Doors time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. <id name="ID"> <generator class="assigned" /> </id>

    <generator>表示一个主键的生成机制.即具体通过何种方式来生成.生成方式包括:increment:生成long, short或者int类型的主键,不能在cluster环境下使用.适 ...

  5. javaweb面试一

    1.forward与redirect区别,说一下你知道的状态码,redirect的状态码是多少? 状态码 说明 200 客户端请求成功 302 请求重定向,也是临时跳转,跳转的地址通过Location ...

  6. 加载 xib 文件 UIView

    记在 UIView 的 xib 文件方式有一下几种: 一 .直接加载 xib 文件, 没有.h.m 文件 1. NSBundle 方式 NSArray *objs = [[NSBundle mainB ...

  7. 【解决】Linux Tomcat启动慢--Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [236,325] milliseconds

    一.背景 今天部署项目到tomcat,执行./startup.sh命令之后,访问项目迟迟加载不出来,查看日志又没报错(其实是我粗心了,当时tomcat日志还没打印完),一开始怀疑是阿里云主机出现问题, ...

  8. HTTP记录

    -------------TCP握手协议------------- 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接. [第一次握手]建立连接时,客户端发送syn包(syn ...

  9. 基于中间件的RBAC权限控制

    RBAC 是什么 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联. 在 Django 中,权限就是用户对一个包含正则表达式 url ...

  10. sharepoint_study_2

    描述:向SharePoint中批量添加用户 解决:原文地址:http://bbs.winos.cn/thread-89236-1-1.html 一般情况下,要想登录SharePoint server ...