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 ...
随机推荐
- bootstrap 固定定位
<!DOCTYPE html> <html><head><meta charset="UTF-8"><title>Boo ...
- 在PC端或移动端应用中接入商业QQ的方法
今天看博友的博客学习了一种很有用的方法: 在页面中需要接入企业的QQ,访问网址:http://shang.qq.com/widget/consult.php.(就是API接口),然后你只需要登录你的Q ...
- 线程高级应用-心得7-java5线程并发库中阻塞队列Condition的应用及案例分析
1.阻塞队列知识点 阻塞队列重要的有以下几个方法,具体用法可以参考帮助文档:区别说的很清楚,第一个种方法不阻塞直接抛异常:第二种方法是boolean型的,阻塞返回flase:第三种方法直接阻塞. 2. ...
- SQL SERVER 2008函数大全(含例子)
--SQL SERVER 2008 函数大全 /* author:TracyLee csdncount:Travylee */ /* 一.字符串函数: 1.ascii(字符串表达式) 返回字符串 ...
- RedHat 7配置yum源
卸载自带的yum软件包 rpm -e yum-utils--.el7.noarch --nodeps rpm -e yum-rhn-plugin--.el7.noarch --nodeps rpm - ...
- PPPOE协议
PPPOE协议 PPPOE的全称为PPP Over Ethernet,用于实现PPP在以太网上的传输.它要求通信双方是点到点的关系,不适于广播型的以太网和一些多点访问型网络. 一.PPPOE的作用 将 ...
- C++——将成员函数作为参数
在C++中,成员函数指针作为参数传递给其他函数和普通函数指针的传递是不同的,首先 我们来回顾一下普通函数指针的传递方法: //------------------------------------- ...
- 青云的机房组网方案(简单+普通+困难)(虚树+树形DP+容斥)
题目链接 1.对于简单的版本n<=500, ai<=50 直接暴力枚举两个点x,y,dfs求x与y的距离. 2.对于普通难度n<=10000,ai<=500 普通难度解法挺多 ...
- Nemo Documents – 给文件添加标签 以日历的形式将文件呈现出来,很像 Outlook,你可以根据年、月、日来查看不同类型的文档
Nemo Documents – 给文件添加标签 scavin(Google+) on 2012.03.28. Nemo Documents 是款文件组织管理工具(文档管理器),不是街道大妈胜似大 ...
- VI打开和编辑多个文件的命令 分屏操作
VI打开和编辑多个文件的命令 可分两种情况: 1.在同一窗口中打开多个文件: vi file1 file2 file3:n 切换到下一个文件 (n=next):N 切换到上一个文件 2.在不同窗口 ...