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 ...
随机推荐
- linux 源码包安装拾遗
源码包安装和apt-get/yum的区别 安装前的区别:概念上的区别 rpm和dpkg包是经过编译过的包,并且其安装位置由厂商说了算,厂商觉得安装在哪里合适,就会装在哪里,而源码包则是没有经过编译的文 ...
- Memcached的实战笔记
官网:http://memcached.org/ 优秀Blogs: http://blog.csdn.net/jingqiang521/article/details/48345021 开启telne ...
- 基于Linux的v4l2视频架构驱动编写
其实,我刚开始一直都不知道怎么写驱动,什么都不懂的,只知道我需要在做项目的过程中学习,所以,我就自己找了一个关于编写Linux下的视频采集监控项目做,然后上学期刚开学的时候听师兄说,跟院长做项目,没做 ...
- Numpy的使用规则
之前安装的python版本是3.7 各种库都是自己一个一个下载安装的 很操心 各种缺功能 后来发现了anaconda 啊 真是一个好东西 简单来说 它就是一个涵盖大部分常用库的python包 一次安装 ...
- 引入拦截器及swagger支持及解决redis无法初始化问题
Springboot引入拦截器 自定义的拦截器类 Interceptor package cn.zytao.taosir.auth.config; import javax.annotation.Re ...
- powerDesigner如何动态显示mysql数据库表结构
原文链接:http://jingyan.baidu.com/article/e5c39bf5d64efa39d760333c.html 有时候,由于数据库中的表太多,主外键关系复杂,对数据库的非设计人 ...
- 磁盘阵列里lun
lun的全称是logical unit number,也就是逻辑单元号.我们知道scsi总线上可挂接的设备数量是有限的,一般为6个或者15个,我们可以用target ID(也有称为scsi id的)来 ...
- 1. Git-2.12.0-64-bit .exe下载
转自:https://blog.csdn.net/u011164906/article/details/59129835 之前一直用SVN最近接触git,Git-2.12.0-64-bit .exe文 ...
- How To Do @Async in Spring--转
原文地址:http://www.baeldung.com/spring-async 1. Overview In this article, we’ll explore the asynchronou ...
- hbase的命令
1.1. 命令 名称 命令表达式 创建表 create '表名', '列族名1','列族名2','列族名N' 查看所有表 list 描述表 describe ‘表名’ 判断表存在 exists ' ...