Codeforces Round #344 (Div. 2) B
1 second
256 megabytes
standard input
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.
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.
Print n lines containing m integers each — the resulting table after all operations are applied.
3 3 3
1 1 3
2 2 1
1 2 2
3 1 3
2 2 2
0 1 0
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1

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的矩阵 两种操作 整行变换 与整列变换
1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai; 整行变为a
2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai. 整列变为a
输出k次变换后的矩阵;
题解:判断每一个位置上的数 其所在行的变换与所在列的变换的先后顺序以及变换结果 变换在后的 为结果 无变化的输出0;
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
struct node
{
int sor;
int reu;
} a[],b[];
int n,m,k;
int q,w,e;
int main()
{
scanf("%d %d %d",&n,&m,&k);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=; i<=k; i++)
{
scanf("%d %d %d",&q,&w,&e);
if(q==)
{
a[w].sor=i;
a[w].reu=e;
}
else
{
b[w].sor=i;
b[w].reu=e;
}
}
for(int i=; i<=n; i++)
{
// cout<<a[i].sor<<" "<<b[i].sor<<endl;
if(a[i].sor>b[].sor)
printf("%d",a[i].reu);
else
{
if(a[i].sor<b[].sor)
printf("%d",b[].reu);
else
printf("");
} for(int j=; j<=m; j++)
{
if(a[i].sor>b[j].sor)
printf(" %d",a[i].reu);
else
{
if(a[i].sor<b[j].sor)
printf(" %d",b[j].reu);
else
printf("");
}
}
printf("\n");
}
return ;
}
Codeforces Round #344 (Div. 2) B的更多相关文章
- Codeforces Round #344 (Div. 2) A. Interview
//http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...
- Codeforces Round #344 (Div. 2) A
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳
E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...
- Codeforces Round #344 (Div. 2) D. Messenger kmp
D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...
- Codeforces Round #344 (Div. 2) C. Report 其他
C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...
- Codeforces Round #344 (Div. 2) B. Print Check 水题
B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...
- Codeforces Round #344 (Div. 2) A. Interview 水题
A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...
- Codeforces Round #344 (Div. 2) B. Print Check
B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #344 (Div. 2)(按位或运算)
Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...
- Codeforces Round #344 (Div. 2)
水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...
随机推荐
- 悲剧文本(Broken Keyboard (a.k.a. Beiju Text),UVA 11988)
题目描述: 题目思路: 1.使用链表来重新定位各个字符 2.用数组实现链表 3.开一个数组list[i]来存储字符数组下一个字符的位置 #include <iostream> #inclu ...
- CsvHelper文档-2读
CsvHelper文档-2读 这个库默认不需要做任何设置就可以很容易的使用它.如果你的类属性名称直接匹配csv的标题名称,那么可以按照下面的实例来用: (以下所有的代码都需要引用using csvhe ...
- C指针函数中的局部变量返回
所谓指针函数其实就是 :一个函数的返回值为指针. 指针函数定义:返回类型标识符* 函数名(形参列表){函数体} eg: int* fun1(int n){} 指针函数和局部变量返回解析: 简 ...
- zookeeper启动配置
zookeeper安装和配置详解 转载 2014年04月16日 14:36:31 16812 摘自:http://www.ibm.com/developerworks/cn/opensource/os ...
- Delegate(QLabel和QComboBox)
一.最终效果 二.实现思路 1.createEditor()中create两个控件,分别是QLabel和QComboBox,将其添加到一个widget中,然后返回该widget: 2.setEdito ...
- Alpha冲刺——第三天
Alpha第三天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...
- java---StringBuilder类的用法(转载)
转载自http://blog.csdn.net/zi_jun/article/details/7624999 String对象是不可改变的.每次使用 System.String类中的方法之一时,都要在 ...
- LintCode-378.将二叉查找树转换成双链表
将二叉查找树转换成双链表 将一个二叉查找树按照中序遍历转换成双向链表. 样例 给定一个二叉查找树: 返回 1<->2<->3<->4<->5. 标签 链 ...
- 《学习OpenCV》课后习题解答2
题目:(P104) 创建一个拥有三个通道的二维字节类型矩阵,大小为100*100,并将所有值赋为0.通过函数cvPtr2D将指针指向中间的通道("绿色").以(20,5)与(40, ...
- AjaxPro怎么用
AjaxPro是首家支持以各种方式通过javascript访问服务端.net的免费库,类似于SAJAX.它能把Javascript请求发送到.NET方法,服务端传回给Javascript,甚至包括串行 ...