POJ3660 Cow Contest floyd传递闭包
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 Sample Output
题意:
有n头牛比赛,m种比赛结果,最后问你一共有多少头牛的排名被确定了,其中如果a战胜b,b战胜c,则也可以说a战胜c,即可以传递胜负。求能确定排名的牛的数目。
思路:
如果一头牛被x头牛打败,打败y头牛,且x+y=n-1,则我们容易知道这头牛的排名就被确定了,所以我们只要将任何两头牛的胜负关系确定了,在遍历所有牛判断一下是否满足x+y=n-1,将满足这个条件的牛数目加起来就是所求解。如果出度+入度=顶点数-1,则能够确定其编号。
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int map[][];
int n,m;
void floyd()
{
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(map[i][k]==&&map[k][j]==)//关系传递
map[i][j]=;
}
int main()
{
cin>>n>>m;
memset(map,,sizeof(map));
for(int i=;i<m;i++)
{
int a,b;
cin>>a>>b;
map[a][b]=;//单向边
}
floyd();
int ans=;
for(int i=;i<=n;i++)
{
int sum=;
for(int j=;j<=n;j++)
{
if((map[i][j]==||map[j][i]==)&&i!=j)
sum++;//计算出度和入度
}
if(sum==n-)
ans++;
}
cout<<ans;
}
POJ3660 Cow Contest floyd传递闭包的更多相关文章
- 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传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16941 Accepted: 9447 题目链接 ...
- POJ-3660.Cow Contest(有向图的传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17797 Accepted: 9893 De ...
- 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时可以知道排名,即为 ...
- poj 3660 Cow Contest (传递闭包)
/* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...
随机推荐
- 关于Handler的理解,子线程不能更新UI的纠正和回调的思考
开发Android这么久了,总会听到有人说:主线程不能访问网络,子线程不能更新UI.Android的主线程的确不能长时间阻塞,但是子线程为什么不能更新UI呢?今天把这些东西整理,顺便在子线程更新UI. ...
- R自带数据包
datasets(R自带数据包) 作者:王彦博 作品来源:百度百科 precip #长度为70的命名向量 euro #欧元汇率,长度为11,每个元素都有命名 landmasses #48个陆地的面积, ...
- Microsoft Excel 自动取数据库数据
1.下载安装mysql-connector-odbc-5.1.5-win32.msi 2.打开控制面板.搜索数据 3.点击添加→MySQL ODBC 5.1 Driver→完成 4.填写名称.IP地址 ...
- 导出CSV表格数据
<?php class Csv{ //导出csv文件 public function put_csv($list,$title){ $file_name="CSV".date ...
- [Android FrameWork 6.0源码学习] ViewGroup的addView函数分析
Android中整个的View的组装是采用组合模式. ViewGroup就相当与树根,各种Layout就相当于枝干,各种子View,就相当于树叶. 至于View类.我们就当它是个种子吧.哈哈! Vie ...
- php7.0版本不再以类名命名构造函数
<?php class Car { var $color = "add"; function Car($color="green") { $this-&g ...
- oracle批量数据导入工具 sqlldr
sqlldr工具参数: [oracle@server ~]$ sqlldr SQL*Loader: Release - Production on Wed Nov :: Copyright (c) , ...
- 反编译Unity3D手机游戏
[旧博客转移 - 2015年11月17日 10:08] 现在大部分U3D手游都没有进行加密处理,要反编译其实很简单 APK是安卓的安装包,安卓是基于Linux的,Linux的安装包一般都是zip,所以 ...
- Carbondata源码系列(一)文件生成过程
在滴滴的两年一直在加班,人也变懒了,就很少再写博客了,最近在进行Carbondata和hive集成方面的工作,于是乎需要对Carbondata进行深入的研究. 于是新开一个系列,记录自己学习Carbo ...
- html中的锚点
一.页面内跳转的锚点设置 页面内的跳转需要两步: 方法一: ①:设置一个锚点链接<a href="#miao">去找喵星人</a>:(注意:href属性的属 ...