Cow Contest(最短路floyed传递闭包)
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场比赛,位置在前面的是胜利的牛的编号,如果一头牛和剩下的牛都能确定等级关系,说明可以去确定该牛的等级
,求出可以确定等级的牛的个数 解题思路:这是一个利用最短路floyed算法的一个传递闭包问题,如果一个点和其余各点都确定关系了,那么这个点的等级就可以确定了。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m;
int map[200][200];
int floyd()
{
int i,j,k;
for(k=1; k<=n; k++)
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
if(map[i][k]&&map[k][j])
{
map[i][j]=1;///如果任意两个点能够通过第三个点发生关系,那么说明这两个点也是有关系的
}
}
}
int main()
{
int a,b,i,j,count,sum;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(map,0,sizeof(map));
for(i=0; i<m; i++)
{
scanf("%d%d",&a,&b);
map[a][b]=1;///可以确定关系的利用邻接矩阵记录为1
}
floyd();
count=0;
for(i=1; i<=n; i++)
{
sum=0;
for(j=1; j<=n; j++)
{
if(map[i][j]||map[j][i])
{
sum++;
}
}
if(sum==n-1)///如果一个点和其余各点的关系确定,那么这个点就可以确定等级
{
count++;
}
}
printf("%d\n",count);
}
return 0;
}
Cow Contest(最短路floyed传递闭包)的更多相关文章
- 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求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- Bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 传递闭包,bitset
1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 891 Solved: 590 ...
- POJ 3660 Cow Contest ( 最短路松弛思想应用 && Floyd求传递闭包 )
题意 : 给出 N 头奶牛在比赛的结果,问你最多的能根据给出结果确定其名次的奶牛头数.结果给出的形式为 A B 代表在比赛当中 A 战胜了 B 分析 : 对于一头奶牛来说,如果我们能确定其他 N - ...
- (poj 3660) Cow Contest (floyd算法+传递闭包)
题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are par ...
- POJ-3660 Cow Contest( 最短路 )
题目链接:http://poj.org/problem?id=3660 Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, ar ...
- POJ 3660 cow contest (Folyed 求传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...
- Median Weight Bead(最短路—floyed传递闭包)
Description There are N beads which of the same shape and size, but with different weights. N is an ...
- Cow Contest POJ - 3660 floyd传递闭包
#include<iostream> #include<cstring> using namespace std; ,INF=0x3f3f3f3f; int f[N][N]; ...
随机推荐
- MySQL 5.7基于GTID的主从复制
since i've broken down the replication enviornment by "reset master;" yesterday.th ...
- 解决IDEA打印到控制台的中文内容乱码
File-->Settings-->Editor-->File Encodings->将图中内容均设置为UTF-8--->点击+号选中自己的项目->Apply--& ...
- linux线程篇 (二) 线程的基本操作
线程 进程 标识符 pthread_t pid_t 获取ID pthread_self() getpid() 创建 pthread_create() fork 销毁 pthread_exit() ...
- pyhton 下 使用getch(), 输入字符无需回车
原代码来自 https://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin ...
- go学习笔记-标准库
标准库 名称 摘要 archive tar tar包实现了tar格式压缩文件的存取. zip zip包提供了zip档案文件的读写服务. bufio bufio 包实现了带缓存的I/O操作. built ...
- python 的 购物小程序
money = input('请输入您的工资:') shop = [("iphone",5800),("ipod",3000),("book" ...
- SpaceVim 语言模块 dart
原文连接: https://spacevim.org/cn/layers/lang/dart/ 模块简介 功能特性 依赖安装及启用模块 启用模块 语法检查及代码格式化 安装 dart-repl 快捷键 ...
- Tips & Tricks Learned Releasing an Hybrid App Using Steroids.js
http://marcgg.com/blog/2014/04/09/phonegap-steroids-hybrid-native-app-tips/
- 20145207 ms11_050漏洞攻击
实验过程 查看两台主机ip,并ping通 启动msf,进入该漏洞模块,查看漏洞的信息 exploit生成网站地址,开启服务
- Drupal中自定义登录页面
通过覆写template定义新的user_login表单来为自定义登录页面.方法: 1. 本站使用的主题是Rorty.来到\sites\all\themes\rorty,打开template.php ...