2003: Currency Table

这道题目很无语,首先是输入,最后采取的输入方法是读入一个数,就把对应的那个数算出来。接着不管读入的是什么也不会影响到。

接着这道题目用的竟然是FLOYED,但这个算法是经过改变,不需要讨论所有的,只有那种事0的外面才算的,好像是这样,但这道题目我觉得还是有歧义的。 

 

 


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout3s8192K627142Standard

A table of currency ratios can be presented in the following way:

 123...n
11.000.502.50...0.10
22.001.005.00...0.20
30.400.201.00...0.04
............1.00...
n10.005.0025.00...1.00

The presented numbers 1, 2, 3, ... , n denote currency codes.

The ratio m written in the row r and the column c of the table shows that one unit of the currency r is worth m units of the currency c. For example, the number 0.50 in the table above means that one unit of currency 1 costs half of the unit of currency 2, while the number 2.00 shows a reverse ratio, i.e. that one unit of currency 2 is equal to two units of currency 1.

There is redundancy of information in the table. For example, it is possible to develop the whole table having only one row or column.

Write a program to complete the partly filled in currency ratio table. Assume that the input data are correct and not contradictory.

Input Specification

The input file contains several partly filled currency ratio tables. For each teable the integer number n (n<=20) which denotes the size of the table is written in the first line, followed by the table containing n rows. Each row contains n real numbers. Zeros are written instead of the missing numbers.

After the last test case, a line contains a zero followed, which you should not process.

Output Specification

For each table, complete the currency table as much as possible. Each row of the table must be written on one line. Write the values with two digits after a decimal point. Mark zeros for the elements of the table that can not be restored. Write a blank line after each table.

Sample Input

3
1.00 0.50 0.00
0.00 0.00 8.00
0.00 0.00 0.00
3
1.00 0.00 4.00
0.00 1.00 0.00
0.00 0.00 0.00
0

Sample Output

1.00 0.50 4.00
2.00 1.00 8.00
0.25 0.12 1.00

1.00 0.00 4.00
0.00 1.00 0.00 
0.25 0.00 1.00

 


This problem is used for contest: 4 

 

#include<iostream>
#define t 0.00001
int main()
{
 int i,j,k,n;
 float a[21][21],m;
 freopen("in.txt","r",stdin);
 freopen("out.txt","w",stdout);
 while((scanf("%d",&n),n)!=0)
 {
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      a[i][j]=t;
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
    {
    scanf("%f",&m);
    if(i==j)
     a[i][j]=1.00;
    else
        a[i][j]=m;
       
    if(a[i][j]<=t && a[j][i]>t)
        a[i][j]=1.00/a[j][i];
    else
             if(a[i][j]>t && a[j][i]<=t)
        a[j][i]=1.00/a[i][j];      
    }
     for(k=0;k<n;k++)
    for(i=0;i<n;i++)
    {
   if(i!=k)
   {
        for(j=0;j<n;j++)
        if(i!=j && k!=j && a[i][j]<=t && a[i][k]>=t && a[k][j]>=t)
        {
                  a[i][j] = a[i][k] * a[k][j];
                  a[j][i] = 1.00 / a[i][j];
     }
   }
    }
        for(i=0;i<n;i++)
        {
          for(j=0;j<n;j++)
          {
            printf("%.2f",a[i][j]);
            if(j!=n-1) printf(" ");
    }
          printf("/n");
  } 
  printf("/n");      
 }
 return 0;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值