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 ...
随机推荐
- POJ 2187 Beauty Contest( 凸包求最远点对 )
链接:传送门 题意:给出 n 个点,求出这 n 个点中最远的两个点距离的平方 思路:最远点对一定会在凸包的顶点上,然后直接暴力找一下凸包顶点中距离最远的两个点 /******************* ...
- BZOJ 1492 [NOI2007]货币兑换Cash (CDQ分治/splay 维护凸包)
题目大意:太长了略 splay调了两天一直WA弃疗了 首先,我们可以猜一个贪心,如果买/卖,就一定都买/卖掉,否则不买/卖 反正货币的行情都是已知的,没有任何风险,所以肯定要选择最最最优的方案了 容易 ...
- HDU 6125 Free from square (状压DP+分组背包)
题目大意:让你在1~n中选择不多于k个数(n,k<=500),保证它们的乘积不能被平方数整除.求选择的方案数 因为质数的平方在500以内的只有8个,所以我们考虑状压 先找出在n以内所有平方数小于 ...
- hadoop 使用java操作hdfs
1.创建目录 import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.ha ...
- 光盘文件的挂载和yum源配置
一.挂载光盘文件 1.将光盘推入 2.新建挂载点 mkdir /mnt/cdrom 3.挂载 3.1临时挂载 mount /dev/dcrom /mnt/cdrom 或者 mount –t iso ...
- WinServer-授权规则
授权规则: 使用谓词可以限制网站只能使用某一种请求 来自为知笔记(Wiz)
- CentOS进入图形界面
CentOS进入图形界面 学习了: http://www.centoscn.com/CentosBug/osbug/2014/0831/3620.html http://bbs.csdn.net/to ...
- python爬虫 分页获取图片并下载
--刚接触python2天,想高速上手,就写了个爬虫,写完之后,成就感暴增,用起来顺手多了. 1.源代码 #coding=utf-8 import urllib import re class Pag ...
- spring web mvc第一天
spring web mvc 感觉就是高大上啊!啥都是配置文件就能够了.所以第一步就是弄清楚配置文件使用和总体框架的流程! Spring web mvc最重要的当然是Controller,也就是首先 ...
- yolo源码解析(2):处理图片
首先安装ffmpeg, 参考https://blog.csdn.net/lwgkzl/article/details/77836207 然后将视频切分为图片, 参考:https://zhuanlan. ...