ZOJ Problem Set - 1058 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






分析:
题意:
第一行是测试组数t,接下来五行代表5*5的兑换矩阵,每个数分别对应两个国家之间的兑率(兑率是一个double型的数)。接下来每一行的第一个数n代表去过几个国家(n==0代表结束),其中第一个国家和最后一个国家都是美国(不在这n个里面表示),第2~n+1个数代表国家的编号(1~5),最后一个数(第n+2个数)代表开始旅行时拥有的钱。要求输出经过这么多次的兑换后 Issac Bernand Miller 所得到的钱(保留两位数,四舍五入)。




简单的模拟题。注意四舍五入的处理。
ac代码:
#include<iostream>
#include<cstdio>
using namespace std;
double a[6][6];
int b[12];
int main()
{
    int t,n;
    int i,j,k;
    double s;
    bool flag=0;
    scanf("%d",&t);
    while(t--)
    {
        if(flag)
        printf("\n");
        flag=1;
        //int m;
        for(i=1;i<=5;i++)
        for(j=1;j<=5;j++)
        scanf("%lf",&a[i][j]);
        while(scanf("%d",&n)&&n)
        {
            for(i=2;i<=n+1;i++)
            {
                scanf("%d",&b[i]);
            }
            scanf("%lf",&s);
            b[1]=1;//起点是美国
            b[i]=1;//终点也是美国
            for(i=2;i<=n+2;i++)
            {
                s=(int)(s*a[b[i-1]][b[i]]*100+0.5);//转换,四舍五入
                s/=100;
            }
            printf("%.2lf\n",s);
        }


    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值