存储构造题(Print Check)
连接:Print Check
题意:n行m列的矩阵,有k次涂色,每一涂一行或者一列,求最后的涂色结果。
从数据的大小看,暴力肯定要TLE;
问题是如何存储数据。
首先:我们只要最后的涂色结果。
其次:没有必要用for每个数据涂一遍。
所以如果能一次直接涂一行就可以了;
#include <iostream>
#include <cstdio>
uising namespace std;
#define N 5005
const int M = 1e9 +;
typedef long long LL;
int row[N],col[N];
int rt[N],ct[N];
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m,k,x,a,rc;
cin>>n>>m>>k;
for(int i = ; i <= k; i++){
scanf("%d%d%d",&rc,&x,&a);
if(rc == ){
row[x] = a;rt[x] = i;
}
else {
col[x] = a;ct[x] = i;
}
}
for(int i = ;i <= n; i++){
for(int j = ;j <= m;j++){
printf("%d ",rt[i] < ct[j]?col[j]:row[i]);
}
printf("\n");
}
return ;
}
存储构造题(Print Check)的更多相关文章
- 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 ...
- HDU 5355 Cake (WA后AC代码,具体解析,构造题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5355 题面: Cake Time Limit: 2000/1000 MS (Java/Others) ...
- cf251.2.C (构造题的技巧)
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- 【构造题 贪心】cf1041E. Tree Reconstruction
比赛时候还是太慢了……要是能做快点就能上分了 Monocarp has drawn a tree (an undirected connected acyclic graph) and then ha ...
- Codeforces 1491G - Switch and Flip(构造题)
Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \( ...
- 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 ...
- hdu4671 Backup Plan ——构造题
link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 2, ....... ...
随机推荐
- PHP中去除字符串中的换行的方法
在PHP中,有时候我们需要对字符串的换行进行过滤,比如天涯PHP博客中文章页面的description信息,我是直接截取的文章内容,并过滤掉html符号,最终还要过滤掉其中的换行.下面整理一下常见的去 ...
- Linux 日志服务器 rsyslog
预先需要httpd.php.mysql,yum方式安装.创建数据库: yum install rsyslog rsyslog-mysql cd /usr/share/doc/rsyslog-mysql ...
- 慕课网-安卓工程师初养成-5-4 使用 Eclipse 调试程序
来源:http://www.imooc.com/video/1627 IDE断点调试功能 比如 之前的程序,写错了,变成如下 package com.imooc; import java.util.S ...
- 使用PHP导入和导出CSV文件
我们先准备mysql数据表,假设项目中有一张记录学生信息的表student,并有id,name,sex,age分别记录学生的姓名.性别.年龄等信息. CREATE TABLE `student` ( ...
- 为什么C++中空类和空结构体大小为1?(转载)
原文链接:http://www.spongeliu.com/260.html 对于结构体和空类大小是1这个问题,首先这是一个C++问题,在C语言下空结构体大小为0(当然这是编译器相关的).这里的空类和 ...
- 异步编程:When.js快速上手
前些天我在团内做了一个关于AngularJS的分享.由于AngularJS大量使用Promise,所以我把基于Promise的异步编程也一并介绍了下.很多东西都是一带而过,这里再记录下. Angula ...
- PIC32MZ tutorial -- 32-bit Timer
The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...
- 深入理解JS异步编程(一)
js事件概念 异步回调 首先了讲讲js中 两个方法 setTimeout()和 setInterval() 定义和用法: setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式. 语法 ...
- 【转】你真的理解Python中MRO算法吗?
你真的理解Python中MRO算法吗? MRO(Method Resolution Order):方法解析顺序. Python语言包含了很多优秀的特性,其中多重继承就是其中之一,但是多重继承会引发很多 ...
- mysql 重复数据防止插入:)
insert into table (id, name, age) values(1, "A", 19) on duplicate key update name=values(n ...