POJ 1860 Currency Exchange 解题报告

11 篇文章 0 订阅

Qusetion Link

Problem analysising

There is n type money, just like the node, m curreny exchange points ,just like m edges.
The first thing you should know is that the digraph is directed.The cost from u node to v node is (100 - 0.39)×29.75=2963.3975. You should do is trying to find a way to make money become more and more.Try to think Bellman-Ford algorithm is how to find the negative edge.The negative edge is make the cost of starting point to ending point less and less,so we can make arry called dis different , chang something ,then we can find a way make the money arise.

This is AC code

#include<iostream>
#include<queue>
#include<cstring>
#include<string>
#include<sstream>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<ctime>
using namespace std; 
#define rep(i,aa,bb) for(register int i=aa;i<=bb;i++)
#define rrep(i,aa,bb) for(register int i=aa;i>=bb;i--)
#define mset(var,val)	 memset(var,val,sizeof(var))
#define LL long long 
#define eps 0.000001
#define inf 0x3f3f3f3f
#define llinf 1e18
#define exp 0.000001
#define pai 3.141592654
#define random(x)   rand()%(x)
#define lowbit(x)   x&(-x)
inline int read()
{
	int x=0,y=1;char a=getchar();while ( a>'9' || a<'0'){if ( a=='-')y=-1;a=getchar();}
	while ( a>='0' && a<='9' ){	x=(x<<3)+(x<<1)+a-'0'; a=getchar();}return x*y;
}
#define N 109
int n,m,s;double v; 
struct node{
	int u,v;
	double h,y; 
}e[N*N];int tot = 0;double dis[N];
void add_ead(int u,int v,double uvh,double uvy){
	++tot; 
	e[tot].u = u; e[tot].v = v; e[tot].h = uvh; e[tot].y = uvy; 
}
bool bellman(){
	rep(i,1,n)	dis[i] = 0; 
	dis[s] = v; 
	for (int ai = 1 ; ai <= n; ai++){
		for (int bi = 1; bi <= tot; bi++){
			int u = e[bi].u , v = e[bi].v ; double h = e[bi].h , y = e[bi].y;
			if ( dis[v] < ( dis[u] - y )*h  ){
				dis[v] = (dis[u] - y )*h;
			}
		}
	}
	rep(i,1,tot)
		if ( dis[e[i].v] < (dis[e[i].u]-e[i].y)*e[i].h )	return true; 
	return false; 
}
int main()
{
//#ifdef LOCAL 
//	freopen("1.txt","r",stdin);
//#endif 
	srand((int)time(0));
//	std::ios::sync_with_stdio(false);
	scanf("%d%d%d%lf",&n,&m,&s,&v);
	rep(i,1,m){
		int u,v; double uvh,uvy,vuh,vuy; 
		scanf("%d%d%lf%lf%lf%lf",&u,&v,&uvh,&uvy,&vuh,&vuy);
		add_ead(u,v,uvh,uvy);
		add_ead(v,u,vuh,vuy);
	}
	if ( bellman() )	printf("YES\n");
	else printf("NO\n");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值