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. Linux_window与linux之间文件互传,上传下载

    window与linux之间文件互传 运行环境:Centos os7 + win8.1 +putty putty:是一个Telnet,ssh,rlogin,纯tcp以及串行接口连接软件,由于linux ...

  2. Day-8: 面对对象编程

    面对过程的程序设计方法意在将函数分成子函数,再依次调用这些函数来解决问题. 而面对对象的程序设计方法,来源于自然界,类是实例的抽象,实例是类的具体.自定义出来的对象是类,而所有的数据都可以看成是对象, ...

  3. ADO.NET调用存储过程

    建表 CREATE TABLE [tab_cJ] ( [id] [, ) NOT NULL PRIMARY KEY, [name] [varchar] () , [age] [int] NULL , ...

  4. 记一次wiki数据爬取过程

    最近有个爬取各国领导人信息的奇怪需求,要求百度和维基两种版本的数据,最要命的还要保持数据的结构不变.正好印象中隐约记得维基有专门的领导人列表页,不考虑爬取下来的格式不变的话应该很好爬的样子. 首先思路 ...

  5. Project 5:替换指定字符串

    这个程序主要用于替换指定字符串,较为简单. #include <stdio.h> void change(char *,char *,char *); int ju(char *,char ...

  6. 启动springjar

    java -jar cms-exporter-0.0.1-SNAPSHOT.jar --spring.config.location=classpath:./config

  7. (2)ES6解构赋值-数组篇

    1.解构赋值-数组篇 //Destrcturing(解构) //ES5 /* var a = 1; var b = 2; var c = 3; */ //ES6 var [a,b,c] = [1,2, ...

  8. 转:【Java并发编程】之九:死锁(含代码)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17200937 当线程需要同时持有多个锁时,有可能产生死锁.考虑如下情形: 线程A当前持有互 ...

  9. MyEclipse安装步骤和破解

    Myeclipse的安装步骤 MyEclipse简介: MyEclipse,是在eclipse 基础上加上自己的插件开发而成的功能强大的企业级集成开发环境,主要用于Java.Java EE以及移动应用 ...

  10. 201521123025《JAVA程序设计》第6周学习总结

    1. 本章学习总结 2. 书面作业 Q1.clone方法 1.1Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么? 要克隆对象要覆盖clon ...