hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217
Arbitrage
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4430 Accepted Submission(s): 2013
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.
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.
0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <map> #define MAXX 35
#define INF 1000000000
double d[MAXX][MAXX];
using namespace std; void Flody(int n)
{
int i,j,k;
for(k=; k<n; k++)
for(i=; i<n; i++)
for(j=; j<n; j++)
if(d[i][k] * d[k][j] > d[i][j])
d[i][j] = d[i][k] * d[k][j];
} int main()
{
int n,i,j,t,tmp=;
while(scanf("%d",&n)!=EOF&&n)
{
char str[],str1[],str2[];
int cas=;
double rate;
map<string,int> m;
map<string,int>::iterator it;
for(i=; i<n; i++)
for(j=; j<n; j++)
d[i][j] = ;
for(i=; i<n; i++)
{
scanf("%s",str);
m[str]=cas++;
}
scanf("%d",&t);
for(i=; i<t; i++)
{
scanf("%s%lf%s",str1,&rate,str2);
d[m[str1]][m[str2]]=rate;
}
Flody(n);
bool flag=false;
for(i=; i<n; i++)
{
if(d[i][i]>1.0)
{
flag=true;
break;
}
}
if(flag)
{
printf("Case %d: Yes\n",++tmp);
}
else
{
printf("Case %d: No\n",++tmp);
}
}
return ;
}
hdu 1217 (Floyd变形)的更多相关文章
- hdu 1217 Arbitrage (最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1217 /************************************************* ...
- UVA10048 Audiophobia[Floyd变形]
UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- HDU 1217 Arbitrage(Bellman-Ford判断负环+Floyd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 Brit ...
- HDU 4034 Graph(Floyd变形——逆向判断)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...
- HDU 1217 Arbitrage(Floyd的应用)
给出一些国家之间的汇率,看看能否从中发现某些肮脏的......朋友交易. 这是Floyd的应用,dp思想,每次都选取最大值,最后看看自己跟自己的.....交易是否大于一.... #include< ...
随机推荐
- JavaScript复习笔记——字符串
String构造器可以使用new调用,也可以不使用,但是,这两种调用的结果也是完全不一样的.用new调用的时候,String作为构造器函数,创建字符串对象.不使用new的时候,String用作一个常规 ...
- 69道Java Spring 面试&笔试题
目录 Spring 概述 依赖注入 Spring beans Spring注解 Spring数据访问 Spring面向切面编程(AOP) Spring MVC Spring 概述 1. 什么是spri ...
- Google Map: JavaScript API RefererNotAllowedMapError
visite https://console.developers.google.com/apis/credentials and select the project you use. http:/ ...
- 删除ecshop登录后台看到的系统信息
登陆ecshop后台,默认打开在页面顶部会出现个系统信息,显示操作系统,数据库版本,以及安装日期系统版本号.部分客户问到怎么删除,这里最模板提供ecshop教程告诉大家方法. 找到admin\temp ...
- Python repr() 或str() 函数(转)
Python 有办法将任意值转为字符串:将它传入repr() 或str() 函数.函数str() 用于将值转化为适于人阅读的形式,而repr() 转化为供解释器读取的形式(如果没有等价的语法,则会发生 ...
- 关于基于webrtc的android-apk 和 webrtc-brows
这一段时间我在做一些关于基于webrtc应用的一些研究,做个一个android的demo,详情如下: 手机客户端: 基于webrtc的 android apk (webrtc 代码版本 R67 ...
- vim标准操作
主要技巧: ->普通模式负责所有光标定位能力.插入模式随时使用<esc>键回到普通模式并且尽量保持普通模式为主要的工作状态. -> hjkl四键负责光标的低速移动,如果还在使用 ...
- Alignment
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14547 Accepted: 4718 Descriptio ...
- 《利用python进行数据分析》读书笔记--第十章 时间序列(三)
7.时间序列绘图 pandas时间序列的绘图功能在日期格式化方面比matplotlib原生的要好. #-*- coding:utf-8 -*- import numpy as np import pa ...
- MySQL bin-log 日志清理方式
MySQL bin-log 作用 1.数据恢复:如果你的数据库出问题了,而你之前有过备份,那么可以看日志文件,找出是哪个命令导致你的数据库出问题了,想办法挽回损失. 2.主从服务器之间同步数据:主 ...