【SPFA】POJ1860-Currency Exchange】的更多相关文章

真是气skr人..没把d[]换成double...de了一上午的bug// 记得用G++提交啊 题目链接:http://poj.org/problem?id=1860 题意:告诉你n个点,m条路.起始点s,还有初始金额money.每条路表示从a->b的汇率和佣金以及b->a的汇率和佣金.你在该点所得是(本金-佣金)*汇率.问你这个人能不能赚钱. 题解:spfa套一下//.记得d[]换成double.具体的看看代码.QWQ. 代码: #include<iostream> #inclu…
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 currencies. There can be several points specializing in the same pair o…
[题目大意] 给出每两种货币之间交换的手续费和汇率,求出从当前货币s开始交换,能否赚. [思路] 反向运用SPFA,判断是否有正环.每次队首元素出队之后,判断一下到源点s的距离是否增大,增大则返回true.一开始判断正环的思路如果有一个元素入队超过n次,则说明存在正环.后来发现这个思路是不适用的,因为这个正环中并不一定包含源点..要注意的是:题目中的m并不是边数,边数应该是m*2!所以开数组的时候要尤其注意数组不能开小了.由于C++的判定中如果没有崩掉,不会返回RE只会返回WA,我纠结了好久才找…
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 currencies. There can be several points specializing in the…
题目链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 32128   Accepted: 12228 Description Several currency exchange points are working in our city. Let us suppose that each point specialize…
最短路计数 [问题描述]   给出一个N个顶点M条边的无向无权图,顶点编号为1-N.问从顶点1开始,到其他每个点的最短路有几条. [输入格式]   输入第一行包含2个正整数N,M,为图的顶点数与边数. 接下来M行,每行两个正整数x, y,表示有一条顶点x连向顶点y的边,请注意可能有自环与重边. [输出格式]   输出包括N行,每行一个非负整数,第i行输出从顶点1到顶点i有多少条不同的最短路,由于答案有可能会很大,你只需要输出mod 100003后的结果即可.如果无法到达顶点i则输出0. [输入样…
Currency Exchange DescriptionSeveral 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 currencies. There can be several points sp…
之前看到一题需要并查集+SPFA,然后就特别囧的发现自己SPFA这个历史遗留问题已经不知道怎么打了╮(╯▽╰)╭ 就果断挑了一题特别裸的SPFA赶紧搞搞掉,顺便自己乱YY下学SPFA的笔记,免得自己下次又逗比了 SPFA是求最短路问题的一种解法解决的是单源最短路,也就是求所有点到某一个点的最短路反正自己乱YY当成是最短的路径+BFS+是否入队就完事了,大概的看程序的标注[QAQ...表示还好自己看得懂自己的程序]据说调用STL的队列更省事,哪天学学嗯 [题目描述] 情人节到了,情侣们也活跃起来了…
[题目大意] 给出一张有向图,以1位源点,求“从源点出发到各点的距离”和“与各点返回源点的距离和”相加得到的和. [思路] 毫无疑问是最短路径,但是这数据量就算是SPFA也绝壁会超时啊,抱着必死的心态写了submitt,居然AC..才意识到Time Limit: 8000MS. 大体的实现方法就用SPFA先计算出单源最短路径,接着再把每一条边中起始点和终止点进行对话,把各点返回源点的最短路径转换为单源最短路径,重复操作. SPFA的思路大致如下:先将源点加入队列.对于队列中的队首,对于以它为起始…
链接:http://poj.org/problem?id=1860 Currency Exchange 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 currenc…