博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3360 H-Cow Contest
阅读量:5094 次
发布时间:2019-06-13

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

 

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 54 34 23 21 22 5

Sample Output

2

题解:$floyd$ 算法 如果赢过的人加上败给的人的和是 $N - 1$ 就是可以确定位置的人

代码:

#include 
#include
#include
#include
using namespace std;int N, M;int mp[110][110];void floyd() { for(int k = 1; k <= N; k ++) { for(int i = 1; i <= N; i ++) { if(mp[i][k]) for(int j = 1; j <= N; j ++) { if(mp[k][j] == 1 && mp[i][k] == 1) { mp[i][j] = 1; mp[j][i] = -1; } else if(mp[k][j] == -1 && mp[i][k] == -1) { mp[i][j] = -1; mp[j][i] = 1; } else continue; } } }}int main() { memset(mp, 0, sizeof(mp)); scanf("%d%d", &N, &M); for(int i = 1; i <= M; i ++) { int a, b; scanf("%d%d", &a, &b); mp[a][b] = 1; mp[b][a] = -1; } floyd(); int ans = 0; for(int i = 1; i <= N; i ++) { int sum = 0; for(int j = 1; j <= N; j ++) if(mp[i][j]) sum ++; if(sum == N - 1) ans ++; } printf("%d\n", ans); return 0;}

  

转载于:https://www.cnblogs.com/zlrrrr/p/9895713.html

你可能感兴趣的文章
cassandra vs mongo (1)存储引擎
查看>>
Visual Studio基于CMake配置opencv1.0.0、opencv2.2
查看>>
Vue音乐项目笔记(三)
查看>>
遍历Map对象
查看>>
计算剪贴板里仿制的代码行数
查看>>
MySQL索引背后的数据结构及算法原理
查看>>
#Leetcode# 209. Minimum Size Subarray Sum
查看>>
C#语言-04.OOP基础
查看>>
1)session总结
查看>>
PHP深浅拷贝
查看>>
SDN第四次作业
查看>>
ActiveMQ(4) ActiveMQ JDBC 持久化 Mysql 数据库
查看>>
DM8168 DVRRDK软件框架研究
查看>>
django迁移数据库错误
查看>>
epoll学习01
查看>>
yii 跳转页面
查看>>
闭包问题
查看>>
C#一个FTP操作封装类FTPHelper
查看>>
Linux运维基础入门(二):网络基础知识梳理02
查看>>
你所不知道的 CSS 阴影技巧与细节
查看>>