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时可以知道排名,即为 ...
随机推荐
- IEnumerable、GetEnumerator、IEnumerator之间的关系。
了解了这些也就明白了遍历的原理,晚安. using System; using System.Collections; public class Person { public Person(stri ...
- 「BZOJ 3209」花神的数论题
Title Link 戳我 Title Solution 这道题可以运用组合数的思想啊,数位dp也可以,随便你怎么做,这里就讲一讲组合数的做法吧,要小于n,所以我们可以枚举n二进制下1的位置,在i-1 ...
- .db轻量级本地数据库
1.概述: db文件一般是数据库数据存放文件. db是datebase的缩写,是数据库文件. 我们可以简单的理解为db是本地轻量级数据库(用了缓存,储存少量本地数据,防止断电等突发意外的发生对我们的程 ...
- 变量声明和定义的关系------c++ primer
为了允许把程序分成多个逻辑部分来编写,c++语言支持分离式编译机制 为了支持分离式编译,c++语言把声明和定义区分开来.声明(declaration)使得名字为程序所知,一个文件如果想使用别处定义的名 ...
- opencv3.3.1+vs2015+c++实现直接在图像上画掩码,保存掩码图片
左键红右键蓝,保存为k #include "opencv2\imgproc\imgproc.hpp" // Gaussian Blur #include "opencv2 ...
- Selenium API(二)
1.定位一组元素 WebDriver提供了8种定位一组元素的方法. driver.find_elements_by_css_selector() driver.find_elements_by_tag ...
- 51 nod 1350 斐波那契表示
每一个正整数都可以表示为若干个斐波那契数的和,一个整数可能存在多种不同的表示方法,例如:14 = 13 + 1 = 8 + 5 + 1,其中13 + 1是最短的表示(只用了2个斐波那契数).定义F(n ...
- C#下Excel的普通处理和报表设计
一.准备:想要操作Excel,先要在添加2个COM引用: 1.Microsoft Excel 14.0 Object Library (版本不同14.0也可能是12.0等) 2.Microsoft O ...
- Linux 调节分辨率
首先,你要有 GUI 才能设置分辨率 Tool of xrandr xrandr -s 1360x768
- NetworkX初相识
听说NetworkX是一个很牛的复杂网络研究的工具,就来试一下吧. import networkx as nx G= nx.Graph()#建立一个空白的图 G.add_node("node ...