POJ 1860 Currency Exchange(SPFA+邻接矩阵)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std; const int eps=1e-7;
const int MAXN=110;
int N,M,S;
double V,Vcur[MAXN],R[MAXN][MAXN],C[MAXN][MAXN];
bool vis[MAXN];
int cntNode[MAXN]; bool SPFA()
{
queue<int> que;
int u,v; for(int i=1;i<=N;i++)
Vcur[i]=0,vis[i]=0,cntNode[i]=0;
Vcur[S]=V;vis[S]=1;cntNode[S]=1;
que.push(S); while(!que.empty())
{
u=que.front();que.pop();
vis[u]=0; for(v=1;v<=N;v++)
{
if((Vcur[u]-C[u][v])*R[u][v]>Vcur[v]+eps)
{
Vcur[v]=(Vcur[u]-C[u][v])*R[u][v];
if(!vis[v])
{
vis[v]=1;
++cntNode[v];
que.push(v);
if(cntNode[v]>N)
return true;
}
}
}
}
return false;
} int main()
{
scanf("%d%d%d%lf",&N,&M,&S,&V);
int a,b;
double r,c,rr,cc;
while(M--)
{
scanf("%d%d%lf%lf%lf%lf",&a,&b,&r,&c,&rr,&cc);
R[a][b]=r;C[a][b]=c;
R[b][a]=rr;C[b][a]=cc;
}
if(!SPFA()) printf("NO\n");
else printf("YES\n");
return 0;
}
POJ 1860 Currency Exchange(SPFA+邻接矩阵)的更多相关文章
- POJ 1860 Currency Exchange (SPFA松弛)
题目链接:http://poj.org/problem?id=1860 题意是给你n种货币,下面m种交换的方式,拥有第s种货币V元.问你最后经过任意转换可不可能有升值.下面给你货币u和货币v,r1是u ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange 最短路+负环
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告
三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
- (简单) POJ 1860 Currency Exchange,SPFA判圈。
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)
链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...
- POJ 1860 Currency Exchange【SPFA判环】
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
随机推荐
- jxl 导入excel
jsp部分 <div class="modal-dialog"> <div class="modal-content"> <div ...
- ascii 转换为 utf-8
Python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错: UnicodeDecodeError: 'ascii' codec can't de ...
- CSS3学习之——【特殊属性】
一.CSS3的一些特殊属性 1.1 text-shadow text-shadow曾经在css2中就出现过,但在css2.1版本中又被抛弃了,现在css3.0版本又重新捡回来了.这说明text-sha ...
- 转:iOS 屏幕适配,autoResizing autoLayout和sizeClass图文详解
1. autoResizing autoresizing是苹果早期的ui布局适配的解决办法,iOS6之前完全可以胜任了,因为苹果手机只有3.5寸的屏幕,在加上手机app很少支持横屏,所以iOS开发者基 ...
- 给Cygwin重新安装curl
之前已经安装过了cygwin了,但是重装了系统了. 不过发现cygwin倒是还可以继续使用. 现在想要使用其中的curl工具. 但是却在cygwin安装目录 E:\dev_install_root\c ...
- react 学习与使用记录
相关技术:webpack+react+react-router+redux+immutable 郭永峰react学习指南 1.git bash--windows命令行工具 --教程 下载地址 2. i ...
- ELK 日志系统搭建配置
logstash是一个数据分析软件,主要目的是分析log日志.整一套软件可以当作一个MVC模型,logstash是controller层,Elasticsearch是一个model层,kibana是v ...
- Tiny6410之控制icache驱动
什么是cache: 基于程序访问的局限性,在主存和CPU通用寄存器之间设置了一类高速的.容量较小的存储器,把正在执行的指令地址附件的一部分指令或数据从主存调入这类存储器,供CPU 在一段时间内使 ...
- eclipse背景主题
长时间对着电脑敲代码,眼睛受不了啊,果然程序员就没人权吗?之前咱给codeblocks背景换了颜色,去官网上粘粘代码然后替换一下就行了,这里不多说, 这里说的是给ecllipse换主题,按理说ecli ...
- C#导出EXCEL的方法
/// using System; using System.Collections.Generic; using System.Text; using System.Data; using Syst ...