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时可以知道排名,即为 ...
随机推荐
- 死磕Java之聊聊LinkedList源码(基于JDK1.8)
工作快一年了,近期打算研究一下JDK的源码,也就因此有了死磕java系列 LinkedList 是一个继承于AbstractSequentialList的双向链表,链表不需要capacity的设定,它 ...
- opencv3.3.1+vs2015+c++实现直接在图像上画掩码,保存掩码图片
左键红右键蓝,保存为k #include "opencv2\imgproc\imgproc.hpp" // Gaussian Blur #include "opencv2 ...
- 20165219第4次实验《Android程序设计》实验报告
20165219第4次实验<Android程序设计>实验报告 一.实验内容及步骤 (一)Android Stuidio的安装Hello world测试 要求 参考http://www.cn ...
- pycharm自动调整html页面代码缩进不正确的解决办法
pycharm自动调整html页面代码缩进不正确的解决办法
- GG and MM HDU - 3595 Every-SG
$ \color{#0066ff}{ 题目描述 }$ 两堆石子,GG和MM轮流取,每次在一堆石子中取另一堆石子的k\((k\ge1)\)倍,不能操作的输 现在二人要玩n个这样的游戏,每回合每个人对每个 ...
- P4855 MloVtry的idea
$ \color{#0066ff}{ 题目描述 }$ MloVtry是一个脑洞很大的人,它总会想出一些奇奇怪怪的idea. 可问题是,MloVtry作为一个蒟蒻,很多时候都没办法解决自己提出的问题,所 ...
- win7运行nodejs,返回IPV6:::ffff:127.0.0.1
问题: 在win7上使用telnet连接node生成的服务器,在获取ip的过程中出现的问题. win7默认开启IPV6,所以获取的IP地址带有::ffff:前缀. 如果程序中使用到了IP地址,有可能会 ...
- GTF/GFF文件的差异及其相互转换
我们在做生物分析的时候,经常会碰到GFF格式的文件以及GTF格式的注释文件.他们有着相似的名字,甚至连内容都极为相似~那么,他们究竟差在哪里呢? GFF全称为general feature forma ...
- C++_友元1-友元类是什么
友元函数:不是类的成员函数,但是能够访问类的私有数据成员. 之前有个矛盾就是规定非成员函数不能直接访问类的私有数据,但是这会儿却可以,但那只是针对常规非成员函数而言,特殊的非成员函数就可以访问类的私有 ...
- LeetCode936. Stamping The Sequence
一.题面 You want to form a target string of lowercase letters. At the beginning, your sequence is targe ...