博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3660——Cow Contest(判断绝对顺序)
阅读量:2344 次
发布时间:2019-05-10

本文共 1895 字,大约阅读时间需要 6 分钟。

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就能够确定绝对顺序

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 5005#define mod 1000000007using namespace std;int n,m;int map[MAXN][MAXN];void Floyd(){ int i,j,k; for(k=1; k<=n; k++) for(i=1; i<=n; i++) for(j=1; j<=n; j++) if(map[i][j]>map[i][k]+map[k][j]) map[i][j]=map[i][k]+map[k][j];}int main(){ scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) map[i][j]=(i==j?0:INF); //注意自身和自身距离为0。 int a,b; while(m--) { scanf("%d%d",&a,&b); map[a][b]=1; } Floyd(); int ans=0; for(int i=1;i<=n;++i) { int tmp=0; for(int j=1;j<=n;++j) { if(i!=j) { if(map[i][j]

转载地址:http://nscvb.baihongyu.com/

你可能感兴趣的文章
搜索引擎来路关键词的挖掘:百度统计的高级分析报告导出获取来源关键词
查看>>
C/C++题目--拷贝构造函数概念
查看>>
C/C++题目--深复制与浅复制
查看>>
数据结构教程--李春葆版(总结)之线性表-顺序存储结构练习题
查看>>
C++虚函数底层机制
查看>>
linux gdb的详细用法 运行与断点
查看>>
删除vector中重复元素
查看>>
和为s的连续正数序列
查看>>
什么是Redis?什么是nosql?NoSQL数据库的四大分类
查看>>
为什么说Redis是单线程的以及Redis为什么这么快!
查看>>
redis的过期健删除策略以及内存淘汰机制
查看>>
map 如何使用结构体作为自定义键值
查看>>
Mysql几种索引类型的区别及适用情况
查看>>
Redis持久化的两种方式
查看>>
判断一个数组,是否可以分成两个数组之和相等的数组
查看>>
背包问题
查看>>
结构体变量之间的比较和赋值原理
查看>>
C++ const修饰函数、函数参数、函数返回值
查看>>
将单链表的每k个节点之间逆序
查看>>
删除链表中重复的节点——重复节点不保留
查看>>