nyoj 211——Cow Contest——————【floyd传递闭包】
Cow Contest
- 描述
-
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.
- 输入
- * 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 BThere 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传递闭包】的更多相关文章
- NYOJ 211 Cow Contest (弗洛伊德+传递闭包 )
title: Cow Contest 弗洛伊德+传递闭包 nyoj211 tags: [弗洛伊德,传递闭包] 题目链接 描述 N (1 ≤ N ≤ 100) cows, conveniently nu ...
- POJ3660——Cow Contest(Floyd+传递闭包)
Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...
- POJ3660 Cow Contest —— Floyd 传递闭包
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ-3660 Cow Contest Floyd传递闭包的应用
题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...
- POJ3660 Cow Contest floyd传递闭包
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- nyoj 211 Cow Contest
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=211 思路:我的思路是对每一个点,向上广搜,向下广搜,看总共能不能搜到n-1个结点,能,表 ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
随机推荐
- GeoServer中GeoWebCache(GWC)的使用
本文介绍GeoWebCache的使用方法,包括如何切缓存,访问缓存wms/wmts服务,如何复用栅格缓存等. 文章大部分内容转载自https://www.cnblogs.com/naaoveGIS/p ...
- Docker 的部署方式
在使用 docker run 命令启动 Docker 容器时,如果需要进行端口映射.目录挂载.网络信息等配置,整条命令将变得非常长,并且由于是一条 shell 命令,修改和复用也不方便.我们在大规模部 ...
- Mysql初识数据库《三》数据库概述
1 什么是数据(Data) 描述事物的符号记录称为数据,描述事物的符号既可以是数字,也可以是文字.图片,图像.声音.语言等,数据由多种表现形式,它们都可以经过数字化后存入计算机 在计算机中描述一个事物 ...
- YARN 的调度选项
YARN 中有三种调度器: 1. FIFO 调度器 (FIFO Scheduler) 应用在一个队列中,按照提交的顺序运行应用. 缺点:小作业如果在大作业后面提交,将会一直等到大作业结束才运行. 2. ...
- centos6.5 git clone http 报错
自己搭建服务器环境为centos6.5,需要使用git clone 命令的时候报错 首先查看centos上安装的git版本,我的版本为1.7.10 报错后,查阅相关资料需将centos升级,操作如下 ...
- [Swift]八大排序算法(五):插入排序
排序分为内部排序和外部排序. 内部排序:是指待排序列完全存放在内存中所进行的排序过程,适合不太大的元素序列. 外部排序:指的是大文件的排序,即待排序的记录存储在外存储器上,待排序的文件无法一次装入内存 ...
- The server of Apache (三)——网页优化
在企业中,部署apache后只采用默认的配置参数,会有很多问题,因为那些配置都是针对以前服务器配置的. 一.网页压缩 1.介绍 配置apache的网页压缩功能,是使用Gzip压缩算法来对apache服 ...
- PEP 8 – Style Guide for Python Code
原文:PEP 8 – Style Guide for Python Code PEP:8 题目:Python代码风格指南 作者:Guido van Rossum, www.yszx11.cnBarry ...
- ubtuntu 如何查看内存用量 mongostat详解
free -h top free或者top或者cat /proc/meminfo mongostat是mongdb自带的状态检测工具,在命令行下使用.它会间隔固定时间获取mongodb的当前运行状态, ...
- 6. 重点来啦,pytest的各种装饰圈fixtures
pytest中,fixture的目的是什么 为可靠的和可重复执行的测试提供固定的基线.(可以理解为测试的固定配置,使不同范围的测试都能够获得统一的配置.) fixture提供了区别于传统单元测试(se ...