POJ 3360 H-Cow Contest
http://poj.org/problem?id=3660
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
题解:$floyd$ 算法 如果赢过的人加上败给的人的和是 $N - 1$ 就是可以确定位置的人
代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
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
POJ 3360 H-Cow Contest相关推荐
- H - Cow Contest POJ - 3660(Floyd 传递闭包)
H - Cow Contest POJ - 3660 题意: 有 n 头牛比赛,边 1 -> 2 代表 1 能赢 2 ,给你 m 条边,问能确定出多少头牛的名次? 思路: 如果 1->2 ...
- H - Cow Contest(floyd的传递闭包性)
题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1-N, are participating in a programming contest. As ...
- POJ 3660 Cow Contest [Floyd]
POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- [传递闭包]POJ#3660 Cow Contest
题面 传送门 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24342 Accepted: 13539 ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- Cow Contest【最短路-floyd】
Cow Contest POJ - 3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...
- poj3660 Cow Contest
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8967 Accepted: 5032 Descr ...
最新文章
- InetAddress类和InetSocketAddress的使用
- C语言实现修改文本文件中的特定行
- [转]Oracle 执行计划(Explain Plan) 说明
- 制造内核崩溃并使用crash分析内核崩溃产生的vmcore文件
- 更改hadoop native库文件后datanode故障
- Spring简介-Spring发展历程
- 单片机中存储器扩展位地址线怎么算_51单片机存储器小结
- 【李宏毅2020 ML/DL】P52 Network Compression - Network Pruning
- linux查询文件存储格式,蜗牛哥:Linux中查看文件内容,5种常用查看方式
- 单元测试和sit测试和uat测试
- Linux面试题,经典Linux面试题,常见Linux面试题带答案
- 聚类分析与SPSS实现——《社会统计分析方法》
- Ubuntu 20.04 修改IP地址
- 合成孔径雷达成像——算法与实现图【2.3】仿真——rect函数、sinc函数的傅里叶变换matlab仿真
- 7分钟学会HTML网页制作
- java 读取本地配置文件 Properties
- 【LAB4-Cisco】OSPF邻居建立过程与LSDB分析
- DPU — 完全可编程网络
- ValueError: attempt to get argmax of an empty sequence
- org.gradle.api.resources.ResourceException: Could not get resource ‘https://xxx.xxx/xxx.pom