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;

### Element UI `el-table` 实现单元格合并并计算合计 #### 单元格合并原理 为了实现在 `el-table` 中的单元格合并,可以利用 `span-method` 属性。该属性允许开发者定义函数来自定义每一行和每列的行为,从而决定哪些单元格应该被跨越显示[^2]。 当遍历表格中的每一个单元格时,可以通过比较相邻单元格的数据来判断它们是否相同;如果相同,则记录下这些位置以便后续处理成一个更大的单元格[^3]。 #### 合计功能实现方式 对于合计功能而言,在渲染之前先统计好需要展示的信息是非常重要的一步。通常情况下会预先准备一份经过加工后的数据集,其中包含了原始业务数据以及额外增加的一条或多条汇总信息。这样做的好处是可以简化视图层面上的操作复杂度,并且使得前端性能更优。 下面是一个简单的例子说明如何结合上述两个特性: ```html <template> <div id="app"> <!-- 定义 table 组件 --> <el-table :data="tableData" border style="width: 100%" :cell-style="{ textAlign: 'center' }" :header-cell-style="{ background: '#f8f9fa', color: '#6c757d' }" :span-method="objectSpanMethod"> <el-table-column prop="date" label="日期"></el-table-column> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="amount" label="金额(元)"> <template slot-scope="scope">{{ scope.row.amount | currency }}</template> </el-table-column> </el-table> <!-- 显示总计 --> <p v-if="totalAmount !== null">总金额:<strong>{{ totalAmount | currency }}</strong></p> </div> </template> <script> export default { data() { return { // 原始数据加上一条表示“合计”的特殊项 tableData: [ { date: "2023-01", name: "张三", amount: 100 }, { date: "2023-01", name: "李四", amount: 200 }, { date: "2023-02", name: "王五", amount: 300 } ], totalAmount: null, }; }, mounted() { this.calculateTotal(); }, methods: { objectSpanMethod({ row, column, rowIndex, columnIndex }) { if (columnIndex === 2 && rowIndex % 2 === 0) { return [1, 2]; // 跨越两列 } const mergedCells = {}; let rowspan; let colspan; switch (rowIndex) { case this.tableData.length - 1: // 对于最后一行,“姓名”列为跨行显示 if (columnIndex === 1) { rowspan = 1; // 不实际改变高度 colspan = 2; // 扩展到右边一栏 Object.assign(row, { name: "合计" }); } break; default: rowspan = 1; colspan = 1; } mergedCells[rowspan] = colspan || 1; return [mergedCells]; }, calculateTotal() { let sum = 0; this.tableData.forEach(item => { sum += item.amount; }); this.totalAmount = sum; // 添加一个新的对象作为合计行 this.tableData.push({ date: "", name: "", amount: this.totalAmount }) } }, }; </script> ``` 在这个案例里,通过 `calculateTotal()` 方法提前计算好了所有项目的总额,并将其附加到了原数组的最后一项上。接着在模板部分使用条件语句检查当前索引是否为最后一个元素,如果是的话就让其占据更多空间以达到视觉上的合并效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值