POJ 3660 cow contest (Folyed 求传递闭包)
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个关系,
每个关系两头牛的编号:代表前者打败后者;
然后让你求可以确定名次的有多少头牛;
我们可以利用Folyed 来找找出每头牛可以和多少头牛建立关系,当且一头牛可以和剩下的N-1头牛都可以建立关系时,它的名次就可以确定了;求和即可达到答案;
参考代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define PI acos(-1)
#define EPS 1e-8
const int INF=0x3f3f3f3f;
const LL inf=0x3f3f3f3f3f3f3f3fLL; const int maxn=;
int N,M,A,B,dp[maxn][maxn];
int main()
{
scanf("%d%d",&N,&M);
memset(dp,,sizeof dp);
for(int i=;i<=M;i++) scanf("%d%d",&A,&B),dp[A][B]=; for(int k=;k<=N;k++)
for(int i=;i<=N;i++)
for(int j=;j<=N;j++) if(dp[i][k]&&dp[k][j]) dp[i][j]=; int ans=,j;
for(int i=;i<=N;i++)
{
for(j=;j<=N;j++)
{
if(i==j) continue;
if(!dp[i][j]&&!dp[j][i]) break;
}
if(j>N) ans++;
}
printf("%d\n",ans);
return ;
}
POJ 3660 cow contest (Folyed 求传递闭包)的更多相关文章
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow Contest【Floyd 传递闭包】
传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...
- POJ 3660 Cow Contest(求图的传递性)
题意: 给定n头牛, 然后有m个比较, 求出有多少头牛能确定自己的排名. 分析: 假设有一头牛a, 有ki头牛强于自己, kj头牛弱于自己, ki + kj == n-1时, 那么这头牛的排名就确定了 ...
- poj 3660 Cow Contest (bitset+floyd传递闭包)
传送门 解题思路 考试题,想到传递闭包了,写了个O(n^3)的,T了7个点...后来看题解是tm的bitset优化???以前好像没听过诶(我太菜了),其实也不难,时间复杂度O(n^3/32) #inc ...
- 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 ...
- 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: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- POJ 3660 Cow Contest ( 最短路松弛思想应用 && Floyd求传递闭包 )
题意 : 给出 N 头奶牛在比赛的结果,问你最多的能根据给出结果确定其名次的奶牛头数.结果给出的形式为 A B 代表在比赛当中 A 战胜了 B 分析 : 对于一头奶牛来说,如果我们能确定其他 N - ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
随机推荐
- Java传参-基本数据类型和引用数据类型作为参数的区别(值传递)
java中的方法可以传递参数,参数的传递方法就是值传递. 参数有形参和实参,定义方法时写的参数叫形参,真正调用方法时,传递的参数叫实参. 调用方法时,会把实参传递给形参,方法内部其实是在使用形参. 所 ...
- 关于GDAL读写Shp乱码的问题总结
目录 1. 正文 1.1. shp文件本身的编码的问题 1.2. 设置读取的编码方式 1.2.1. GDAL设置 1.2.2. 解码方式 1.2.3. 其他 2. 参考 1. 正文 最近在使用GDAL ...
- 设置Ubuntu下vim缩进为4个空格
输入命令编辑vim配置文件: sudo vim /etc/vim/vimrc 文件中添加如下: 保存退出即可
- 一.web服务机制
web服务机制 我们先跟着**(Web服务器工作原理总体描述01)这张图,将一次Web服务的工作流程过一遍,我们假设以浏览器作为客户端(1) 用户做出了一个操作,可以是填写网址敲回车,可以是点击链接, ...
- LeetCode18. 四数之和
LeetCode18. 四数之和 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值 ...
- android逆向总结
首先项目里的java文件,以及项目引用到的第三方jar或aar包里面的class,统统都编译成classes.dex放在apk包的根目录,项目的资源目录和AndroidManifest.xml被处理生 ...
- [ch02-01] 线性反向传播
系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 2.1 线性反向传播 2.1.1 正向计算的实例 假设我 ...
- PostGIS 用Navicat工具添加自增
1.新建查询,新增序列(从66开始,每次自增1): CREATE SEQUENCE seq_area INCREMENT 1 MINVALUE 66 MAXVALUE 999999999 START ...
- C#变量---xdd
cshape(c#)学习笔记 1. string str1=Console.ReadLine();//键盘输入的默认为字符串 2. Console.WriteLine('你的成绩是'+a+'分'); ...
- altium designer 20.0.8
altium designer 20.0.8 download : http://dl3.downloadly.ir/Files/Software/Altium_Designer_20.0.8_Bet ...