http://poj.org/problem?id=1860

#include <cstdio>
//#include <queue>
//#include <deque>
#include <cstring>
using namespace std;
#define MAXM 202
#define MAXN 101
int n,m;
int first[MAXN];
int next[MAXM];
int pto[MAXM];
double earn[MAXM];
int start;
double d[MAXN];
double cost[MAXM];
bool vis[MAXM];
void addedge(int from,int to,double fromcost,double fromearn,int index){
next[index]=first[from];
pto[index]=to;
cost[index]=fromcost;
earn[index]=fromearn;
first[from]=index;
}
bool input(){
bool fl=false;
memset(first,-1,sizeof(first));
double double1;
scanf("%d %d %d %lf",&n,&m,&start,&double1);
d[start]=double1;
double fromc,toc,frome,toe;
int from,to;
for(int i=0;i<m;i++){
scanf("%d %d %lf %lf %lf %lf",&from,&to,&frome,&fromc,&toe,&toc);
addedge(from,to,fromc,frome,2*i);
addedge(to,from,toc,toe,2*i+1);
if(from==start&&frome>0.999999){
fl=true;
}
else if(to==start&&toe>0.999999){
fl=true;
}
}
return fl;
}
int que[MAXM];
int quehead;
int quetail;
void pushback(int inse){
que[quetail]=inse;
quetail=(quetail+1)%MAXM;
vis[inse]=true;
}
void pushfront(int inse){
quehead=(quehead-1+MAXM)%MAXM;
que[quehead]=inse;
vis[inse]=true;
}
int pop(){
int ans=que[quehead];
quehead=(quehead+1)%MAXM;
vis[ans]=false;
return ans;
}
bool find_loop(){
if(!input())return false;
pushback(start);
while(quehead!=quetail){
int from=pop();
int p=first[from];
while(p!=-1){
int to=pto[p];
double dtemp1;
if((dtemp1=(d[from]-cost[p])*earn[p])>d[to]){
d[to]=dtemp1;
if(!vis[to]){
if(d[to]>d[que[quehead]])pushfront(to);
else pushback(to);
}
if(to==start){
return true;
}
}
p=next[p];
}
}
return false;
}
int main(){
if(find_loop()){
printf("YES\n");
}
else printf("NO\n");
}

  

POJ 1860 Currency Exchange 最短路 难度:0的更多相关文章

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

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

  2. POJ 1860 Currency Exchange (最短路)

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

  3. poj 1860 Currency Exchange (最短路bellman_ford思想找正权环 最长路)

    感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 mo ...

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

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

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

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

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

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

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

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

  8. POJ 1860 Currency Exchange (最短路)

    Currency Exchange Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) T ...

  9. POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】

    链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

随机推荐

  1. 09 redo and undo

    本章提要-----------------------------------------------redo, undo 定义redo, undo 如何工作如何访问 redo, undo提交和回滚- ...

  2. maven核心概念4

    一.Maven坐标 1.1.什么是坐标? 在平面几何中坐标(x,y)可以标识平面中唯一的一点. 1.2.Maven坐标主要组成 groupId:组织标识(包名) artifactId:项目名称 ver ...

  3. C++——并发编程

    一.高级接口:async()和Future 1.1 async()和Future的第一个用例 假设需要计算两个操作数的总和,而这两个操作数是两个函数的返回值.寻常加法如下: func1() + fun ...

  4. Android LayoutInflater深度解析 给你带来全新的认识

      转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38171465 , 本文出自:http://blog.csdn.net/lmj ...

  5. pl/sql developer执行光标所在行

    一.发现问题 需要执行某一行语句时,需要选中该行语句,点击F8才行. 二.解决问题 中文版:工具->首选项->SQL窗口->自动选择语句 英文版:tools->preferen ...

  6. 转载 - LINUX下查看CPU使用率的命令

    几个常用的命令,一些不错的解释 http://blog.csdn.net/wengpingbo/article/details/6302058 1.top 使用权限:所有使用者 使用方式:top [- ...

  7. VB6 GDI+ 入门教程[5] 基础绘图小结

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[5] 基础绘图小结 2009 年 6 月 18 日 4条 ...

  8. SQL中SUBSTRING函数的用法

    功能:返回字符.二进制.文本或图像表达式的一部分 语法:SUBSTRING ( expression, start, length ) SQL 中的 substring 函数是用来抓出一个栏位资料中的 ...

  9. 中医与DBA

    很多药方,只要吃不死,总有一款适合你.哈哈.我要做西医,先检查身体,再了解每种药的作用,做到对症下药.

  10. Java并发编程:并发容器之ConcurrentHashMap

    转载: Java并发编程:并发容器之ConcurrentHashMap JDK5中添加了新的concurrent包,相对同步容器而言,并发容器通过一些机制改进了并发性能.因为同步容器将所有对容器状态的 ...