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< ...
随机推荐
- ActiveMQ消息的可靠性机制(转)
文章转自:http://www.linuxidc.com/Linux/2013-02/79664.htm 1.JMS消息确认机制 JMS消息只有在被确认之后,才认为已经被成功地消费了.消息的成功消费通 ...
- select、poll、epoll之间的区别
select.poll.epoll之间的区别总结[整理] select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就 ...
- 【python cookbook】【字符串与文本】16.以固定的列数重新格式化文本
问题:重新格式化一些很长的字符串,以指定的列数来显示 解决方案:textwrap模块的fill()方法来实现 # A long string s = "Look into my eyes, ...
- 非常好!!!【从头开始写操作系统系列】实现一个-GDT(1)【转】
转自:http://blog.csdn.net/luoyhang003/article/details/47338019 权声明:本文为博主原创文章,未经博主允许不得转载.(文章来源:http://b ...
- Wall Street English
1月23号,报名Wall Street English!
- xib托线出来的为什么是weak而不是strong
因为控件他爹( view.superview )已经揪着它的小辫了( strong reference ),你( viewController )眼瞅着( weak reference )就好了. 当 ...
- [xcode]Xcode查找函数(方法)调用及被调用
参考资料:http://stackoverflow.com/questions/7145045/find-method-references-in-xcode 这个功能有的说是 Find Caller ...
- [转]UIApplicationDelegate分析小结
转载地址:http://www.apkbus.com/android-131646-1-1.html 我们开发出来的运行在iOS平台上的应用程序都有一个UIApplication类的对象.1.是iOS ...
- Oracle关闭session锁
select session_id from v$locked_object;//找到锁的sessionId SELECT * FROM v$session //查看该sessionId以及对应的 ...
- Sudoku
Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15952 Accepted: 7791 Special Judge ...