题目大意:套汇
套利是使用货币汇率的差异将一个单位的货币转换为多个相同的货币单位,例如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. Debug your C# project more efficiently

    I am a very beginner working with C# and Visual Studio 2013. When I debug my project, I always reope ...

  2. corejava_chap02

    //单行注释  --不能用在一行代码的中间/**/多行注释 --任何地方/** */文档注释  文档注释用在:package.class.member variables.member method. ...

  3. 安装freebsd9 出现 mountroot>怎么办

    之前手欠把linux分区给删了想重装freebsd 重新进入的时候mbr提示grub信息 用PE把MBR删掉 之后再用freebsd光盘启动出现mountroot> 就用mountroot> ...

  4. 解决 dyld: Library not loaded:Reason: image not found

    在使用第三方framework时,直接把framework拖到项目中,运行时报错: dyld: Library not loaded: @rpath/ZipZap.framework/ZipZap R ...

  5. MySQL数据库服务器 主从配置

    A B 为两台 MySQL 服务器,均开启二进制日志,数据库版本 MySQL 5.5 一.服务器参数   [A 服务器 192.168.1.100] server-id = 1 binlog-do-d ...

  6. php配置虚拟主机的配置步骤(hosts、httpd.conf、vhosts.conf)1.配置本地的dns文件2.配置apache的主配置文件3.配置Apache的虚拟主机

    1.域名解析(DNS) 找到C:\Windows\System32\drivers\etc目录下的hosts文件,在里面进行添加对应的内容

  7. javascript原型模式理解

    传统的面向对象语言中,创建一个对象是通过使用类来创建一个对象的,比如通过类飞行器来创建一个对象,飞机. 而js这种没有类概念的动态设计语言中,创建对象是通过函数来创建的,所以通常也把js称为函数式语言 ...

  8. 网页布局只mian部分左右固定,中间部分自适应

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. Android ListView+image的使用

    首先创建layout部局文件xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayo ...

  10. 【转载】详细解读C#中的 .NET 弱事件模式

    你可能知道,事件处理是内存泄漏的一个常见来源,它由不再使用的对象存留产生,你也许认为它们应该已经被回收了,但不是,并有充分的理由. 在这个短文中(期望如此),我会在 .Net 框架的上下文事件处理中展 ...