poj2240 floyd
//Accepted 732 KB 782 ms
//floyd应用
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
;
double a[imax_n][imax_n];
map<string ,int > mp;
int n;
double max(double a,double b)
{
) return b;
return a;
}
void floyd()
{
;k<=n;k++)
;i<=n;i++)
;j<=n;j++)
&& a[k][j]>1e-)
a[i][j]=max(a[i][j],a[i][k]*a[k][j]);
/*
for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)
{
printf("%.3lf ",a[i][j]);
}
printf("\n");
}
*/
}
int main()
{
;
string s;
string s1,s2;
double rate;
while (scanf("%d",&n),n)
{
mp.clear();
;i<=n;i++)
{
cin>>s;
mp[s]=i;
}
int m;
scanf("%d",&m);
;i<=n;i++)
;j<=n;j++)
{
;
;
}
;i<=m;i++)
{
cin>>s1>>rate>>s2;
//cout<<mp[s1]<<" "<<mp[s2]<<endl;
a[mp[s1]][mp[s2]]=rate;
}
floyd();
;
;i<=n;i++)
>1e-) flag=;
printf("Case %d: ",++t);
if (flag) printf("Yes\n");
else printf("No\n");
}
;
}
poj2240 floyd的更多相关文章
- POJ-2240(floyd算法简单应用)
Arbitrage poj-2240 #include<iostream> #include<cstdio> #include<cstring> #include& ...
- POJ2240 Arbitrage(Floyd判负环)
跑完Floyd后,d[u][u]就表示从u点出发可以经过所有n个点回到u点的最短路,因此只要根据数组对角线的信息就能判断是否存在负环. #include<cstdio> #include& ...
- POJ2240——Arbitrage(Floyd算法变形)
Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...
- poj2240 - Arbitrage(汇率问题,floyd)
题目大意: 给你一个汇率图, 让你判断能否根据汇率盈利 #include <iostream> #include <cstdlib> #include <cstdio&g ...
- poj2240最短路 floyd
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17360 Accepted: 7308 Descri ...
- POJ-2240 Arbitrage---判断正环+枚举
题目链接: https://vjudge.net/problem/POJ-2240 题目大意: 已知n种货币,以及m种货币汇率及方式,问能否通过货币转换,使得财富增加. 思路: 由于这里问的是财富有没 ...
- floyd算法学习笔记
算法思路 路径矩阵 通过一个图的权值矩阵求出它的每两点间的最短路径矩阵.从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按一个公式,构造出矩阵D(1):又 ...
- 最短路(Floyd)
关于最短的先记下了 Floyd算法: 1.比较精简准确的关于Floyd思想的表达:从任意节点A到任意节点B的最短路径不外乎2种可能,1是直接从A到B,2是从A经过若干个节点X到B.所以,我们假设maz ...
- 最短路径之Floyd算法
Floyd算法又称弗洛伊德算法,也叫做Floyd's algorithm,Roy–Warshall algorithm,Roy–Floyd algorithm, WFI algorithm. Floy ...
随机推荐
- [充电]C++ string字符串替换
//C++ 第一种替换字符串的方法用replace()|C++ 第二种替换字符串的方法用erase()和insert()[ C++string|C++ replace()|C++ erase()|C+ ...
- (6) 深入理解Java Class文件格式(五)
前情回顾 本专栏的前几篇博文, 对class文件中的常量池进行了详细的解释. 前文讲解了常量池中的7种数据项, 它们分别是: CONSTANT_Utf8_info CONSTANT_NameAndTy ...
- 制作圆角:《CSS3 Border-radius》
今天我们在一起来看看CSS3中制作圆角的属性border-radius的具体用法.如今CSS3中的border-radius出现后,让我们没有那么多的烦恼了,首先制作圆角图片的时间是省了,而且其还有多 ...
- selenium处理Ajax浮动框方法
package com.allin.pc;import java.util.List;import org.openqa.selenium.WebElement;import org.openqa.s ...
- 常用js总结1
1.cookie.js(封装了cookie的基本操作) 1.引入cookie.js <script type="text/javascript" src="../j ...
- SerialChat与Arduino的配合使用
最近在开发过程中,用到了Arduino开发板以及其IDE:Arduino,这个IDE使用起来很方便,编码也很简单,但有一点美中不足的是Arduino只能输出数值,不能绘图,所以就用到了另外一款串口调试 ...
- CSS3的chapter1
初学CSS3的第一天,虽然之前有接触过CSS,不过好像是CSS2,我也上网了解了一下CSS3,新增了很多强大的元素,也让我更有兴趣去学习了. CSS(Cascading Style Sheets) 层 ...
- 堆排序(C++实现)
#include<iostream> #include<vector> using namespace std; void swap(vector<int> &am ...
- python打怪之路【第一篇】:99乘法表
需求:实现99乘法表 代码: #!/usr/bin/env python # -*- coding:utf-8 -*- #author chenjing for i in range(10): for ...
- mac 启动apache + php
一.启动Apache 在终端里输入命令,启动 Apache: sudo apachectl start 关闭 Apache: sudo apachectl stop 重启 Apache:sudo ap ...