存储构造题(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, ....... ...
随机推荐
- json格式的数组长度
var data = [{"id":"1","name":"a"},{"id":"2&qu ...
- CentOS6.4 安装 erlang
wget http://www.erlang.org/download/otp_src_17.0.tar.gz -P /usr/local/src/ wget http://www.erlang.or ...
- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...
- nodejs将PDF文件转换成txt文本,并利用python处理转换后的文本文件
目前公司Web服务端的开发是用Nodejs,所以开发功能的话首先使用Nodejs,这也是为什么不直接用python转换的原因. 由于node对文本的处理(提取所需信息)的能力不强,类似于npm上的包: ...
- Bootstrap 更改Navbar默认样式
alt+shift+n 新建文件ctrl+shift+/ 注释ctrl+shift+f 重新排版代码ctrl+/ 注释 /* navbar */.navbar-default { background ...
- jQuery自动补全
方法一: jquery-autocomplete配置: <script type="text/javascript" src="/js/jquery-1.4.2.m ...
- JQuery中ajax请求写法
$.ajax({ type: "POST", url: "ygdwController.do?getonygdw", data : "id=" ...
- Hibernate 一级二级缓存
1.一级缓存与session关联,session关闭时,缓存数据消失: 2.一级缓存无法自我控制缓存的数量,需考虑缓存溢出: 3.二级缓存与sessionFactory关联,当sessionFacto ...
- smarty模板原理
smarty模板原理 模板主要是用来让前端和后端分离的,前台页面只是一个前台页面,后台页面用php代码写逻辑,写完逻辑拿到前台显示. 一.写法 一般需要以下:写3个页面: 1.显示页面aa.htm ...
- (十一) 一起学 Unix 环境高级编程 (APUE) 之 高级 IO
. . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...