列表

详情


NC13883. Matrix

描述

Today HH is palying with a n×n matrix.
 All the numbers of the matrix is 0 initial, and every time HH will do one of the following things:
1.make all the numbers in the k row become v
2.make all the numbers in the k column become v
Now HH wants to know what's the final matrix after q options.     

输入描述

The first line contains an positive integer T(1≤T≤10), represents there are T test cases. 
For each test case: 
The first line contains two positive integers n,q(1≤n≤500,1≤q≤2*105) - the size of the matrix and the times of the options. 
 Then q lines following, for each line contains three integers op,k,v(1≤op≤2,1≤k≤n,1≤v≤100). 
 if op=1, then HH will change all the numbers in the k row into v 
 if op=2, then HH will change all the numbers in the k column into v

输出描述

For each test case, you should output n lines , each line n numbers , indicating the final matrix, note that for each line ,you should print exactly one blank between two numbers.

示例1

输入:

1
3 3
1 2 3
2 2 1
1 1 3

输出:

3 3 3
3 1 3
0 1 0

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++ 11.0.1) 解法, 执行用时: 1344ms, 内存消耗: 8492K, 提交时间: 2023-06-11 20:52:13

#include <stdio.h>
int a[501][501];
int main()
{int t;
scanf("%d",&t);
while(t--)
{int n,q;
scanf("%d%d",&n,&q);
while(q--)
{ int op,k,v;
scanf("%d%d%d",&op,&k,&v);
if(op==1)
 for(int i=0;i<n;i++)
    a[k-1][i]=v;
else for(int i=0;i<n;i++)
    a[i][k-1]=v;}
 for(int i=0;i<n;i++)
 {for(int j=0;j<n;j++)
 printf("%d ",a[i][j]);
  printf("\n");}
}}

上一题