codeforces 631B Print Check
2017-09-29 17:15
323 查看
B. Print Check
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants
you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows
and m columns. Rows are numbered from top to bottom with integers from 1 to n,
while columns are numbered from left to right with integers from 1 to m.
Initially, all cells are painted in color 0.
Your program has to support two operations:
Paint all cells in row ri in
color ai;
Paint all cells in column ci in
color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) —
the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109),
means that row ri is
painted in color ai;
2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109),
means that column ci is
painted in color ai.
Output
Print n lines containing m integers
each — the resulting table after all operations are applied.
Examples
input
output
input
output
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
题目大意:给你一个n*m的矩阵,k次操作,1操作是把每一行变成相应的数字,2操作变列
模拟一下,对每一行每一列进行标记
#include<iostream>
#include<cstdio>
using namespace std;
pair<int,int> row[5010];
pair<int,int> column[5010];
int main(){
//freopen("in.txt","r",stdin);
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int test=1;test<=k;test++){
int op,x,col;
scanf("%d%d%d",&op,&x,&col);
if(op==1){
row[x].first=col;
row[x].second=test;
}
else{
column[x].first=col;
column[x].second=test;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(row[i].second>column[j].second) printf("%d",row[i].first);
else printf("%d",column[j].first);
if(j==m) putchar('\n');
else putchar(' ');
}
}
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants
you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows
and m columns. Rows are numbered from top to bottom with integers from 1 to n,
while columns are numbered from left to right with integers from 1 to m.
Initially, all cells are painted in color 0.
Your program has to support two operations:
Paint all cells in row ri in
color ai;
Paint all cells in column ci in
color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) —
the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109),
means that row ri is
painted in color ai;
2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109),
means that column ci is
painted in color ai.
Output
Print n lines containing m integers
each — the resulting table after all operations are applied.
Examples
input
3 3 3 1 1 3 2 2 1 1 2 2
output
3 1 3 2 2 2 0 1 0
input
5 3 5 1 1 1 1 3 1 1 5 1 2 1 1 2 3 1
output
1 1 1 1 0 1 1 1 1 1 0 1 1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
题目大意:给你一个n*m的矩阵,k次操作,1操作是把每一行变成相应的数字,2操作变列
模拟一下,对每一行每一列进行标记
#include<iostream>
#include<cstdio>
using namespace std;
pair<int,int> row[5010];
pair<int,int> column[5010];
int main(){
//freopen("in.txt","r",stdin);
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int test=1;test<=k;test++){
int op,x,col;
scanf("%d%d%d",&op,&x,&col);
if(op==1){
row[x].first=col;
row[x].second=test;
}
else{
column[x].first=col;
column[x].second=test;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(row[i].second>column[j].second) printf("%d",row[i].first);
else printf("%d",column[j].first);
if(j==m) putchar('\n');
else putchar(' ');
}
}
}
相关文章推荐
- codeforces 631B Print Check
- codeforces 631B B. Print Check
- Codeforces 631B Print Check【模拟】
- Codeforces 631B Print Check【模拟】
- CodeForces 631B Print Check
- CodeForces 631B Print Check
- codeforces 631B Print Check
- CodeForces 631B B. Print Check(水题水题)
- Codeforces 631B Print Check 【思维】
- 第三周周赛——基础数据结构结业场(坚持就会有AK,题目出自codeforces 633C,633D,631B,651A,651C以及poj1577)
- CodeForces 631 B.Print Check(水~)
- codeforces 631B (STL set)
- codeforces 344 B. Print Check解题报告
- codeforces 631B Print Check模拟
- codeforces 333B - Chips
- codeforces 544D Destroying Roads (最短路)
- codeforces 671A Recycling Bottles
- 【CodeForces】257C - View Angle(计算几何)
- 【CodeForces】500B - New Year Permutation(Floyd)(贪心)
- codeforces 459C - Pashmak and Buses 【构造题】