最短路(Floyd_Warshall) POJ 2240 Arbitrage
/*
最短路:Floyd模板题
只要把+改为*就ok了,热闹后判断d[i][i]是否大于1
文件输入的ONLINE_JUDGE少写了个_,WA了N遍:)
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
double d[][]; void Floyd_Warshall(int n)
{
for (int k=; k<=n; ++k)
{
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
if (d[i][j] < d[i][k] * d[k][j])
{
d[i][j] = d[i][k] * d[k][j];
}
}
}
} for (int i=; i<=n; ++i)
{
if (d[i][i] > )
{
puts ("Yes"); return ;
}
} puts ("No"); return ;
} int main(void) //POJ 2240 Arbitrage
{
#ifndef ONLINE_JUDGE
freopen ("F.in", "r", stdin);
#endif int n, num; int cas = ;
while (cin >> n && n)
{
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
if (i == j) d[i][j] = ;
else d[i][j] = ;
}
} map<string, int> m;
string s, s1, s2;
for (int i=; i<=n; ++i)
{
cin >> s;
m[s] = i;
} cin >> num;
for (int i=; i<=num; ++i)
{
double w;
cin >> s1 >> w >> s2;
d[m[s1]][m[s2]] = w;
} cout << "Case " << ++cas << ": ";
Floyd_Warshall (n);
} return ;
}
最短路(Floyd_Warshall) POJ 2240 Arbitrage的更多相关文章
- poj 2240 Arbitrage 题解
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21300 Accepted: 9079 Descri ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- poj 2240 Arbitrage (Floyd)
链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...
- poj 2240 Arbitrage (最短路 bellman_ford)
题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...
- POJ 2240 Arbitrage(最短路 套汇)
题意 给你n种币种之间的汇率关系 推断是否能形成套汇现象 即某币种多次换为其他币种再换回来结果比原来多 基础的最短路 仅仅是加号换为了乘号 #include<cstdio> #in ...
- POJ 2240 - Arbitrage - [bellman-ford求最短路]
Time Limit: 1000MS Memory Limit: 65536K Description Arbitrage is the use of discrepancies in currenc ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2240 Arbitrage(floyd)
http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...
随机推荐
- Robot Motion(imitate)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11065 Accepted: 5378 Des ...
- js矩阵菜单或3D立体预览图片效果
js矩阵菜单或3D立体预览图片效果 下载地址: http://files.cnblogs.com/elves/js%E7%9F%A9%E9%98%B5%E8%8F%9C%E5%8D%95%E6%88% ...
- google推出的SwipeRefreshLayout下拉刷新用法
使用如下: 1.先下载android-support-v4.jar最新版本,之前的版本是没有SwipeRefreshLayout下拉刷新控件的,如果已经更新,此步骤可省略. 2.在xml文件中引用an ...
- BNU 2418 Ultra-QuickSort (线段树求逆序对)
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=2418 解题报告:就是给你n个数,然后让你求这个数列的逆序对是多少?题目中n的范围是n & ...
- 初识suse-Linux相关!
Linux这种系统很奇怪,差不多每种不同的版本,它所使用的安装等一些重要命令皆有所变化.假若,你要熟练掌握一种OS,那么如果安装软件/应用,那是入门的第一步. 安装命令中: RedHat.CentOS ...
- linux 如何清理僵尸进程
今天在维护服务器的时候,发现有5个nova-novncproxy的僵尸进程. 26327 ? S 0:05 \_ /usr/bin/python /usr/bin/nova- ...
- Linux 守护进程和超级守护进程(xinetd)
一 .Linux守护进程 Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务的程序是由运行在后台的守护进程来执行的 ...
- bash read命令用法
read -p "Enter your student ID: " USERNAMEread -s -p "Enter your password: " PAS ...
- 《ASP.NET MVC4 WEB编程》学习笔记------HtmlHelper
本文转载自powerzhang,如果给您带来不便请联系博主. 在实际的程序中,除了在View中展示数据外,还需要在View与后台的数据进行交互,在View中我就需要用的表单相关的元素: 在MVC3框架 ...
- Java for LeetCode 063 Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...