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. [转载] LinkedIn架构这十年

    原文: http://colobu.com/2015/07/24/brief-history-scaling-linkedin/ 原文: A Brief History of Scaling Link ...

  2. js问的我醉的不要不要的。

    function a(b){ console.log(b); function b(){ console.log(b); } b();} a(1); 两个console.log会输出什么?竟然一个1都 ...

  3. 关于ASP.NET的web.config的小笔记

    在ASP和MVC开发中,有一些参数是需要活动更改的,最常见的就是数据库的链接字符串<connectionStrings>节点下配置的.在今天接触的项目中,我又接触到了自定义配置参数,就是可 ...

  4. hdu3124Arbiter(最小圆距离-扫描线)

    链接 详解http://blog.sina.com.cn/s/blog_6e7b12310100qnex.html #include <iostream> #include<cstd ...

  5. iOS开发之在Xcode代码中插入类似QQ的表情

    1.Xcode打开工程 2.菜单栏Edit--->SpecialCharacters 3.点击它出现

  6. uva 11800 Determine the Shape

    vjudge上题目链接:Determine the Shape 第二道独自 A 出的计算几何水题,题意就是给你四个点,让你判断它是哪种四边形:正方形.矩形.菱形.平行四边形.梯形 or 普通四边形. ...

  7. Java Base64编码解码实现

    我尝试过两种方式:java自带的sun.misc的工具类,还有commons-codec.jar 1.sun.misc的工具类 String encoderStr = null; BASE64Enco ...

  8. python操作mongodb之五大量写操作

    import pymongo #库名 db = pymongo.MongoClient('192.168.30.252',27017).bulk_example #test集合插入 db.test.i ...

  9. Python开发者须知 —— Bottle框架常见的几个坑

    Bottle是一个小巧实用的python框架,整个框架只有一个几十K的文件,但却包含了路径映射.模板.简单的数据库访问等web框架组件,而且语法简单,部署方便,很受python开发者的青睐.Pytho ...

  10. git tag推送小分析

    一个推送可以用三条命令 -[deleted]-git push origin --tags git push origin master --follow-tags git push --follow ...