标签:
http://poj.org/problem?id=1860
题意:现一个人手里有一种货币, 价值为 V , 他要拿到货币兑换点去兑换成另一种货币。 然后兑换货币是要有手续费 C 以及汇率 R, 计算公式为:
(V - C)* R, 问你他能否通过兑换钱币使他到最后钱币价值提高。(当然到最后还得兑换成他初始的货币)
题解:
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<queue> using namespace std; typedef long long LL; #define oo 0x3f3f3f3f #define maxn 310 int head[maxn], num[maxn], v[maxn]; double dist[maxn]; int n, s, cnt; double V; struct node { int v, next; double r, c; }e[maxn]; void Add(int u, int v, double r, double c) { e[cnt].v=v; e[cnt].r=r; e[cnt].c=c; e[cnt].next=head[u]; head[u]=cnt++; } int spfa() { queue<int>Q; v[s] = 1; num[s]++; dist[s] = V; Q.push(s); while(Q.size()) { int p = Q.front(); Q.pop(); v[p] = 0; for(int i=head[p]; i!=-1; i=e[i].next) { int q = e[i].v; double k = (dist[p] - e[i].c)*e[i].r; if(dist[q] < k) { dist[q] = k; if(!v[q]) { v[q] = 1; num[q]++; Q.push(q); if(num[q]>n) return 1; } } } } if(dist[s] > V) return 1; return 0; } int main() { int a, b, m; double rab, rba, cab, cba; while(scanf("%d%d%d%lf", &n, &m, &s, &V)!=EOF) { cnt = 0; memset(head, -1, sizeof(head)); memset(dist, 0, sizeof(dist)); memset(v, 0, sizeof(v)); memset(num, 0, sizeof(num)); for(int i=1; i<=m; i++) { scanf("%d%d%lf%lf%lf%lf", &a, &b, &rab, &cab, &rba, &cba); Add(a, b, rab, cab); Add(b, a, rba, cba); } if( spfa() ) printf("YES\n"); else printf("NO\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/daydayupacm/p/5688243.html