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<];
 vector<int>ab;
 ],n,m;
 void fun(int x)
 {
     if(x<=n)
         printf("C%d",x);
     else printf("R%d",x-n);
 }
 void work()
 {
     ;
     //for(i=0; i<=m; i++)sort(a[i].begin(),a[i].end());
     queue<int>q;
     ab.clear();
     while(!q.empty())q.pop();
     ; i<=m; i++),ans++;
     while(!q.empty())
     {
         now=q.front();
         q.pop();
         if(!b[now])
             ab.push_back(now);
         ; 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 ;
     }
     ; i<ab.size(); i++)
     {
         fun(ab[i]);
         )
             printf("\n");
         else printf(" ");
     }
 }
 int main()
 {
     int t,i,j;
     char x;
     scanf("%d",&t);
     while(t--)
     {
         scanf("%d",&n);
         m=*n;
         ; i<=m; i++)a[i].clear();
         memset(b,,sizeof(b));
         getchar();
         ; i<=n; i++)
         {
             ; 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. 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 ...

  3. 【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 ...

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

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

  5. zjuoj 3780 Paint the Grid Again

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

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. ZOJ 3781 - Paint the Grid Reloaded - [DFS连通块缩点建图+BFS求深度][第11届浙江省赛F题]

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

随机推荐

  1. 用NSAttributedString实现简单的图文混排

    iOS7以后,因为TextKit的强大,可以用NSAttributedString很方便的实现图文混排(主要是利用了NSTextAttachment). 关于Textkit的牛逼之处,可以参考objc ...

  2. Hibernate---detached entity passed to persist一个解决方法

    1.查看id生成策略,2.查看是否是手动设置的id :3.查看实体对象映射配置是否正确. 例如: public Emplopes(String name, char gender) { super(n ...

  3. crucible VS gerrit

    crucible优缺点:1.其支持各种版本控制系统,如CVS,SVN,GIT2.代码审核方面其主要支持Post commit模式,即开发者在代码提交到master后进行review3.其虽然也支持Pr ...

  4. jQuery之Deferred对象详解

    deferred对象是jQuery对Promises接口的实现.它是非同步操作的通用接口,可以被看作是一个等待完成的任务,开发者通过一些通过的接口对其进行设置.事实上,它扮演代理人(proxy)的角色 ...

  5. APUE第五章:标准IO库

    5.2流和file对象 #include <wchar.h> int fwide(FILE *fp, int mode); Returns: positive if stream is w ...

  6. 如何在网页中显示pdf

    用如下的html代码即可(例子): <div class="postBody"> <div id="cnblogs_post_body"> ...

  7. Android深入研究Adapter重绘

    一直以来Adapter的使用都仅仅是流于表面,仅仅知道要实现几个抽象的方法,把Adapter设置给某种listView,就能够非常好的工作起来.所谓理解仅仅是建立在主观的猜想上面,认为应该是这样,对, ...

  8. 在unity3d游戏中添加中文语音控制

    最近打算尝试一下OLAMI在游戏中应用的可能性,这里做一下记录. unity官方教程中的几个项目很精简,但看起来很不错,里面有全套的资源.最后我选择了tanks-tutorial来做这个实验. 下载和 ...

  9. MSIL实用指南-生成if...else...语句

    if...else...语句是非常重要的选择语句,它的生成一般需要ILGenerator的DefineLabel方法和MarkLabel方法,以及Brtrue_S和Br_S指令. 一.DefineLa ...

  10. Python-字典(dict)

    字典是一种key-value的数据类型,字典里必须写Key和value: 字典的优点是取数方便和速度快. 字典的定义使用大括号{ },每个值用“,”隔开,key和value使用“:”分隔. value ...