题目大意:套汇
套利是使用货币汇率的差异将一个单位的货币转换为多个相同的货币单位,例如1美元可以买0.5英镑,1英镑可以买10法郎,1法郎可以买0.21美元,然后聪明的人经过一些列兑换可以得到 1*0.5*10*0.21 = 1.05美元,盈利百分之5,你的工作就是判断是否能套汇成功(不得不说这个描述简介漂亮,没有一句废话)。
/////////////////////////////////////////////////////////////
这道题有点类似以前做过的汇率问题,不过没有指定哪一个是自己持有的货币,估计可以是任意一种能变多都行,试一下吧,用每一个货币都试试,反正最多30种,也不算多
方法没错,不过消耗的时间比较多,应该是map比较耗时,以后小心map
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<string>
#include<map>
#include<iostream>
using namespace std; const int maxn = ;
const int oo = 0xfffffff;
const double StartMoney = ; struct node
{
    int y;
    double rate;
    node(int y, double r):y(y), rate(r){}
};
vector<node> G[maxn];
double v[maxn]; void Initialization(int s, int N)//初始化变量
{
    for(int i=; i<=N; i++)
        v[i] = -oo;     v[s] = StartMoney;
}
int  Spfa(int s)
{
    queue<int> Q;
    Q.push(s);     while(Q.size())
    {
        int i = Q.front();Q.pop();
        int len = G[i].size();         for(int j=; j<len; j++)
        {
            node q = G[i][j];
            double k = v[i] * q.rate;             if(k > v[q.y])
            {
                v[q.y] = k;
                Q.push(q.y);
            }
        }         if(v[s] > StartMoney)
            return ;
    }     return ;
} int  main()
{
    int N, M, t=;     while(scanf("%d", &N), N)
    {
        int i;
        double r;
        string A, B;
        map<string, int> a;         for(i=; i<=N; i++)
        {
            cin >> A;
            a[A] = i;
        }         scanf("%d", &M);         for(i=; i<=M; i++)
        {
            cin >> A >> r >> B;
            int x = a[A], y = a[B];
            G[x].push_back(node(y, r));
        }         for(i=; i<=N; i++)
        {
            Initialization(i, N);
            if(Spfa(i) == )
                break;
        }         if(i <= N)
            printf("Case %d: Yes\n", t++);
        else
            printf("Case %d: No\n", t++);         for(i=; i<=N; i++)
            G[i].clear();
    }     return ;

}

I - Arbitrage的更多相关文章

  1. poj 2240 Arbitrage

    Time Limit: 1000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   Java class name ...

  2. UVa 104 - Arbitrage(Floyd动态规划)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  3. Arbitrage(bellman_ford)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16652   Accepted: 7004 Descri ...

  4. 最短路(Floyd_Warshall) POJ 2240 Arbitrage

    题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...

  5. poj-------(2240)Arbitrage(最短路)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15640   Accepted: 6563 Descri ...

  6. ZOJ 1092 Arbitrage

    原题链接 题目大意:Arbitrage这个单词的解释是“套利交易”,就是利用几个币种之间的汇率差价来赚钱.比如人民币兑美元6:1,美元兑欧元1.5:1,欧元兑人民币10:1,那么用9元人民币可以换1. ...

  7. poj 2240 Arbitrage bellman-ford算法

    点击打开链接 Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13434   Accepted: 5657 ...

  8. HDU 1217 Arbitrage (Floyd)

    Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...

  9. POJ 2240 Arbitrage (求负环)

    Arbitrage 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/I Description Arbitrage is the ...

  10. POJ2240——Arbitrage(Floyd算法变形)

    Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...

随机推荐

  1. 详细查看数据库SQL执行计划

    DBCC DROPCLEANBUFFERS 清除数据缓存DBCC FREEPROCCACHE  清除执行计划缓存 SET SHOWPLAN_XML ON 此语句导致 SQL Server 不执行 Tr ...

  2. 制作SSL证书

    上一节介绍了OpenSSL的目录结构,本节介绍一下SSL证书的制作. OpenSSL安装后建议把其中的bin目录添加到系统环境变量中,方便以后操作. 建立一个新的目录SSL专门用来制作证书. 建立证书 ...

  3. 我的第一个boke

    哈哈哈 接口

  4. OC - 25.CAKeyframeAnimation

    概述 简介 CAKeyframeAnimation又称关键帧动画 CAKeyframeAnimation是抽象类CAPropertyAnimation的子类,可以直接使用 通过values与path两 ...

  5. 嵌入式css样式,写在当前的文件中

    现在有一任务,把下面的“超酷的互联网”.“服务及时贴心”.“有趣易学”这三个短词文字字号修改为18px. 如果用内联式css样式的方法进行设置将是一件很头疼的事情(为每一个<span>标签 ...

  6. SQL Server的事务处理与高级查询

    6.高级查询与脚本 6.1子查询 位于SELECT查询中的SELECT查询. 6.11 标量表达式 select id,val,val-(select avg(val) from tbltest) f ...

  7. excel poi 文件导出,支持多sheet、多列自动合并。

    参考博客: http://www.oschina.net/code/snippet_565430_15074 增加了多sheet,多列的自动合并. 修改了部分过时方法和导出逻辑. 优化了标题,导出信息 ...

  8. css学习--inline-block详解及dispaly:inline inline-block block 三者区别精要概括

    *知识储备: 内联元素:是不可以控制宽和高.margin等:并且在同一行显示,不换行. 块级元素:是可以控制宽和高.margin等,并且会换行. 1.inline-block 详解 (1)一句话就是在 ...

  9. PHP 设计模式之适配器模式

    <?php //[主要角色] //目标(Target)角色:定义客户端使用的与特定领域相关的接口,这也就是我们所期待得到的 //源(Adaptee)角色:需要进行适配的接口 //适配器(Adap ...

  10. DEDECMS栏目自定义字段添加

    用到的文件: catalog_add.htm  路径:\dede\templets\ catalog_edit.htm  路径:\dede\templets\  catalog_add.php  路径 ...