POJ 1860 Currency Exchange 最短路 难度:0
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的更多相关文章
- POJ 1860 Currency Exchange 最短路+负环
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- poj 1860 Currency Exchange (最短路bellman_ford思想找正权环 最长路)
感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 mo ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
- 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 ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) T ...
- POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】
链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
随机推荐
- 简析 addToBackStack使用和Fragment执行流程
在使用Fragment的时候我们一般会这样写: FragmentTransaction transaction = getSupportFragmentManager().beginTransacti ...
- spring @ExceptionHandler注解方式实现异常统一处理
首先,在我们的工程中新建BaseController父类,内容如下: package com.ztesoft.zsmartcity.framework.exception; import java.i ...
- linux下在jar包中找类是否存在
find /usr/lib -name "*.jar" -exec grep -Hsli 类名 {} \;
- iOS开发 差间距滚动
CGFloat fView_Height(UIView *aView) { return aView.frame.size.height; } CGFloat fView_Width(UIView * ...
- [C:\Users\Administrator\.IntelliJIdea2016.1\system\tomcat\Unnamed_demo_2\work\Catalina\localhost\demo\org\apache\jsp\index_jsp.java]
http://www.oschina.net/question/1444338_2146454?sort=time
- EL表达式 (详解)(转)
EL表达式 1.EL简介 1)语法结构 ${expression} 2)[]与.运算符 EL 提供.和[]两种运算符来存取数据. 当要存取的属性名称中包含一 ...
- 图片左右滚动的js代码
html代码 <div class="demo" id="demo" style="overflow:hidden; width:660px; ...
- aspcms标签使用经验
1.调用导航栏标签写法,sort是网站后台栏目管理的编号{aspcms:type sort=19} <a href="[type:link]" title="[ty ...
- echarts折线图--数据交互
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- robotframework笔记1
机器人框架是一个基于Python的,可扩展的关键字驱动的自动化测试最终到终端的验收测试和验收测试驱动开发(ATDD)框架.它可用于检测分布式异类应用程序,其中,验证要求感人几种技术和接口. 下面列出了 ...