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. Qt中QBitmap 的使用 --QBitmap的作用

    特别注意:如果想把做一个先把图画在内存中,在显示到页面,不要使用bitmap,这个只有单色: 一般情况下QBitmap只作为图片掩码使用,比如做不规则窗口. QBitmap表示一种只有黑白的单色图片, ...

  2. C#构造函数详解和析构函数详解

    首先来了解下构造函数的定义: C#构造函数是一种特殊的成员函数,它的作用主要用于为对象分配存储空间,对数据成员进行初始化. 接下来看一下他的语法定义形式: |访问修饰符| 标识符 (|参数列表|) | ...

  3. 十一、Node.js监听代码改动自动重启node插件supervisor

    我们慢慢地发现,每次我们稍微改变js代码都需要重启服务才能在浏览器显示新的效果,很麻烦,这里我们可以通过npm命令安装supervisoror插件,安装方法如下 之前章节我们知道安装了nodejs就会 ...

  4. 异常上报功能Bugly简介

    目的:为了能够快速定位到线上版本bug位置,经过比较之后,决定使用腾讯家的Bugly. 1.注册产品 官方文档使用指南 1.1 登录 - 使用 QQ 登录Bugly官网 没有账号就注册,要实名就实名, ...

  5. SQL数据库查询语言(1)

    目录 MySQL数据库 MySQL安装与配置 DDL数据定义语言 创建数据库 查看.删除数据库 修改.备份.恢复数据库 创建表 修改表 MySQL常用数据类型 DML数据操纵语言 Insert语句 m ...

  6. BDD 相关整理---介绍

    # BDD介绍 ### 什么是BDD Behavior-driven development In software engineering, behavior-driven development ...

  7. 递归缓存技术,缓存机制Memoization

    先看一下代码: 再看一下执行时间: 可以看出第一个阶乘的执行时间是3ms,后面的由于缓存了之前的计算结果,所以直接返回结果. 原理就是缓存之前的计算,避免重复计算.关键在于建立缓存数组. 可以看一下执 ...

  8. C++_基础1-基本数据类型

    面向对象(OOP)的本质是设计并扩展自己的数据类型.设计自己的数据类型就是让类型与数据匹配. 如果正确做到这一点,就会发现以后使用数据会容易很多.然而创建自己的类型之前,必须了解并理解C++内置类型. ...

  9. matlab的pdist函数详解

    Pairwise distance between pairs of object(Pdist函数用于各种距离的生成) 语法: D=pdist(x) D=pdist(x,distance) 解释: D ...

  10. [HNOI2014]抄卡组

    [Luogu3234] [LOJ2208] 题解及代码 锻炼哈希码力的一道题 , 具体细节见代码 #include<cstdio> #include<cstring> #inc ...