poj2240 - Arbitrage(汇率问题,floyd)

题目大意:

给你一个汇率图, 让你判断能否根据汇率盈利

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
#define INF 0xfffffff
#define maxn 50

char P[maxn][maxn];
double G[maxn][maxn];
int n, m;

bool Floyd()
{
    for(int k=0; k<n; k++)
    {
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
            {
                if(G[i][j] < G[i][k] * G[k][j])
                {
                    G[i][j] = G[i][k] * G[k][j];
                }
            }
        }
    }

    for(int i=0; i<n; i++)
    {
        if(G[i][i] > 1)
            return true;
    }
    return false;
}
int num(char str[])
{
    for(int i=0; i<n; i++)
    {
        if( strcmp(str,P[i]) == 0 )
            return i;
    }
    return -1;
}
int main()
{
    char str[maxn];
    int a, b, cas = 1;
    double c;
    while(scanf("%d",&n), n)
    {
        memset(G,0,sizeof(G));

        for(int i=0; i<n; i++)
        {
            scanf("%s",P[i]);
            G[i][i] = 1;
        }

        scanf("%d",&m);

        for(int i=0; i<m; i++)
        {
            scanf("%s",str);
            a = num(str);
            scanf("%lf",&c);
            scanf("%s",str);
            b = num(str);
            G[a][b] = c;
        }
        printf("Case %d: ",cas++);

        if( Floyd() )
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

  

时间: 2024-10-13 20:13:03

poj2240 - Arbitrage(汇率问题,floyd)的相关文章

POJ2240——Arbitrage(Floyd算法变形)

Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys

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

Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15640   Accepted: 6563 Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currenc

POJ-2240 -Arbitrage(Bellman)

题目链接:Arbitrage 让这题坑了,精度损失的厉害,用赋值的话,直接全部变成0.00了,无奈下,我只好往里输了,和POJ1860一样找正环,代码也差不多,稍微改改就可以了,但是这个题精度损失的比那个....水过 POJ计划的最短路模块,刷完了,最短路问题,挺坑的,但是就是那点东西,变来变去,就是改改dis[]的更新条件. 明天就要开始POJ的最小生成树了, ME                  TI 704Kb            46Ms #include <iostream> #

UVA 436 - Arbitrage (II)(floyd)

UVA 436 - Arbitrage (II) 题目链接 题意:给定一些国家货币的汇率,问能否通过不断换货币使钱得到增长 思路:floyd,完事后判断一下有没有连到自己能大于1的情况 代码: #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <map> using namespace std; const int N = 35;

uva 104 Arbitrage (DP + floyd)

uva 104 Arbitrage Description Download as PDF Background The use of computers in the finance industry has been marked with controversy lately as programmed trading – designed to take advantage of extremely small fluctuations in prices – has been outl

poj2240 Arbitrage (spfa判环)

Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10997   Accepted: 4622 Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currenc

Arbitrage(最短路-floyd算法变形求正权)

Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16127   Accepted: 6780 Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currenc

poj2240——Arbitrage(Bellman-Ford算法)

Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 Fre

poj图论解题报告索引

最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman-ford,spfa) poj1511 - Invitation Cards(单源来回最短路径,spfa邻接表) poj1797 - Heavy Transportation(最大边,最短路变形,dijkstra,spfa,bellman-ford) poj2240 - Arbitrage(汇率问题,