Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

Leo has a grid with N × N cells. He wants to paint each cell with a specific color (either black or white).

Leo has a magical brush which can paint any row with black color, or any column with white color. Each time he uses the brush, the previous color of cells will be covered by the new color. Since the magic of the brush is limited, each row and each column can only be painted at most once. The cells were painted in some other color (neither black nor white) initially.

Please write a program to find out the way to paint the grid.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains an integer N (1 <= N <= 500). Then N lines follow. Each line contains a string with N characters. Each character is either 'X' (black) or 'O' (white) indicates the color of the cells should be painted to, after Leo finished his painting.

Output

For each test case, output "No solution" if it is impossible to find a way to paint the grid.

Otherwise, output the solution with minimum number of painting operations. Each operation is either "R#" (paint in a row) or "C#" (paint in a column), "#" is the index (1-based) of the row/column. Use exactly one space to separate each operation.

Among all possible solutions, you should choose the lexicographically smallest one. A solution X is lexicographically smaller than Y if there exists an integer k, the first k - 1 operations of X and Y are the same. The k-th operation of X is smaller than the k-th in Y. The operation in a column is always smaller than the operation in a row. If two operations have the same type, the one with smaller index of row/column is the lexicographically smaller one.

Sample Input

2
2
XX
OX
2
XO
OX

Sample Output

R2 C1 R1
No solution
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;
vector<int>a[];
vector<int>ab;
int b[],n,m;
void fun(int x)
{
if(x<=n)
printf("C%d",x);
else printf("R%d",x-n);
}
void work()
{
int now,i,ans=;
//for(i=0; i<=m; i++)sort(a[i].begin(),a[i].end());
queue<int>q;
ab.clear();
while(!q.empty())q.pop();
for(i=; i<=m; i++)if(!b[i])q.push(i),b[i]=-,ans++;
while(!q.empty())
{
now=q.front();
q.pop();
if(!b[now])
ab.push_back(now);
for(i=; i<a[now].size(); i++)
{
b[a[now][i]]--;
if(!b[a[now][i]])q.push(a[now][i]),ans++;
}
}
if(ans!=m)
{
printf("No solution\n");
return ;
}
for(i=; i<ab.size(); i++)
{
fun(ab[i]);
if(i==ab.size()-)
printf("\n");
else printf(" ");
}
}
int main()
{
int t,i,j;
char x;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
m=*n;
for(i=; i<=m; i++)a[i].clear();
memset(b,,sizeof(b));
getchar();
for(i=; i<=n; i++)
{
for(j=; j<=n; j++)
{
x=getchar();
if(x=='X')
{
a[j].push_back(i+n);
b[i+n]++;
}
else
{
a[i+n].push_back(j);
b[j]++;
}
}
getchar();
}
work();
}
}

Paint the Grid Again ZOJ - 3780 拓扑的更多相关文章

  1. Paint the Grid Reloaded ZOJ - 3781 图论变形

    Paint the Grid Reloaded Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %ll ...

  2. 【最短路+bfs+缩点】Paint the Grid Reloaded ZOJ - 3781

    题目: Leo has a grid with N rows and M columns. All cells are painted with either black or white initi ...

  3. ZOJ 3780 Paint the Grid Again(隐式图拓扑排序)

    Paint the Grid Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N × N cel ...

  4. 【ZOJ - 3780】 Paint the Grid Again (拓扑排序)

    Leo has a grid with N × N cells. He wants to paint each cell with a specific color (either black or ...

  5. ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds      Me ...

  6. zjuoj 3780 Paint the Grid Again

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Paint the Grid Again Time Limit: 2 ...

  7. Paint the Grid Again (隐藏建图+优先队列+拓扑排序)

    Leo has a grid with N × N cells. He wants to paint each cell with a specific color (either black or ...

  8. ZOJ 3781 Paint the Grid Reloaded(BFS+缩点思想)

    Paint the Grid Reloaded Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N rows ...

  9. ZOJ 3781 Paint the Grid Reloaded(BFS)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Leo has a grid with N rows an ...

随机推荐

  1. 为什么Java字符串是不可变对象?

    转自 http://developer.51cto.com/art/201503/468905.htm 本文主要来介绍一下Java中的不可变对象,以及Java中String类的不可变性,那么为什么Ja ...

  2. tomcat配置不用访问工程名

    <Host name="localhost" appBase="/server/webapps" unpackWARs="true" ...

  3. svn: Can't convert string from 'UTF-8' to native

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt227 svn 版本库中有文件是以中文字符命名的,在 Linux 下 chec ...

  4. 第3阶段——内核启动分析之make uImage编译内核(3)

    目标: 通过分析makefile,明白make uImage如何编译内核 把整个内核的makefile分成三类(makefile资料文档在linux-2.6.22.6/Documentation/bu ...

  5. TensorBoard使用

    关于TensorBoard的安装是在安装Tensorflow的过程中就已经默认安装好了,所以安装了Tensorflow就不需要再安装TensorBoard,直接使用就可以了. 具体的使用方法: 命令行 ...

  6. 转: 【Java并发编程】之二十一:并发新特性—阻塞队列和阻塞栈(含代码)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17511147 阻塞队列 阻塞队列是Java5并发新特性中的内容,阻塞队列的接口是Java. ...

  7. 团队作业8——第二次项目冲刺(Beta阶段)5.27

    1.当天站立式会议照片 会议内容: 本次会议为第七次会议 本次会议在陆大楼2楼召开,本次会议内容: ①:检查总结上次任务完成情况 ②:安排今天的分工 ③:对昨天的问题进行讨论 2. 每个人的工作 (有 ...

  8. 201521123007《Java程序设计》第1周学习总结

    1. 本周学习总结 了解了JAVA语言的发展历史及特点,还有JDK.JRE.JVM三者之间的关系,安装并设置JAVA开发平台,使用Notepad++和Eclipse编辑器编写JAVA程序并运行,学会使 ...

  9. VBScript中InStr函数的用法

    InStr([start, ]str1, str2[, compare]) [用途]:返回str2在str1中的位置.匹配成功时,返回值最小值为1,未匹配到时返回0. [参数说明]: start:在s ...

  10. Java 课程设计 "Give it up"小游戏设计(个人) 201521123077

    1.团队课程设计博客链接 http://www.cnblogs.com/agts/p/7067948.html 2.个人负责模块或任务说明 个人任务:实现游戏画面的制作,游戏逻辑的编写,以及一些模块与 ...