Problem 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 ≤ 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

题意:给出两头牛之间的竞争的结果(a,b),a赢b,确定有多少头牛能够确定其排名。

思路:对于一头牛,如果想确定其排名,那么就是在明确的知道比它高的有几只、低的有几只,且前后加起来正好是 n-1 只时,可以确定他的排名。

所给的关系可以看做是一条路,只需判断任意两点是否连通,再确定一个点的入度和出度相加是否等于 n-1,因此可以判断这个点是否为所求的点。

因此本题实质是判断一个有向无权图的任意两点是否导通,即求图的传递闭包,使用 Floyd 即可。

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 101
#define MOD 2520
#define E 1e-12
using namespace std;
int g[N][N];
int degree[N][N];
int main()
{int n,m;while(scanf("%d%d",&n,&m)!=EOF){memset(g,0,sizeof(g));for(int i=0;i<m;i++){int x,y;scanf("%d%d",&x,&y);g[x][y]=1;}for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(g[i][k]&&g[k][j])g[i][j]=1;memset(degree,0,sizeof(degree));for(int i=1;i<=n;i++)//计算点的度数{for(int j=1;j<=n;j++)if(i!=j){if(mp[i][j]){degree[i]++;degree[j]++;}}}int cnt=0;for(int i=1;i<=n;i++)if(degree[i]==n-1)cnt++;printf("%d\n",cnt);}return 0;
}

Cow Contest(POJ-3660 )相关推荐

  1. Silver Cow Party (POJ - 3268 )

    Silver Cow Party (POJ - 3268 ) 这道题是我做的最短路专题里的一道题,但我还没做这个,结果比赛就出了,真是.......... 题目: One cow from each ...

  2. 【二分】Best Cow Fences(poj 2018)

    Best Cow Fences poj 2018 题目大意: 给出一个正整数数列,要你求平均数最大,长度不小于M的字串,结果乘1000取整 输入样例 10 6 6 4 2 10 3 8 5 9 4 1 ...

  3. Bailian2734 十进制到八进制【入门】(POJ NOI0113-45)

    问题链接:POJ NOI0113-45十进制到八进制 2734:十进制到八进制 总时间限制: 1000ms 内存限制: 65536kB 描述 把一个十进制正整数转化成八进制. 输入 一行,仅含一个十进 ...

  4. Bailian2676 整数的个数【入门】(POJ NOI0105-11)

    问题链接:POJ NOI0105-11 整数的个数 2676:整数的个数 总时间限制: 1000ms 内存限制: 65536kB 描述 给定k(1 < k < 100)个正整数,其中每个数 ...

  5. Bailian4029 数字反转【进制】(POJ NOI0105-29)

    问题链接:POJ NOI0105-29 数字反转 4029:数字反转 总时间限制: 1000ms 内存限制: 65535kB 描述 给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数 ...

  6. Bailian2735 八进制到十进制【入门】(POJ NOI0113-46)

    问题链接:POJ NOI0113-46 八进制到十进制 2735:八进制到十进制 总时间限制: 1000ms 内存限制: 65536kB 描述 把一个八进制正整数转化成十进制. 输入 一行,仅含一个八 ...

  7. (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题)

    layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题) author: " ...

  8. 牛客假日团队赛8:K.Cow Contest(最短路(floyd)变形)

    链接:https://ac.nowcoder.com/acm/contest/1069/K 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6553 ...

  9. 吴昊品游戏核心算法 Round 7 —— 熄灯游戏AI(有人性的Brute Force)(POJ 2811)

    暴力分为两种,一种属于毫无人性的暴力,一种属于有人性 的暴力.前面一种就不说了,对于后面一种情况,我们可以只对其中的部分问题进行枚举,而通过这些子问题而推导到整个的问题中.我称之为有人性的Brute ...

  10. 2015 ACM Arabella Collegiate Programming Contest(F题)

    F. Palindrome [ Color: Pink ] A string is palindrome if it can be read the same way in either direct ...

最新文章

  1. 支付宝个人账单出来了,这里有最全的查看攻略!
  2. SAGAN生成更为精细的人脸图像(tensorflow实现)
  3. 最近参加一个公司的入职培训
  4. 计算机会比人的神经系统更发达吗?
  5. APP性能测试之jmeter
  6. 【Python通过分贝监测Windows系统是否有声音播放】
  7. mysql数据库备份方法有几种_MySQL数据库备份的几种方式
  8. 百度360争推1TB永久网盘
  9. windows Server2016 关闭135端口
  10. win10计算机还原点如何创建,win10系统创建还原点及系统还原的操作方法
  11. Http头:only-if-cached
  12. Hibernate框架学习1
  13. Android蓝牙开发系列文章-蓝牙设备类型知多少?
  14. IC验证必备的数字电路基础知识(一):数字逻辑基础
  15. 学习:数学----欧拉定理与扩展欧拉定理
  16. Silverlight开发实践--My Silverlight Clock (源)
  17. awk将文件某个列按照逗号分隔
  18. 浪潮积极参与OCP开放计算生态建设 联手Intel共同创新
  19. Excel如何批量在数字后面添加单位
  20. java 运动控制,S7-1500T连接S120实现运动控制(Startdrive)

热门文章

  1. 「最有用」的特殊大数据:一文看懂文本信息系统的概念框架及功能
  2. 在GPU上运行,性能是NumPy的11倍,这个Python库你值得拥有
  3. 极度烧脑+惊人发现:4个颠覆你世界观的量子理论实验
  4. 我30岁了。现在开始编程,会不会太晚?
  5. 使用libcurl以Post方式向HTTP服务器提交数据
  6. 灵魂拷问,SQL 查询语句先执行 SELECT吗?
  7. SQL 查找是否存在,别再 count 了,很耗费时间的!
  8. 阿里如何面试MySQL优化CPU消耗
  9. SpringCloud微服务:阿里开源组件Nacos,服务和配置管理
  10. 记录hiveonspark:Execution Error, return code 30041 from org.apache.hadoop.hive.ql.exec.spark.SparkTask