POJ——T1860 Currency Exchange
http://poj.org/problem?id=1860
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 29874 | Accepted: 11251 |


题目大意:
#include <cstring>
#include <cstdio> #define dou double
#define INF 1<<29
#define MAX(a,b) ( a>b ?a :b ) using namespace std; const int N();
int n,m,s,u,v;
dou money,uvr,uvl,vur,vul;
int head[N],sumedge;
struct Edge
{
int to,next;
dou rate,lose;
Edge(int to=,int next=,dou rate=0.00,dou lose=0.00) :
to(to),next(next),rate(rate),lose(lose) {}
}edge[N<<]; void ins(int from,int to,dou rate,dou lose)
{
edge[++sumedge]=Edge(to,head[from],rate,lose);
head[from]=sumedge;
} dou change_money(dou x,dou rate,dou lose)
{ return (x-lose)*rate ; } int vis[N],if_YES;
dou dis[N]; void SPFA(int now)
{
vis[now]=;
if(if_YES) return ;
for(int i=head[now];i;i=edge[i].next)
{
int go=edge[i].to;
dou rate=edge[i].rate,lose=edge[i].lose;
dou cmoney=change_money(dis[now],rate,lose);
if(cmoney>dis[go])
{
if(vis[go])
{
if_YES=true;
break ;
}
dis[go]=cmoney;
SPFA(go);
}
}
vis[now]=;
return ;
} void init(int n)
{
if_YES=sumedge=;
memset(dis,,sizeof(dis));
memset(head,,sizeof(head));
} int main()
{
// freopen("made.txt","r",stdin);
// freopen("myout.txt","w",stdout); while(~scanf("%d%d%d%lf",&n,&m,&s,&money))
{
if(s>n)
{
printf("NO\n");
continue;
}
init(n);
for(;m;m--)
{
scanf("%d%d%lf%lf%lf%lf",&u,&v,&uvr,&uvl,&vur,&vul);
ins(u,v,uvr,uvl); ins(v,u,vur,vul);
}
dis[s]=money; SPFA(s);
if(if_YES) printf("YES\n");
else printf("NO\n");
}
return ;
}
BFS求环法:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int u,v,w;
const int maxn = ;
const int maxm = ;
const int oo = <<;
struct node
{
int u;
int v;
double x,y ;
int next;
}edge[maxm];
double dis[maxn];
int m,n,num;
double ount;
int head[maxn],cnt,sum[maxn];
int vis[maxn] = {};
queue<int>qu;
void add(int u,int v,double x,double y)
{
edge[cnt].u = u ;
edge[cnt].v = v ;
edge[cnt].x = x ;
edge[cnt].y = y ;
edge[cnt].next = head[u];
head[u] = cnt++ ;
}
int spfa(int s)
{
for(int i = ; i < m ; i++)
{
dis[i] = ;
vis[i] = ;
}
dis[s] = ount;
qu.push(s);
vis[s] = ;
while(!qu.empty())
{
int u = qu.front();
qu.pop();
vis[u] = ;
for(int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if((dis[u]-edge[i].y)*edge[i].x > dis[v])
{
dis[v] = (dis[u]-edge[i].y)*edge[i].x;
if(!vis[v])
{
vis[v] = ;
qu.push(v);
}
sum[v]++;
if(sum[v] > m)
return -;
}
}
}
return ;
}
void Init()
{
cnt = ;
memset(head,-,sizeof(head));
memset(sum,,sizeof(sum));
while(!qu.empty())
qu.pop();
}
int main()
{
freopen("made.txt","r",stdin);
freopen("stdout.txt","w",stdout); while(scanf("%d %d %d %lf",&m,&n,&num,&ount)!=EOF)
{
Init();
int u,v;
double x,y,xx,yy ;
for(int i = ; i < n ; i++)
{
scanf("%d %d %lf %lf %lf %lf",&u,&v,&x,&y,&xx,&yy);
add(u,v,x,y);
add(v,u,xx,yy);
}
if(spfa(num) > )
cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return ;
}
POJ——T1860 Currency Exchange的更多相关文章
- 最短路(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 (最短路)
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 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- POJ 1860 Currency Exchange 最短路+负环
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- POJ 1860 Currency Exchange (Bellman-Ford)
题目链接:POJ 1860 Description Several currency exchange points are working in our city. Let us suppose t ...
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
随机推荐
- pytorch 8 CNN 卷积神经网络
# library # standard library import os # third-party library import torch import torch.nn as nn impo ...
- Manacher(最大回文字串)
很好的讲解 注意两端的字符要不同,同时数组要开大一些 [Manacher]最长回文子串 #include<bits/stdc++.h> #define REP(i, a, b) for(r ...
- Java IO(三) 之 FileInputStream
前言: 对于文件系统中的文件.都能够使用FileInputStream流类以二进制的形式进行读取.可是因为Java本身的定位在JVM之上,没有处理计算机底层的能力.因此一些涉及底层处理的方法都是使用n ...
- LeetCode_Maximum Depth of Binary Tree
一.题目 Maximum Depth of Binary Tree My Submissions Given a binary tree, find its maximum depth. The ma ...
- linux定时备份mysql数据库文件
1.设定定时器:终端敲入:crontab -e命令 2,然后写入 00 23 * * * /home/db_bak_file/dbbak.sh >>/home/db_bak_fil ...
- 去除iframe滚动条
主页面的IFRAME中添加:scrolling="yes" 子页面程序代码: 让竖条消失: <body style='overflow:scroll;overflow-x:a ...
- oracle-常见的执行计划(一)
一.表访问方式 CBO基础概念中有讲到,访问表的方式有两种:全表扫描和ROWID扫描. 全表扫描的执行计划:TABLE ACCESS FULL ROWID扫描对应执行计划:TABLE ACCESS B ...
- python 3.x 学习笔记9 (面向对象)
1.面向对象 面向对象是一种对现实世界理解和抽象的方法,是计算机编程技术发展到一定阶段后的产物. 2.类(class): 一个类即是对一类拥有相同属性的对象的抽象.蓝图.原型.在类中定义了这些对象的都 ...
- 【原创】JMS发布者订阅者【异步接收消息】
发布订阅模式和PTP方式不同之处为后者依赖于一个Topic话题: package com.thunisoft.jms.mine.topic; import java.util.HashMap; imp ...
- BZOJ2225: [Spoj 2371]Another Longest Increasing CDQ分治,3维LIS
Code: #include <cstdio> #include <algorithm> #include <cstring> #define maxn 20000 ...