【HDOJ1217】【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): 9455 Accepted Submission(s): 4359
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.
USDollar
BritishPound
FrenchFranc
3
USDollar 0.5 BritishPound
BritishPound 10.0 FrenchFranc
FrenchFranc 0.21 USDollar
3
USDollar
BritishPound
FrenchFranc
6
USDollar 0.5 BritishPound
USDollar 4.9 FrenchFranc
BritishPound 10.0 FrenchFranc
BritishPound 1.99 USDollar
FrenchFranc 0.09 BritishPound
FrenchFranc 0.19 USDollar
0
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
char ss[][];
double qwq[][];
int find(char dd[])
{
for(int i = ; i< n ;i++)
{
if(strcmp(dd,ss[i])==)return i;
}
}
int main()
{
int case1=;
while(scanf("%d",&n)&&n)
{
memset(qwq,,sizeof(qwq));
for(int i = ; i< n ; i++)
{
scanf("%s",ss[i]);
qwq[i][i]=;
}
int m;
scanf("%d",&m);
while(m--)
{
char qq[],ww[];
double asd;
scanf("%s%lf%s",qq,&asd,ww);
int u=find(qq);
int v=find(ww);
qwq[u][v]=asd;
}
for(int i = ; i < n ; i++)
{
for(int j = ; j < n; j++)
{
for(int k = ; k< n ; k++)
{
qwq[j][k]=max(qwq[j][i]*qwq[i][k],qwq[j][k]);
}
}
}
bool flag=false;
for(int i = ; i < n; i++)
{
if(qwq[i][i]>1.0)
{
flag=true;
break;
}
}
printf("Case %d: ",case1++);
if(flag){
printf("Yes\n");
}
else
printf("No\n");
} return ;
}
【HDOJ1217】【Floyd求最长路】的更多相关文章
- XYZZY(spfa求最长路)
http://acm.hdu.edu.cn/showproblem.php?pid=1317 XYZZY Time Limit: 2000/1000 MS (Java/Others) Memor ...
- spfa求最长路
http://poj.org/problem?id=1932 spfa求最长路,判断dist[n] > 0,需要注意的是有正环存在,如果有环存在,那么就要判断这个环上的某一点是否能够到达n点,如 ...
- 训练赛 Grouping(强连通分量缩点 + DAG求最长路)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=158#problem/F 大致题意:给出n个人和m种关系(ti,si),表示ti ...
- hdu 1534(差分约束+spfa求最长路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1534 思路:设s[i]表示工作i的开始时间,v[i]表示需要工作的时间,则完成时间为s[i]+v[i] ...
- POJ 3592--Instantaneous Transference【SCC缩点新建图 && SPFA求最长路 && 经典】
Instantaneous Transference Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6177 Accep ...
- POJ - 3249 Test for Job (在DAG图利用拓扑排序中求最长路)
(点击此处查看原题) 题意 给出一个有n个结点,m条边的DAG图,每个点都有权值,每条路径(注意不是边)的权值为其经过的结点的权值之和,每条路径总是从入度为0的点开始,直至出度为0的点,问所有路径中权 ...
- Vulnerable Kerbals CodeForces - 772C【拓展欧几里得建图+DAG上求最长路】
根据拓展欧几里得对于同余方程 $ax+by=c$ ,有解的条件是 $(a,b)|c$. 那么对于构造的序列的数,前一个数 $a$ 和后一个数 $b$ ,应该满足 $a*x=b(mod m)$ 即 $ ...
- HDU - 6201 transaction transaction transaction(spfa求最长路)
题意:有n个点,n-1条边的无向图,已知每个点书的售价,以及在边上行走的路费,问任选两个点作为起点和终点,能获得的最大利益是多少. 分析: 1.从某个结点出发,首先需要在该结点a花费price[a]买 ...
- 洛谷 P3627 [APIO2009]抢掠计划 Tarjan缩点+Spfa求最长路
题目地址:https://www.luogu.com.cn/problem/P3627 第一次寒假训练的结测题,思路本身不难,但对于我这个码力蒟蒻来说实现难度不小-考试时肛了将近两个半小时才刚肛出来. ...
随机推荐
- 逆袭之旅DAY16.东软实训.Oracle.索引
2018-07-12 14:44:27 四.索引1.创建索引手动创建:create index 索引名 on 表名(列名,[列名,...])create table employee(pno numb ...
- UVa 10891 - Game of Sum 动态规划,博弈 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- TModalResult 和 MessageBox 返回值
//其实是对应的{ TModalResult values } const mrNone = ; mrOk = idOk; mrCancel = idCancel; mrAbort = idAbort ...
- Android system :灯光系统_HAL_lights
一.android灯光系统框架: Java: frameworks/base/services/core/java/com/android/server/lights/LightsService.ja ...
- 卷积神经网络-Dropout
dropout 是神经网络用来防止过拟合的一种方法,很简单,但是很实用. 基本思想是以一定概率放弃被激活的神经元,使得模型更健壮,相当于放弃一些特征,这使得模型不过分依赖于某些特征,即使这些特征是真实 ...
- c#继承中的函数调用实例
using System; namespace Test { public class Base { public void Print() { ...
- ChinaCock界面控件介绍-CCButton
即将发布的ChinaCock新版本,将带来一个CCButton控件,实现可视按钮.Delphi原生的Button,在上面滑动后,当释放手指时会误触发OnClick事件,这不是我们想要的结果,CCBut ...
- L2-002. 链表去重(数组模拟)
L2-002. 链表去重 因为数值比较小,所以直接用数组来模拟 #include<cstdio> #include<cstring> #include<iostream& ...
- tomcat自动缓存的几种解决方式
第一种方法:打开一个项目,这里我打开的Mail项目,然后点击Myeclipse菜单栏中的project-选择clean: 选择要clean的项目,确定即可不用进入tomcat服务器直接清理缓存. 上面 ...
- Python 笔试 —— 效率与优雅
1. 效率 字符串拼接: 加号拼接字符串将造成对象的创建和垃圾的回收: 使用字符串的 join 方法对尤其是循环中的字符串进行拼接(先将不断出现的字符串 append 到 一个 list 中,再进行 ...