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. Ext.grid.EditorGridPanel分页刷新

    store.reload(); var start = grid.getBottomToolbar().cursor;//获取当前页开始条数 上面获取当前页第一条记录的方法有时候说未定义,我现在使用下 ...

  2. mysql的索引问题分析

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "PingFang SC"; color: #454545 } span. ...

  3. 开源的API集成测试工具 v0.1.2 - 增强体验

    Hitchhiker 是一款开源的 Restful Api 集成测试工具,你可以在轻松部署到本地,和你的team成员一起管理Api. 详细介绍请看: http://www.cnblogs.com/br ...

  4. Redis在java中的使用

    1.首先安装Redis环境.可以在Windows.linux.别的服务器上搭建Redis环境 2.在java工程中导入必须的jar包 如maven上导入两个jar] <!-- Redis必须包 ...

  5. cat、tail、head、tee、grep、wc、sort文件操作和过滤

    详见;http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt103 文件操作和过滤 绝大多数命令行工作是针对文件的.我们会在本节中讨论如何 ...

  6. struts2和spring mvc的比较

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt236   Struts2 Springmvc       机制 基于filt ...

  7. HTTP请求范例

    package com.grefr.basemethod; /*JAVA发送HTTP请求,返回HTTP响应内容,实例及应用 博客分类: JAVA实现 Java.netBeanJDKApache . J ...

  8. mkyaffs2image制作根文件系统、使用NFS挂载虚拟机目录(2)

    1.制作根文件系统及nfs烧写 1.1 先解压文件系统,/wok/nfs_root 目录下是已经构造好的各种文件系统:① fs_mini.tar.bz2 是最小的根文件系统,里面的设备节点是事先建立好 ...

  9. 九度OJ 1016 火星A+B AC版

    #include <iostream> #include <string.h> #include <sstream> #include <math.h> ...

  10. 201521123053《Java程序设计》第1周学习总结

    1. 本周学习总结 第一次接触Java,让我感到很吃力,有些困难.但我知道接触所有新事物都会困难,慢慢来就好. 下面是我这周的学习总结: one  第一节课 老师上课太快了,而且我没预习,根本跟不上 ...