Codeforces Round #344 (Div. 2)-B. Print Check(贪心+模拟)
来源:互联网 发布:文墨飞星排盘软件 编辑:程序博客网 时间:2024/06/11 18:49
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 31 1 32 2 11 2 2
3 1 3 2 2 2 0 1 0
5 3 51 1 11 3 11 5 12 1 12 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.
#include<iostream>#include<functional>#include<algorithm>#include<cstring>#include<string>#include<vector>#include<cstdio>#include<cmath>#include<set>using namespace std;#define CRL(a) memset(a,0,sizeof(a))#define QWQ ios::sync_with_stdio(0)typedef unsigned __int64 LL;typedef __int64 ll;#define CMP bool cmp(const node& a,const node& b){return a.R<b.R||(a.R==b.R&&a.L<b.L); }const int T = 100010;const int mod = 1000000007;struct node{int num,a1,a2;}a[T];int row[5050],col[5050];int vis[T];int main(){#ifdef zsc freopen("input.txt","r",stdin);#endifint i,j,k,n,m;while(~scanf("%d%d%d",&n,&m,&k)){for(i=1;i<=k;++i){scanf("%d%d%d",&a[i].num,&a[i].a1,&a[i].a2);}fill(vis,vis+T,0);for(i=0;i<5050;++i){row[i] = m;col[i] = n;}i = k;int cnt = 0,val=n*m;while(i&&cnt<val){int t = 1;if(a[i].num==1&&row[a[i].a1]){j = (a[i].a1-1) * m;while(j<a[i].a1*m){if(!vis[j])vis[j] = a[i].a2,cnt++,col[t]!=0?col[t]-1:0;j++,t++;}row[a[i].a1] = 0;}else if(a[i].num==2&&col[a[i].a1]){j = a[i].a1-1;while(j<n*m){if(!vis[j])vis[j] = a[i].a2,cnt++,row[t]!=0?row[t]-1:0;j += m,t++;}col[a[i].a1] = 0;}i--;}for(i=0;i<val;++i){printf("%d ",vis[i]);if((i+1)%m==0)printf("\n");}} return 0;}
#include <bits/stdc++.h>using namespace std;int arr[5009][5009];int row[5009];int col[5009];int rowval[5009];int colval[5009];int main() { //freopen("in.txt","r+",stdin); int n,m,k,t,r,a; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=k;i++){ scanf("%d%d%d",&t,&r,&a); if(t==1){ row[r]=i; rowval[r]=a; }else{ col[r]=i; colval[r]=a; } } int ans; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ ans=0; //cout<<endl<<row[i]<<" "<<col[j]<<endl; if(row[i]>col[j]){ ans=rowval[i]; }else{ ans=colval[j]; } if(j!=1) printf(" "); printf("%d",ans); } printf("\n"); } return 0;}
- Codeforces Round #344 (Div. 2)-B. Print Check(贪心+模拟)
- Codeforces Round #344 (Div. 2) B. Print Check (模拟)
- Codeforces Round #344 (Div. 2) B. Print Check【思维】
- Codeforces Round #344 (Div. 2) B. Print Check
- Round #344 (Div. 2) B-Print Check
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- Codeforces Round #389 (Div. 2)B. Santa Claus and Keyboard Check(模拟)
- Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(贪心 模拟)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- Codeforces 631B Print Check【模拟】
- codeforces 631B Print Check模拟
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #428 (Div. 2) B 贪心
- Codeforces Round #334 (Div. 2)-More Cowbell(贪心模拟)
- Codeforces Round #340 (Div. 2)(C)贪心,模拟
- Codeforces Round #109 (Div. 2) B (贪心)
- Codeforces Round #111 (Div. 2) B Unlucky Ticket (贪心)
- 控制器间的传值(顺传&回传),代理方法
- Apache和Nginx区别
- EditText 表情符号过滤
- java单元测试(使用junit)
- 带参宏定义的一个易错题
- Codeforces Round #344 (Div. 2)-B. Print Check(贪心+模拟)
- 继往开来
- Android binder (1): 智能指针
- Ant 编译问题汇总----待续
- <%@ page isELIgnored="false"%>的作用
- 非阻塞同步算法与CAS(Compare and Swap)无锁算法
- 四次元新浪微博客户端Android源码
- BZOJ 2152 聪聪可可 [树分治 or 树形DP]
- Android binder (2): Parcel