ZOJ1058 Currency Exchange【水题】

Currency Exchange
Time Limit: 2 Seconds Memory Limit: 65536 KB
When Issac Bernand Miller takes a trip to another country, say to France, he exchanges his US dollars for French francs. The exchange rate is a real number such that when multiplied by the number of dollars gives the number of francs. For example, if the exchange rate for US dollars to French francs is 4.81724, then 10 dollars is exchanged for 48.1724 francs. Of course, you can only get hundredth of a franc, so the actual amount you get is rounded to the nearest hundredth. (We‘ll round .005 up to .01.) All exchanges of money between any two countries are rounded to the nearest hundredth.
Sometimes Issac‘s trips take him to many countries and he exchanges money from one foreign country for that of another. When he finally arrives back home, he exchanges his money back for US dollars. This has got Issac thinking about how much if his unspent US dollars is lost (or gained!) to these exchange rartes. You‘ll compute how much money Issac ends up with if he exchanges it many times. You‘ll always start with US dollars and you‘ll always end with US dollars.

Input

The first 5 lines of input will be the exchange rates between 5 countries, numbered 1 through 5. Line i will five the exchange rate from country i to each of the 5 countries. Thus the jth entry of line i will give the exchange rate from the currency of country i to the currency of country j. the exchange rate form country i to itself will always be 1 and country 1 will be the US. Each of the next lines will indicate a trip and be of the form

N c1 c2 ?? cn m

Where 1 <= n <= 10 and c1, ??, cn are integers from 2 through 5 indicating the order in which Issac visits the countries. (A value of n = 0 indicates end of input, in which case there will be no more numbers on the line.) So, his trip will be 1 -> c1 -> c2 -> ?? -> cn -> 1. the real number m will be the amount of US dollars at the start of the trip.

Output

Each trip will generate one line of output giving the amount of US dollars upon his return home from the trip. The amount should be fiven to the nearest cent, and should be displayed in the usual form with cents given to the right of the decimal point, as shown in the sample output. If the amount is less than one dollar, the output should have a zero in the dollars place.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input

1

1 1.57556 1.10521 0.691426 7.25005
0.634602 1 0.701196 0.43856 4.59847
0.904750 1.42647 1 0.625627 6.55957
1.44616 2.28059 1.59840 1 10.4843
0.137931 0.217555 0.152449 0.0953772 1
3 2 4 5 20.00
1 3 100.00
6 2 3 4 2 4 3 120.03
0

Sample Output

19.98
99.99
120.01
Source: East Central North America 2001, Practice

问题链接ZOJ1058 Currency Exchange
问题描述:(略)
问题分析
????这是一个有关汇率计算的水题,关键是数据表示,另外计算过程略微复杂,处理好就可以了。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* ZOJ1058 Currency Exchange */

#include <stdio.h>

#define M 5
double r[M + 1][M + 1];
#define N 10
int b[N + 1];

int main(void)
{
    int t, flag = 0, i, j;
    scanf("%d", &t);
    while(t--) {
        if(flag) printf("\n"); flag = 1;

        for(i = 1; i <= M; i++)     /* 读入汇率 */
            for(j = 1; j <= M; j++)
                scanf("%lf", &r[i][j]);

        int n;
        while(scanf("%d", &n) == 1 && n) {
            b[1] = 1;           /* 起始国家:美国 */
            for(i = 2;  i <= n + 1; i++)
                scanf("%d", &b[i]);
            b[i] = 1;          /* 结束国家:美国 */
            double m;
            scanf("%lf", &m);
            for(i = 2;  i <= n + 2; i++) {      /* 兑换处理 */
                m *= r[b[i - 1]][b[i]];
                m = (int)(m * 100 + 0.5);       /* 四舍五入 */
                m /= 100;
            }

            printf("%.2lf\n", m);
        }
    }

    return 0;
}

原文地址:https://www.cnblogs.com/tigerisland45/p/10159828.html

时间: 2024-11-10 14:37:34

ZOJ1058 Currency Exchange【水题】的相关文章

UCF “Practice” Local Contest — Aug 25, 2018 Boots Exchange 水题

#include <bits/stdc++.h> using namespace std; int n; set <int> a; map <int,int> cnt; int main() { cin >> n; int ans = 0; for (int i = 1; i <= n; ++i) { int x; cin >> x; a.insert(x); ++cnt[x]; } for (int i = 1; i <= n; +

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

UVA10763:Foreign Exchange&amp;&amp;UVA10340: All in All(水题)

10763:水题不解释直接贴代码. #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <math.h> #include <queue> #define eps 1e-9 typedef long long ll; using namespace std; int n; int d[500100]; int

G - Brain Network (easy)(并查集水题)

G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u CodeForces 690C1 Description One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know

POJ 1860 Currency Exchange (Bellman ford)

Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22405   Accepted: 8095 Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and pe

poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)

链接:poj 1860 题意:给定n中货币,以及它们之间的税率,A货币转化为B货币的公式为 B=(V-Cab)*Rab,其中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会增加 分析:这个题就是判断是否存在正权回路,可以用bellman-ford算法,不过松弛条件相反 也可以用SPFA算法,判断经过转换后,转换为原本货币的值是否比原值大... bellman-ford    0MS #include<stdio.h> #include<string.h> str

【POJ 1860】 Currency Exchange

[POJ 1860] Currency Exchange 模拟货比交易 输入数据n 货币种类 m 交易种类 s 初始货币类型 v 初始持币数 m行分别为 A B(该种交易的两种货币A.B) RAB, CAB, RBA ,CBA A->B和B->A的交易汇率和手续费 交易后金额为(s-c)*r 最短路模板题 遍历看是否有正环(即可无限增加资本) 写了两种做法 SPFA比BellMan耗时长 可啪 SPFA #include <cstdio> #include <vector&g

POJ1860:Currency Exchange(BF)

http://poj.org/problem?id=1860 Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be sev

POJ 1860 Currency Exchange (最短路)

Currency Exchange Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 2 Problem Description Several currency exchange points are working in our city. Let us suppose that