Arbitrage

poj-2240

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
map<string,int>ma;
int n;
int m;
float graph[32][32];
float d[32][32];
void floyd(){
for(int k=0;k<n;k++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(d[i][j]<d[i][k]*d[k][j]){
d[i][j]=d[i][k]*d[k][j];
}
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int c=0;
while(cin>>n&&n){
string s;
ma.clear();
for(int i=0;i<n;i++){
cin>>s;
ma[s]=i;
}
cin>>m;
string s1,s2;
float k;
memset(d,0,sizeof(d));
for(int i=0;i<m;i++){
cin>>s1>>k>>s2;
int x=ma[s1];
int y=ma[s2];
graph[x][y]=k;
d[x][y]=k;
}
floyd();
bool flag=false;
for(int i=0;i<n;i++){
if(d[i][i]>1.0){
flag=true;
break;
}
}
cout<<"Case "<<++c<<": ";
if(flag)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}

POJ-2240(floyd算法简单应用)的更多相关文章

  1. poj 2240 floyd算法

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17349   Accepted: 7304 Descri ...

  2. Floyd算法简单实现(C++)

    图的最短路径问题主要包括三种算法: (1)Dijkstra (没有负权边的单源最短路径) (2)Floyed (多源最短路径) (3)Bellman (含有负权边的单源最短路径) 本文主要讲使用C++ ...

  3. Poj(2240),Floyd求汇率是不是赚钱

    题目链接:http://poj.org/problem?id=2240. Floyd算法修改一下,我要最大路径(通过转汇率变到最大)改成max. #include <iostream> # ...

  4. 算法笔记_069:Floyd算法简单介绍(Java)

    目录 1 问题描述 2 解决方案 2.1 使用Floyd算法得到最短距离示例 2.2 具体编码   1 问题描述 何为Floyd算法? Floyd算法功能:给定一个加权连通图,求取从每一个顶点到其它所 ...

  5. poj 2240(floyd)

    http://poj.org/problem?id=2240 题意:有些人会利用货币的不用汇率来进行套现,比如1美元换0.5英镑,而1英镑又可以换10法郎,而1法郎又可以换0.21的美元,那么经过货币 ...

  6. 图论---POJ 3660 floyd 算法(模板题)

    是一道floyd变形的题目.题目让确定有几个人的位置是确定的,如果一个点有x个点能到达此点,从该点出发能到达y个点,若x+y=n-1,则该点的位置是确定的.用floyd算发出每两个点之间的距离,最后统 ...

  7. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  8. [ACM_模拟] POJ 1094 Sorting It All Out (拓扑排序+Floyd算法 判断关系是否矛盾或统一)

    Description An ascending sorted sequence of distinct values is one in which some form of a less-than ...

  9. floyd算法 青云的机房组网方案(简单)

    青云的机房组网方案(简单) 青云现在要将 nn 个机房连成一个互相连通的网络.工程师小王设计出一个方案:通过在 nn 个机房之间铺设 n-1n−1 条双向的光纤,将所有的机房连接.可以假设数据在两个机 ...

随机推荐

  1. poj 2653 线段相交裸题(解题报告)

    #include<stdio.h> #include<math.h> const double eps=1e-8; int n; int cmp(double x) { if( ...

  2. hdu5550 Game Rooms

    Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission ...

  3. Uva 12436 Rip Van Winkle's Code

    Rip Van Winkle was fed up with everything except programming. One day he found a problem whichrequir ...

  4. oslab oranges 一个操作系统的实现 final

    见 github  https://github.com/TouwaErioH/subjects/tree/master/oslab-oranges

  5. Verilog hdl 实现单周期cpu

    参考计组实验测试指令 - 简书,添加了一些细节. 1.添加 bne指令 修改 ctrl.v       之后修改mipstestloopjal_sim.asm,mars dump 为 bnetest. ...

  6. Linux 网络协议栈开发基础篇—— 网桥br0

    一.桥接的概念 简单来说,桥接就是把一台机器上的若干个网络接口"连接"起来.其结果是,其中一个网口收到的报文会被复制给其他网口并发送出去.以使得网口之间的报文能够互相转发. 交换机 ...

  7. Apple 产品反人类的设计 All In One

    Apple 产品反人类的设计 All In One 用户体验 shit rank WTF rank iPhone 更换铃声 WTF, 这么简单的一个功能搞得太复杂了 使用要下载 1.6 G的库乐队 A ...

  8. Taro 框架实现原理

    Taro 框架实现原理 小程序 H5 RN Web 多端框架 Taro 1.x & Taro 2.x 编译型架构, 语法编译转换 Taro 1/2 属于编译型架构,主要通过对类 React 代 ...

  9. HTML 5.3

    HTML 5.3 W3C Working Draft, 18 October 2018 https://www.w3.org/TR/html53/ refs https://www.w3.org/TR ...

  10. GitHub & Hacker & MicroSoft

    GitHub & Hacker & MicroSoft GitHub源码被黑客洗劫和勒索事件 微软也未能幸免 https://www.cnbeta.com/articles/tech/ ...