floyd
Posted mekakucityactor
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了floyd相关的知识,希望对你有一定的参考价值。
floyd可用于解决某些可传递性问题(如1<2,2<3,则1<3 )
POJ2240:http://poj.org/problem?id=2240
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 28138 | Accepted: 11789 |
Description
Your job is to write a program that takes a list of currency exchange rates as input and then determines whether arbitrage is possible or not.
Input
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.
Output
Sample Input
3 USDollar BritishPound FrenchFranc 3 USDollar 0.5 BritishPound BritishPound 10.0 FrenchFranc FrenchFranc 0.21 USDollar 3 USDollar BritishPound FrenchFranc 6 USDollar 0.5 BritishPound USDollar 4.9 FrenchFranc BritishPound 10.0 FrenchFranc BritishPound 1.99 USDollar FrenchFranc 0.09 BritishPound FrenchFranc 0.19 USDollar 0
Sample Output
Case 1: Yes Case 2: No
题意:给出一堆货币汇率,判断是否可以通过一些交换赚取差价。
题解:货币的交换过程属于乘法运算,具有传递性,可以通过floyd得到所有交换情景,判断dist[i][i]与1的大小关系即可。
POJ3660:http://poj.org/problem?id=3660
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16083 | Accepted: 8997 |
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
题意:给出一些数据的大小关系,判断由多少个数据可以被确定具体排名
题解:易知如果知道一个数据与另外n-1个数的关系,就可以确定它的排名,由于大小关系具有可传递性,所以可以使用floyd得到所有数之间的关系统计能与另外n-1个数确定的个数即可
以上是关于floyd的主要内容,如果未能解决你的问题,请参考以下文章