POJ 3660 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.
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的延伸
用floyd根据三头牛之间a-b,b-c的胜负关系来判断a-c的胜负关系,然后显然除了和自己以外,如果和其他奶牛的关系已经确定了,他的排名也就确定了
然后就写出来了 代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; int map[][],n,m; int main()
{
memset(map,-,sizeof(map));
scanf("%d%d",&n,&m);
int xx,yy;
for(int i=;i<=m;i++)
{
scanf("%d%d",&xx,&yy);
map[xx][yy]=;
map[yy][xx]=;
}
for(int i=;i<=n;i++)
{
map[i][i]=;
}
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]=;
}
if(!map[i][k]&&!map[k][j])
{
map[i][j]=;
}
}
}
}
int ans=;
for(int i=;i<=n;i++)
{
int flag=;
for(int j=;j<=n;j++)
{
if(map[i][j]==-)
{
flag=;
}
}
ans+=flag;
}
printf("%d\n",ans);
}
POJ 3660 Cow Contest(传递闭包)的更多相关文章
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
- POJ 3660 Cow Contest. (传递闭包)【Floyd】
<题目链接> 题目大意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 解题分析: 首先,做这道题要明确,什么叫确定牛的排名.假设 ...
- 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
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
随机推荐
- Flask之视图(二)
2.2 扩展 上下文:相当于一个容器,保存了Flask程序运行过程中的一些信息. Flask中有两种上下文,请求上下文和应用上下文. 请求上下文(request context) request和se ...
- win8下ctrl+alt+down失效问题
最近换win8系统后用myeclipse发现这个用得最多快捷键居然不能用了. 百度后的确是显卡的快捷键冲突,但禁用显卡快捷键后仍然无效,把eclipse换成其他的不能忍. 所以把显卡快捷键换了就可以了 ...
- jstack来分析linux服务器上Java应用服务性能异常
使用jdk自带的jstack来分析linux服务器上应用服务性能异常: 1.top查找出哪个进程消耗的系统资源情况 [op1@jira ~]$ top top - 19:23:43 up 22 day ...
- GPRS 通信
最近使用SIM900A GSM/GPRS模块,做一些简单物联网信息投递. 1.选取何种流量卡 一般来讲,需要带身份证去运营商办理新的电话卡.对于小流量用户,实际上就是办一个最低月租即可,因为套餐会赠送 ...
- TBluetoothLEDevice.UpdateOnReconnect
System.Bluetooth.TBluetoothLEDevice.UpdateOnReconnect Description Indicates whether the manager auto ...
- Delphi IOS class_addMethod
class_addMethod 学习FMX.Platform.iOS.pas文件的处理办法 d:\program files (x86)\embarcadero\studio\17.0\source\ ...
- 我的Linux之路——windows10用WMware安装CentOS6.9 虚拟机详细步骤
出自:http://blog.51cto.com/13438667/2059926 一.安装环境 windows10操作系统物理机VMware Workstation 软件(可以在网上下载)CentO ...
- C++Primer笔记-----day02
====================================================================day02=========================== ...
- Sersync + Rsync 代码分发
简介: Sersync 是基于 inotify 来编写的 Linux 系统文件监控工具,当监控到文件发生变化时,调用 rsync 同步文件. 类似的功能,以前有用 rsync + inotify 实现 ...
- springboot 的定时任务使用
定时任务在Spring Boot中的集成 在启动类中加入开启定时任务的注解: 在SpringBoot中使用定时任务相当的简单.首先,我们在启动类中加入@EnableScheduling来开启定时任务. ...