Cow Contest

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16941   Accepted: 9447

题目链接:http://poj.org/problem?id=3660

Description:

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 ≤ NA ≠ 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场比赛,然后给出m场比赛的胜负关系,问有多少只牛能确定它们自己的名次。

题解:

这个题有点像拓扑排序,但是只用拓扑序并不能保证结果的正确性。

其实解这个题我们只需要发现这样一个关系就好了,若一只牛的名次能够被确定,那么它赢它的牛和它赢的牛个数之和为n-1。

利用这个关系,我们floyd传递闭包预处理一下,然后判断一下数量关系就好了。

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int N = , M = ;
int n,m;
int mp[N][N];
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
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++){
mp[i][j]=(mp[i][j]|(mp[i][k]&mp[k][j]));
}
}
}
int ans=;
for(int i=;i<=n;i++){
int win=,lose=;
for(int j=;j<=n;j++){
if(mp[i][j]) win++;
if(mp[j][i]) lose++;
}
if(win+lose==n-) ans++;
}
cout<<ans;
return ;
}

POJ3660:Cow Contest(Floyd传递闭包)的更多相关文章

  1. POJ3660——Cow Contest(Floyd+传递闭包)

    Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...

  2. POJ3660 Cow Contest —— Floyd 传递闭包

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  3. POJ-3660 Cow Contest Floyd传递闭包的应用

    题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...

  4. POJ3660 Cow Contest floyd传递闭包

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  5. POJ-3660.Cow Contest(有向图的传递闭包)

      Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17797   Accepted: 9893 De ...

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

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

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

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

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

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

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

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

随机推荐

  1. Python变量和循环

    1.Python变量 比C语言,Java语言更加简洁,不需要加int等等类型定义,直接变量名 = 值,Python里甚至不需要分号.有些特定的不能当做变量名,变量只能由字母.数字和下划线组成,下划线可 ...

  2. DSP28335的XINTF操作SRAM实验

    1. 本次使用三兄弟的XDS28335开发板,研究一下XINTF操作SRAM的代码.哈弗结构,奇怪,DSP28335是哈弗结构,那么数据和程序空间应该独立的,为啥书上说采用统一的寻址方式?估计只是读写 ...

  3. 转MySQL详解--索引

    写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...

  4. 深入理解计算机系统(1)--hello world程序的生命周期

    第一篇笔记的主题是讨论Hello World程序的生命周期,程序是最简单的hello world程序,使用高级C语言编写. 先介绍整个生命周期中涉及到的几个部分以及相应的概念,然后总结整个生命周期,最 ...

  5. vue3.0 部署的基础流程

    1.创建vue.config.js 主要是负责做设置的 2.修改vue.config.js 参考官方说明: 注意:对于本地开发的同学要注意,你之前在处理网络请求时是在8080端口下请求,现在如果换成了 ...

  6. QC的使用学习(二)

    今日学习清单: 1.Quality  Center中左上角选项中(QC 10.0中文版)工具菜单下的自定义中的几个内容,有:用户属性.组.项目用户.模块访问.需求类型.项目列表等.用户属性打开后是对当 ...

  7. C++学习---- static关键字用法总结

    static: 作用:存储在静态数据区的变量会在程序刚开始运行时就完成初始化,也是唯一的一次初始化.共有两种变量存储在静态存储区:全局变量和static变量. 1.隐藏:(静态全局变量和静态函数)   ...

  8. mysql分布式技术

    所有的分布式技术 dobble zokkiper ngix

  9. BZOJ 1565 NOI2009 植物大战僵尸 topo+最小割(最大权闭合子图)

    题目链接:https://www.luogu.org/problemnew/show/P2805(bzoj那个实在是有点小小的辣眼睛...我就把洛谷的丢出来吧...) 题意概述:给出一张有向图,这张有 ...

  10. 辨析ADK&JVM&JRE&JDK&ADT

    一.SDK 英文全称:Software Development Kit 中文译名:软件开发工具包 详解: 由第三方服务商提供的实现软件产品某项功能的工具包. 为了扩展软件功能或其它方面而设计出来给开发 ...