poj 2240 Arbitrage ([kuangbin带你飞]专题四 最短路练习)

Arbitrage 描述Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 Briti 阅读详情

Description

Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 * 10.0 * 0.21 = 1.05 US dollars, making a profit of 5 percent. 

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. 

Input

The input will contain one or more test cases. Om the first line of each test case there is an integer n (1<=n<=30), representing the number of different currencies. The next n lines each contain the name of one currency. Within a name no spaces will appear. The next line contains one integer m, representing the length of the table to follow. The last m lines each contain the name ci of a source currency, a real number rij which represents the exchange rate from ci to cj and a name cj of the destination currency. Exchanges which do not appear in the table are impossible. 
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.

Output

For each test case, print one line telling whether arbitrage is possible or not in the format "Case case: Yes" respectively "Case case: No".

Sample Input

3
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

Sample Output

Case 1: Yes
Case 2: No


題意:金币之间可以转换,问转换到最后能不能盈利


题解:flod求环,看自己到自己的值能不能大于1



#include <iostream>
#include <string.h>
#include<cstdio>
using namespace std;
#define MAXC 100
#define MAXV 50

double map[MAXV][MAXV];
int n,m;

void Input(){
	char s[MAXV][MAXC],a[MAXC],b[MAXC];
	int i,k,j;
	double c;
	for(i=0;i<=n;i++)
		for(j=0;j<=n;j++)
			if(i==j)
				map[i][j]=1;
			else
				map[i][j]=0;
	for(i=1;i<=n;i++) scanf("%s",s[i]);
	scanf("%d\n",&m);
	for(i=1;i<=m;i++){
		scanf("%s %lf %s",a,&c,b);
		for(j=1;j<=n;j++)
			if(!strcmp(s[j],a)) break;
		for(k=1;k<=n;k++)
			if(!strcmp(s[k],b)) break;
		map[j][k]=c;
	}
}

void floyd(){
	int i,j,k;
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				if(map[i][k]*map[k][j]>map[i][j])
					map[i][j]=map[i][k]*map[k][j];
}

int main(){
	int cas=1,i;
	while(scanf("%d",&n) && n){
		Input();
		floyd();
		printf("Case %d: ",cas++);
		for(i=1;i<=n;i++)
			if(map[i][i]>1) break;
		if(i>n) printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}






SAP-ABAP:SAP HANA性能神器FDA:是极速查询的引擎,也是CPU过载的元凶 在SAP S/4HANA的世界里,有一个被ABAP开发者们既爱又怕的特性——Fast Data Access(FDA),它能将性能提升百倍,也能让CPU瞬间飙升。本文将带您全面解剖这一核心机制。 阅读详情

相关推荐

Carsim与AVL CRUISE联合仿真:从零搭建整车模型的实战指南

本文详细介绍了如何从零开始搭建Carsim与AVL CRUISE联合仿真整车模型,涵盖软件环境配置、接口设置、模型连接及调试技巧。通过联合仿真,可充分发挥Carsim在车辆动力学和AVL CRUISE在动力系统仿真方面的优势,为电动车和混合动力汽车的研发提供精准的整车模型分析。

weixin_29067143的博客 938

Arbitrage(最短路-floyd算法变形求正权)

Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16127   Accepted: 6780 Description Arbitrage is the use of discrepancies in currency exchange rates t

Rocky0429 2971

上证指数30年k线图_金融占星简单解读上证指数30年历史行情

阅读此文需要一定的占星基础知识,本人对于金融知识了解甚少,如有描述错误请包涵指正!影响大众事件发展趋势的都是外行星,即木星-冥王星这5颗,由于时间跨度长达30年,绘制社会行星的K线图工作量太大,所以只以时代行星对这30年行情的简单解读作为分享,在今后的短期分析中会逐渐加入社会行星,甚至在个股分析上还会加入个人行星。那即使只绘制时代行星,所展现出来的信息也无法在一张图上画出来,否则太乱难以分辨,所以...

weixin_39831242的博客 1673

hdoj1217

Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description Arbitrage is the use of discrepancies in currency exchange rates to transform o

◆◇丶生如夏花。谁来订阅我的悲伤 562

从零开始利用MATLAB进行FPGA设计(六)用ADC采集信号教程1

用AN9238采集信号的方法(1),包含PLL、FIFO、ILA的基础教程。

WZT725的博客 3094

cdk&java | 分子sdf文件生成

sdf

ASKCOS博客 1089

poj 2240 Arbitrage 是否存在套率 Bellman-ford

Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of

kongming_acm的专栏 668

地平线J6的基础简介

地平线J6M芯片:面向中阶辅助驾驶市场的高性价比芯片

weixin_43084908的博客 4445

[kuangbin带你飞]专题四 最短路练习 I - Arbitrage POJ - 2240

I - Arbitrage  POJ - 2240  Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose tha...

qq_41037114的博客 322

【Kubernetes】Kubernetes 安全沙箱深度对比:gVisor vs Kata Containers

Kubernetes安全沙箱深度对比:gVisor和Kata Containers在架构、性能与安全性方面各有特点。gVisor通过用户态内核(Sentry)实现软件隔离,启动快(毫秒级)但CPU开销大(20-30%),适合Web服务等场景。Kata Containers采用轻量级虚拟机提供硬件级隔离,启动较慢(1-2秒)但兼容性更好,适合金融等高安全需求。测试显示gVisor在动态请求下性能下降33%,而Kata性能接近原生。建议根据场景选择:多租户/快速启动用gVisor,敏感数据/极致安全用Kata,

九师兄 178

静态代码审计插件 snyk 使用教程

静态代码审计插件 snyk 使用教程

SHELLCODE_8BIT的博客 2002

[ An Ac a Day ^_^ ][kuangbin带你飞]专题四 最短路练习 POJ 2240 Arbitrage spfa求负环

题意就是问倒腾外币能不能升值 不用spfa 用其他的最短路算法也可以 松弛条件换成dist[v]<dist[u]*e[u][i].value 当然 貌似只有spfa有这个坑…… 有A (value>1.0) A 这种情况……我的天 用Dij Floyd都只用判断如果松弛到了自己 那么一定有环 直接跳出就行 1 #include<cstdio> ...

weixin_30695195的博客 110

Ubuntu22.04安装ros(一键搞定)

然后发现可以一键安装,话不多说,直接终端输入如下指令。回车之后系统会自动安装ros。

m0_47313541的博客 7413

kuangbin 最短路专题 - POJ - 2240 Arbitrage (最短路 Floyd算法)

kuangbin 最短路专题 - POJ - 2240 Arbitrage (最短路 Floyd算法) Floyd原理推荐可以看看这篇:https://blog.youkuaiyun.com/m0_46272108/article/details/108919125 感觉没什么好讲的。理解Floyd算法就可以了… 这道题是:判断图中是否存在变大环 #include<cstdio> #include<iostream> #include<cstring> #include<

ACM-ICPC 现役(铜牌) Codeforces Rating: 2172 423

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

[kuangbin]专题四 最短路练习 Arbitrage POJ - 2240【spfa】

【题目描述】 Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5...

inv0ker的博客 244

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

正权环负权环——kuangbin最短路专题总结(2)

POJ 1860 Currency Exchange POJ 3259 Wormholes POJ 2240 Arbitrage 这个是比较常见的题型了 一般就是用Bellman-Ford算法或者SPFA算法找 货币转换是找正权环看能不能钱生钱hhh 虫洞那题是找负权环看能不能和以前的自己相遇hhh 感觉这种出题都得有很神奇的脑洞 Bellman-Ford的话就是看第n次会不会发生更新,如果会则有...

qq_37087993的博客 338

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

【动态规划】套汇问题(Floyd算法)

套汇是指利用货币汇兑率的差异将一个单位的某种货币转换为大于一个单位的同种货币。例如,假定1 美元可以买0.7 英镑,1 英镑可以买9.5 法郎,且1 法郎可以买到0.16美元。通过货币兑换,一个商人可以从1 美元开始买入,得到0.7×9.5×0.16=1.064美元,从而获得6.4%的利润。 给定n 种货币c1 ,c2 ,... ,cn的有关兑换率,试设计一个有效算法,用以确定是否存在套汇的可能性...

liudongdong_jlu 4963

Arbitrage swustoj699(正权环检测)

最短路正权环检测。跟poj1860差不多,都是正权环检测。poj1860 Currency Exchange传送门1860 – Currency Exchange (poj.org)除了起点以外,dis都应该初始化为0或者很小的数。

Crushlikearush的博客 1244

最短路习题集(hdu)

下面把在杭电刷题的最短路的代码贴上 hdu 2544 点击打开链接 dijkstra算法 #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #define N 200 #define Y 33333110 using names...

ljlhnick的博客 1466

poj 1860 Currency Exchange ([kuangbin带你飞]专题四 最短路练习)

Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these curren

Strive 609

poj 3259 Wormholes ([kuangbin带你飞]专题四 最短路练习)

Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination

Strive 590

poj 3126 Prime Path([kuangbin带你飞]专题一 简单搜索)

题目连接:题目 题目大意:两个素数,每次可以改变前一个数的某一位,并且改变完还是素数,求从第一个数变成第二个数的最小步数 解题思路:能读懂题目就差不多能知道用bfs,枚举每一位,改变数,看是不是素数, #include #include #include #include #include #include #include #include using namespace std; boo

Strive 565

POJ 3414 Pots([kuangbin带你飞]专题一 简单搜索)

题目连接:题目 题目大意:给你A,B两个杯子和一同水,问你能用两个杯子倒出C的水吗, 解题思路,这个题和非常可乐这个题很相似,其实差不多,但是这个题比较麻烦一些,,标记各种情况 #include #include #include #include #include using namespace std; int a,b,c; const int maxn = 100+5;

Strive 530

poj 1502 MPI Maelstrom([kuangbin带你飞]专题四 最短路练习)

Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee'

Strive 525

poj 1679 The Unique MST ([kuangbin带你飞]专题八 生成树 )

题目大意:给你一个无向图,问如果这个无向图的最小生成树是唯一的就输出最小生成树的权值,否则输出Not Unique! 解题思路,求次小生成树,如果次小生成树中有何最小的权值一样的,则生成树不唯一,否则唯一用Kruskal,求最小生成树,然后枚举其中一个边去掉以后(n-1条),再求最小生成树,然后和原来的权值比较, #include #include #include using nam

Strive 508
上一篇: poj 3660 Cow Contest ([kuangbin带你飞]专题四 最短路练习)
下一篇: wfu第一次周赛代码
Strive_Buff
博客等级 码龄11年 4粉丝 80原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值