题意:给出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传递闭包)题解的更多相关文章

  1. poj 3660 Cow Contest(传递闭包 Floyd)

    链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...

  2. poj 3660 Cow Contest (传递闭包)

    /* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...

  3. POJ 3660 Cow Contest(传递闭包floyed算法)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  4. ACM: POJ 3660 Cow Contest - Floyd算法

    链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Descri ...

  5. POJ 3660 Cow Contest (Floyd)

    题目链接:http://poj.org/problem?id=3660 题意是给你n头牛,给你m条关系,每条关系是a牛比b牛厉害,问可以确定多少头牛的排名. 要是a比b厉害,a到b上就建一条有向边.. ...

  6. POJ - 3660 Cow Contest(传递闭包)

    题意: n个点,m条边. 若A 到 B的边存在,则证明 A 的排名一定在 B 前. 最后求所有点中,排名可以确定的点的个数. n <= 100, m <= 4500 刚开始还在想是不是拓扑 ...

  7. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  8. 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 ...

  9. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

随机推荐

  1. 【WebService】Stax的基本操作基于游标

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <book ...

  2. LeetCode——Add and Search Word - Data structure design

    Description: Design a data structure that supports the following two operations: void addWord(word) ...

  3. 知道WCF的地址用工厂通道方式快速调用WCF

    知道WCF的地址用工厂通道方式快速调用WCF  1 using System;  2 using System.ServiceModel;  3 using System.ServiceModel.D ...

  4. 【BZOJ4545】DQS的trie 后缀自动机+LCT

    [BZOJ4545]DQS的trie Description DQS的自家阳台上种着一棵颗粒饱满.颜色纯正的trie. DQS的trie非常的奇特,它初始有n0个节点,n0-1条边,每条边上有一个字符 ...

  5. postgresql----时间类型

    postgresql支持的时间类型如下图所示: 日期 date: 建议日期的输入格式为1997-01-01,虽然也支持19970101,1/1/1997,Jan-1-1997等多种格式. 时间戳 ti ...

  6. SpringCloud--Ribbon负载均衡

    Ribbon实现客户端负载均衡 负载均衡:是对系统的高可用.网络压力的缓解和处理能力扩容的重要手段之一. 硬件负载均衡:主要通过在服务器节点之间安装专门用于负载均衡的设备: 软件负载均衡:通过在服务器 ...

  7. Servlet------>request和response控制编码乱码问题

    我在request篇和response都有提到,觉得会忘记,所以从新整理一下 request细节四----->通过request控制编码问题 第一种方式是通过设置------>reques ...

  8. oracle(十一) scn

    SCN(System Chang Number)作为oracle中的一个重要机制,在数据恢复.Data Guard.Streams复制.RAC节点间的同步等各个功能中起着重要作用. 理解SCN的运作机 ...

  9. JAVA 线程状态转换

    Thread类中State枚举定义: public enum State { /** * Thread state for a thread which has not yet started. */ ...

  10. Flume+Morphlines实现数据的实时ETL

    转载:http://mp.weixin.qq.com/s/xCSdkQo1XMQwU91lch29Uw Apache Flume介绍: Apache Flume是一个Apache的开源项目,是一个分布 ...