Gym 100917 A. Abstract Picture
来源:互联网 发布:电脑怎样下糖豆软件 编辑:程序博客网 时间:2024/05/22 18:22
Va Sya already defined the colors for some unit squares. Color of other squares does not matter for him.
For this work Va Sya is planning use the continuous technics: he paints whole row or whole column in some color. Moreover, each row and each column must be painted exactly once, so each unit square will be painted twice and its final color will be the last of two used colors.
Help Va Sya to find appropriate sequence of paints.
First line of the input contains one integer n — length of the painting side in units (1 ≤ n ≤ 3000).
Each of the next n lines contains n characters. If i-th character inj-th line equals to '?', it means that color ofi-th cell in j-th row of painting does not matter. Otherwise it contains lowercase English letter from 'a' to 'z' inclusively, which represents the color of corresponding cell (it is well known that Va Sya uses only 26 colors).
Print 2n lines, i-th of those lines contains description of i-th paint in the following format:
«h yc» — rowy is painted with colorc;
«v xc» — columnx is painted with colorc.
Rows are numbered sequentially upside down, columns are numbered sequentially leftside right, so upper left corner is on intersection of row 1 and column 1. Each row and each column must be mentioned in the output exactly once.
You may assume that there exists at least one solution for the given input. If there are several correct solutions, print any of them.
3ac?ab??cz
h 1 ph 3 qv 2 ch 2 bv 1 av 3 z 分析:正解还是很好想的,最后染色的行或列的颜色一定最多只有一种,于是我们倒着来每次把颜色种类小于等于1的行或列记入答案并删除,细节有点多导致那天调了一下下午没找到错,后来写了一个对拍发现是自己在处理'?'时太粗心了。#include <cstdio>#include <iostream>using namespace std;struct HL{ int tot,ch[27];} hl[2][3001];int tot,ans[6001][3],z[6001][2],n,num,f[3001][3001];bool jud[2][3001];char c;int Find(int x,int i){ for(int j=1;j <= 26;j++) if(hl[x][i].ch[j] > 0) return j; return 0;}int main(){ scanf("%d%*c",&n); for(int i=1;i <= n;i++) { for(int j=1;j <= n;j++) { scanf("%c",&c); if(c != '?') { hl[0][i].ch[c-'a'+1]++; hl[1][j].ch[c-'a'+1]++; f[i][j]=c-'a'+1; } } scanf("%*c"); } for(int i=1;i <= n;i++) { for(int j=1;j <= 26;j++) { if(hl[0][i].ch[j]) hl[0][i].tot++; if(hl[1][i].ch[j]) hl[1][i].tot++; } if(hl[0][i].tot <= 1) { z[++tot][0]=0; z[tot][1]=i; jud[0][i]=true; } if(hl[1][i].tot <= 1) { z[++tot][0]=1; z[tot][1]=i; jud[1][i]=true; } } int s=1,t=tot+1; while(s != t) { ans[++num][0]=z[s][0]; ans[num][1]=z[s][1]; int col=ans[num][2]=Find(z[s][0],z[s][1]); int now=z[s][0]; if(col) { for(int i=1;i <= n;i++) if(!jud[(now+1)%2][i] && hl[(now+1)%2][i].ch[col]) { if( now == 1 && f[i][z[s][1]]==0 ) continue; if( now == 0 && f[z[s][1]][i]==0 ) continue; hl[(now+1)%2][i].ch[col]--; if(hl[(now+1)%2][i].ch[col] == 0) hl[(now+1)%2][i].tot--; if(hl[(now+1)%2][i].tot <= 1) { z[t][0]=(now+1)%2; z[t][1]=i; jud[(now+1)%2][i]=true; t++; } } } s++; } for(int i=2*n; i >= 1;i--) if(ans[i][0] == 0) cout<<"h "<<ans[i][1]<<" "<<char(max(1,ans[i][2])+'a'-1)<<endl; else cout<<"v "<<ans[i][1]<<" "<<char(max(1,ans[i][2])+'a'-1)<<endl;}
- Gym 100917 A. Abstract Picture
- a picture
- a picture of innodb_adaptive_hash_index
- take a picture
- a picture of innodb_adaptive_hash_index
- Gym 100015A
- codeforces gym 100645A
- CodeForces Gym 100803A
- Gym 100543A Parades
- Gym 100962A ABBA
- codeforces Gym 101102A
- Codeforces Gym 100372A
- 【Codeforces Gym 100187A】
- Gym 101147.A
- Gym 100273A Ants
- Gym 100917A 类似拓扑 的好题
- VMware architecture - a rough picture
- A picture from notepad++ site.
- Kafka源码分析(2)
- 第五周实践项目1————三角形雏形(2)
- 当用到Map<Integer,E>的使用,用SparseArray<E>替代性能更好
- 游戏服务器架构的思考
- zzuoj-10451: 数字卡片游戏
- Gym 100917 A. Abstract Picture
- Spring注解事务的学习
- Python实现一个简单的Feistel结构的密码算法
- 多线程
- 数字图像处理-照片OCR
- ViewPager切换动画——PageTransformer
- c++第二次实验-1
- 第5周-项目1-三角形类锥形(3)
- Android 异步加载学习