POJ 3660—— Cow Contest——————【Floyd传递闭包】
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
* 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
Output
* Line 1: A single integer representing the number of cows whose ranks can be determined
Sample Input
5 5
4 3
4 2
3 2
1 2
2 5
Sample Output
2 题目大意:有n头牛,m个击败关系。问你最后有多少头牛的名次是可以确定的。 解题思路:Floyd传递闭包后,判断牛i前面有多少头牛,他后边有多少头牛。如果前后牛的头数等于n-1,那么说明他是可以确定名次的。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int d[300][300];
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
int a,b;
for(int i = 0; i < m;i++){
scanf("%d%d",&a,&b);
d[a][b] = 1;
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
d[i][j] = (d[i][j]|| (d[i][k]&&d[k][j]));
}
}
}
int res = 0;
for(int i = 1; i <= n; i++){
int num = 0;
for(int j = 1; j <=n; j++){
if(j == i) continue;
if(d[i][j] || d[j][i]) num++;
}
if(num == n-1) res++;
}
printf("%d\n",res);
}
return 0;
}
POJ 3660—— Cow Contest——————【Floyd传递闭包】的更多相关文章
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- poj 3660 Cow Contest (传递闭包)
/* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...
- POJ 3660 Cow Contest (Floyd)
题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...
- POJ - 3660 Cow Contest(传递闭包)
题意: n个点,m条边. 若A 到 B的边存在,则证明 A 的排名一定在 B 前. 最后求所有点中,排名可以确定的点的个数. n <= 100, m <= 4500 刚开始还在想是不是拓扑 ...
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ3660 Cow Contest —— Floyd 传递闭包
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
随机推荐
- 搭建TensorFlow
网上有许多在线安装TensorFlow框架的,我试了好多,结果安装时间长先不说,还总是出现一些问题,然后我就想着离线安装,成功了,与大家分享! (1)首先,需要下载离线安装的TensorFlow包,可 ...
- Python中的map_reduce
原教程地址: map/reduce-廖雪峰 将数值型字符串转换成数值,解释map, reduce的使用: #!/usr/bin/env python #-*- coding:utf-8 -*- ...
- Object Detection: Face Detection using Haar Cascades
目录 利用基于Haar特征的级联分类器实现人脸检测:官方教程 目标 学习基于Haar特征的级联分类器(Cascade Callifiers)实现人脸检测: 扩展到人眼检测: 基础知识 Paul V ...
- [翻译]CURAND Libaray--Host API--(2)
Translated by xingoo 如果有错误请联系:xinghl90@gmail.com 2.3 返回值 所有的CURAND host端的函数返回值都是curandStatus_t.如果调用没 ...
- c#随笔-正则
- 【转】C#中HttpWebRequest的GetRequestStream执行的效率太低,甚至偶尔死掉
http://www.cnblogs.com/summer_adai/archive/2013/04/26/3045261.html
- kali2017.2之***ss安装与使用
一.命令行安装:apt-get install python-pip ###安装pipsudo pip install shadowsocks ###安装ssgedit /etc/shad ...
- SprimgMVC学习笔记(三)—— 参数绑定
一.默认支持的参数类型 1.1 需求 打开商品编辑页面,展示商品信息. 1.2 需求分析 编辑商品信息,首先要显示商品详情 需要根据商品id查询商品信息,然后展示到页面. 请求的url:/itemEd ...
- ubuntu中误删/var/lib/dpkg/info的补救方法
今晚在ubuntu上安装一个软件时,出现这样的错误提示:E: Sub-process /usr/bin/dpkg returned an error code (1)然后在网上找了查找问题原因及解决方 ...
- Linux忘记roo密码的解决办法
Linux忘记root密码有三种解决办法: 下面详细介绍第一种: 重启系统后出现GRUB界面在引导装载程序菜单上,用上下方向键选择你忘记密码的那个系统键入“e” 来进入编辑模式. 接下来你可以看到 ...