POJ 3660 Cow ContestCow(Floyd传递闭包)题解
题意:给出m个关系,问你能确定机头牛的排名
思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名。
代码:
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<vector>
#include<queue>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = +;
const int INF = 0x3f3f3f3f;
int mp[maxn][maxn],can[maxn];
int main(){
int n,m;
memset(mp,,sizeof(mp));
memset(can,,sizeof(can));
scanf("%d%d",&n,&m);
while(m--){
int u,v;
scanf("%d%d",&u,&v);
mp[u][v] = ;
}
for(int k = ;k <= n;k++){
for(int i = ;i <= n;i++){
for(int j = ;j <= n;j++){
if(mp[i][k] && mp[k][j]){
mp[i][j] = ;
}
}
}
}
int ans = ;
for(int i = ;i <= n;i++){
for(int j = ;j <= n;j++){
if(mp[i][j] && i != j){
can[i]++;
can[j]++;
}
}
}
for(int i = ;i <= n;i++){
if(can[i] == n - ) ans++;
}
printf("%d\n",ans);
return ;
}
POJ 3660 Cow ContestCow(Floyd传递闭包)题解的更多相关文章
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- poj 3660 Cow Contest (传递闭包)
/* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- POJ 3660 Cow Contest (Floyd)
题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...
- POJ - 3660 Cow Contest(传递闭包)
题意: n个点,m条边. 若A 到 B的边存在,则证明 A 的排名一定在 B 前. 最后求所有点中,排名可以确定的点的个数. n <= 100, m <= 4500 刚开始还在想是不是拓扑 ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- 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:65536KB 64bit IO Format:%I64d & %I64u Submit ...
随机推荐
- 小程序 - API 踩坑记录(更新中...)
API 小程序API结构导览图: 声明: 请尊重博客园原创精神,转载或使用图片请注明: 博主:xing.org1^ 出处:http://www.cnblogs.com/padding1015/
- LeetCode——Best Time to Buy and Sell Stock IV
Description: Say you have an array for which the ith element is the price of a given stock on day i. ...
- LeetCode——Integer to Roman
Description: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the r ...
- mysql load data导入脚本
# !/bin/bash ############中文说明###################### #本程序的一些提示需要中文支持,如系统没有安装中文包,请先安装:yum -y groupinst ...
- 写一个体验良好的git commit
一直在使用git也看过格式各样commit log , review 代码时最刺激的是看到这类 "." 应付差事,还有 "fix bug","fix& ...
- T-SQL数据库备份
/*1.--得到数据库的文件目录 @dbname 指定要取得目录的数据库名 如果指定的数据不存在,返回安装SQL时设置的默认数据目录 如果指定NULL,则返回默认的SQL备份目录名 */ /*--调用 ...
- Code Forces 652C Foe Pairs
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- AWR之-enq TX - row lock contention的性能故障-转
1 对这一个小时进行AWR的收集和分析,首先,从报告头中看到DB Time达到近500分钟,(DB Time)/Elapsed=8,这个比值偏高: Snap Id Snap Time Sessio ...
- Go Configure Support hot reloading.
Go Configure – Josh Betz https://josh.blog/2017/04/go-configure Go Configure APRIL 27, 2017 # DEVELO ...
- proxy,https,git,tortoise git,ssh-agent,ssh-add,ssh,ssl,rsync
看具体应用了,一般的文件复制使用scp,增量同步使用rsync.rsync的认证可以使用ssh,还可以是rsync自己的密码文件. ssh-keygen -l 察看 fineprint 5.1 通过p ...