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时可以知道排名,即为 ...
随机推荐
- Cloudstack 安装记录
一.条件要求 1.硬件支持虚拟化,并在BIOS中开启(Inter-VT设为 Enable). 2.Centos 6.5 x86_64 3.环境中的每台主机均为静态IP地址. 4.cloudstack安 ...
- OD 实验(九) - 对一个程序的破解
程序: 运行程序 点击 About 这是要注册的 点击 Register 输入邮箱和注册码,点击 Register Now 逆向: 用 OD 打开程序 右键 -> 查找 -> 所有参考文本 ...
- Ubuntu13.10:密码忘记了怎么办?
重启ubuntu系统,开机时长按shift按键进入GRUB菜单,选择第二个高级模式. 新版的UBUNTU系统居然启用了GRUNB2.0的内核!虽然传说相当的牛X,但是用起来感觉就是非常看不清楚字体,要 ...
- hibernate操作数据库时报错解决方式
java.sql.SQLException: Parameter index out of range (28 > number of parameters, which is 27). 这个说 ...
- Tkinter Menu(菜单)
Tkinter Menu: 这个小工具的目标是,让我们来创建我们的应用程序,可以通过使用各种菜单.核心功能,提供的方式来创建三个菜单类型:弹出式,顶层,和下拉 这个小工具的目标是,让我们来创建 ...
- Nginx 安装与使用
作者:吴秦出处:http://www.cnblogs.com/skynet/ 前言 nginx Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一 ...
- 深入理解Java线程池
我们使用线程的时候就去创建一个线程,这样实现起来非常简便,但是就会有一个问题: 如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统的效率,因为频繁 ...
- Cookie&Session会话跟踪技术
今日内容学习目标 可以响应给浏览器Cookie信息[response.addCookie()] 可以接受浏览器Cookie信息[request.getCookies()] [创建cookie,设置pa ...
- 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 12—Support Vector Machines 支持向量机
Lecture 12 支持向量机 Support Vector Machines 12.1 优化目标 Optimization Objective 支持向量机(Support Vector Machi ...
- python3企业微信群组报警
公司提出一个需求需要做一个企业微信的一个消息推送,需要将消息发送到聊天群里详细信息如下. 如何创建应用请阅读我的上篇文章:https://www.cnblogs.com/wangyajunblog/p ...