栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1860 Currency Exchange

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1860 Currency Exchange

#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;#define maxm 105#define maxn 105struct Edge{    int v, next;    double rate, commission;}edge[maxm * 2];int n, m;int s;int head[maxn];double v;double dist[maxn];bool in_queue[maxn];int push_cnt[maxn];int q[maxn];int edge_cnt;void addedge(int a, int b, double r, double c){    edge[edge_cnt].v = b;    edge[edge_cnt].next = head[a];    edge[edge_cnt].rate = r;    edge[edge_cnt].commission = c;    head[a] = edge_cnt++;}void input(){    edge_cnt = 0;    memset(head, -1, sizeof(head));    scanf("%d%d%d%lf", &n, &m, &s, &v);    s--;    for (int i = 0; i < m; i++)    {        int a, b;        double r, c;        scanf("%d%d", &a, &b);        a--;        b--;        scanf("%lf%lf", &r, &c);        addedge(a, b, r, c);        scanf("%lf%lf", &r, &c);        addedge(b, a, r, c);    }}bool spfa(int s){    for (int i = 0; i < n; i++)        dist[i] = -1;    dist[s] = v;    memset(in_queue, 0, sizeof(in_queue));    memset(push_cnt, 0, sizeof(push_cnt));    int front, rear;    front = 0;    rear = 0;    q[rear++] = s;    in_queue[s] = true;    push_cnt[s] = 1;    while (front != rear)    {        int u = q[front++];        if (front == maxn) front = 0;        in_queue[u] = false;        double cur = dist[u];        for (int i = head[u]; ~i; i = edge[i].next)        { int v = edge[i].v; double r = edge[i].rate; double c = edge[i].commission; double temp = (cur - c) * r; if (temp > dist[v]) {     dist[v] = temp;     if (in_queue[v])         continue;     q[rear++] = v;     if (rear == maxn)         rear = 0;     in_queue[v] = true;     push_cnt[v]++;     if (push_cnt[v] > n)         return true; }        }        if (dist[s] > v) return true;    } return false;}int main(){    input();    if (spfa(s))        puts("YES");    else        puts("NO");    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379099.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号