2003: Currency Table

来源:互联网 发布:穷人想出国 知乎 编辑:程序博客网 时间:2024/06/05 06:40

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

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

 

 


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPEstdin/stdout3s8192K627142Standard

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

 123...n11.000.502.50...0.1022.001.005.00...0.2030.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

31.00 0.50 0.000.00 0.00 8.000.00 0.00 0.0031.00 0.00 4.000.00 1.00 0.000.00 0.00 0.000

Sample Output

1.00 0.50 4.002.00 1.00 8.000.25 0.12 1.001.00 0.00 4.000.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;

原创粉丝点击