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 same pair of currencies. Each point has its own exchange rates, exchange rate of A to B is the quantity of B you get for 1A. Also each exchange point has some commission, the sum you have to pay for your exchange operation. Commission is always collected in source currency.
  For example, if you want to exchange 100 US Dollars into
Russian Rubles at the exchange point, where the exchange rate is 29.75,
and the commission is 0.39 you will get (100 - 0.39) * 29.75 =
2963.3975RUR.

  You surely know that there are N different currencies you can
deal with in our city. Let us assign unique integer number from 1 to N
to each currency. Then each exchange point can be described with 6
numbers: integer A and B - numbers of currencies it exchanges, and real R
AB, C AB, R BA and C BA - exchange rates and commissions when exchanging A to B and B to A respectively.

  Nick has some money in currency S and wonders if he can
somehow, after some exchange operations, increase his capital. Of
course, he wants to have his money in currency S in the end. Help him to
answer this difficult question. Nick must always have non-negative sum
of money while making his operations.

  只要判断是否存在正权回路。。。

代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue> using namespace std; const int INF=10e8;
const int MaxN=; struct Edge
{
int v;
double R,C; Edge(int _v,double _R,double _C):v(_v),R(_R),C(_C) {}
}; vector <Edge> E[MaxN];
bool vis[MaxN];
int couNode[MaxN]; bool SPFA(double S,double lowcost[],int n,int start)
{
queue <int> que;
int u,v;
double R,C;
int len; for(int i=;i<=n;++i)
{
lowcost[i]=;
vis[i]=;
couNode[i]=;
}
vis[start]=;
couNode[start]=;
lowcost[start]=S; que.push(start); while(!que.empty())
{
u=que.front();
que.pop(); vis[u]=;
len=E[u].size(); for(int i=;i<len;++i)
{
v=E[u][i].v;
R=E[u][i].R;
C=E[u][i].C; if(lowcost[u]>=C && (lowcost[u]-C)*R>= && (lowcost[u]-C)*R>lowcost[v])
{
lowcost[v]=(lowcost[u]-C)*R; if(!vis[v])
{
vis[v]=;
++couNode[v];
que.push(v); if(couNode[v]>=n)
return ;
}
}
}
} return ;
} inline void addEdge(int u,int v,double R,double C)
{
E[u].push_back(Edge(v,R,C));
} double ans[MaxN]; int main()
{
int N,M,X,u,v;
double S,r1,r2,c1,c2; while(~scanf("%d %d %d %lf",&N,&M,&X,&S))
{
for(int i=;i<=N;++i)
E[i].clear(); for(int i=;i<=M;++i)
{
scanf("%d %d %lf %lf %lf %lf",&u,&v,&r1,&c1,&r2,&c2); addEdge(u,v,r1,c1);
addEdge(v,u,r2,c2);
} if(SPFA(S,ans,N,X))
printf("NO\n");
else
printf("YES\n");
} return ;
}

(简单) POJ 1860 Currency Exchange,SPFA判圈。的更多相关文章

  1. POJ 1860 Currency Exchange (SPFA松弛)

    题目链接:http://poj.org/problem?id=1860 题意是给你n种货币,下面m种交换的方式,拥有第s种货币V元.问你最后经过任意转换可不可能有升值.下面给你货币u和货币v,r1是u ...

  2. POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)

    POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...

  3. 最短路(Bellman_Ford) POJ 1860 Currency Exchange

    题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...

  4. POJ 1860 Currency Exchange 最短路+负环

    原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Tota ...

  5. POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告

    三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...

  6. POJ 1860——Currency Exchange——————【最短路、SPFA判正环】

    Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u S ...

  7. POJ 1860 Currency Exchange【SPFA判环】

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  8. 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19881   Accepted: 711 ...

  9. POJ 1860 Currency Exchange (bellman-ford判负环)

    Currency Exchange 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/E Description Several c ...

随机推荐

  1. Lua 基础 -- 学习笔记

    标签(空格分隔): Lua 1. Lua可以一次性给多个变量赋值 变量比赋值多,多的变量就赋值nil 变量比赋值少,多的赋值舍弃 local a, b, c = 1, 2, 3 print( a, b ...

  2. GCC: compilation process..

    gcc -Iproj/src myfile.c -o myfile gcc -c myfile.c "compile without linking gcc -D DEBUG myfile. ...

  3. Android简单逐帧动画Frame的实现(三)

    android之动画(三)通过AnimationDrawable控制逐帧动画     android与逐帧动画: 效果图: 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的状态. ...

  4. HDU1114--Piggy-Bank(完全背包变形)

    Piggy-Bank   Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. 6--OC--封装 继承 多态

    OC中的类的三大特性类: 继承,封装,多态 一. 封装 封装就是对类中的一些字段,方法进行保护,不被外界所访问到,有一种权限的控制功能,这样我们在定义类的时候,哪些字段和方法不想暴露出去,哪些字段和方 ...

  6. cocos2d-x 3.x 橡皮擦功能

    1.HelloWorldScene.h cocos2d::DrawNode* _eraser; cocos2d::RenderTexture*_renderTexture; 2.HelloWorldS ...

  7. HDU 5723 Abandoned country

    题目说每条边权值都不一样,说明最小生成树是唯一的,不存在最小期望这一说. 然后就是先求出最小生成树,随便确定一个根节点,计算出每个点的子树有多少节点,记为c[x]. 指向x的这条边被统计的次数为c[x ...

  8. storm的并发

    1 storm并行的基本概念 storm集群中的一个机器可以运行一个或者多个worker,对应于一个或者多个topologies. 1个worker进程运行1个或多个excutor线程.每个worke ...

  9. 测试redis+keepalived实现简单的主备切换【转载】

    转自: 测试redis+keepalived实现简单的主备切换 - Try My Best 尽力而为 - ITeye技术网站http://raising.iteye.com/blog/2311757 ...

  10. PVST+(每个VLAN 的生成树PVST 加)

    PVST+(每个VLAN 的生成树PVST 加) 实验拓扑: 分别在 SW1 和SW2 上show spanning-tree 查看结果: SW1#show spanning-tree VLAN000 ...