2014 Super Training #4 D Paint the Grid Again --模拟
原题:ZOJ 3780 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780
刚开始看到还以为是搜索题,没思路就跳过了。结果后来发现就是一个简单的模拟啊,因为每行每列都只能消去一次,直接慢慢消去就好了,因为按字典序从小到大,那就按行从大到小,列从大到小的顺序来消就可以了,消完了标记一下,把那行或者那列的元素都赋为一个特殊的字符'*'即可。
还是应该多思考啊,不要被题目吓到了。探寻题目的本质才能更好的解题。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define N 14 pair<char,int> ans[];
char ss[][];
int Rvis[],Cvis[]; int main()
{
int t,n,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%s",ss[i]);
memset(Rvis,,sizeof(Rvis));
memset(Cvis,,sizeof(Cvis));
int flag = ;
int o,x,h;
int k = ;
while(!flag)
{
flag = ;
//行X
for(i=n-;i>=;i--)
{
if(Rvis[i])
continue;
o = x = h = ;
for(j=;j<n;j++)
{
if(ss[i][j] == 'X')
x++;
else if(ss[i][j] == 'O')
break;
else
h++;
}
if(j == n && h != n) //没有出现O且不全为'*'
{
Rvis[i] = ;
ans[k].first = 'R';
ans[k++].second = i+;
for(j=;j<n;j++)
ss[i][j] = '*';
flag = ;
break;
}
else if(h == n)
Rvis[i] = ;
}
if(!flag)
continue;
//列O
for(j=n-;j>=;j--)
{
if(Cvis[j])
continue;
o = x = h = ;
for(i=;i<n;i++)
{
if(ss[i][j] == 'X')
break;
else if(ss[i][j] == 'O')
o++;
else
h++;
}
if(i == n && h != n) //没有出现X且不全为'*'
{
Cvis[j] = ;
ans[k].first = 'C';
ans[k++].second = j+;
for(i=;i<n;i++)
ss[i][j] = '*';
flag = ;
break;
}
else if(h == n)
Cvis[j] = ;
}
}
int tag = ;
for(i=;i<n;i++)
for(j=;j<n;j++)
if(ss[i][j] != '*')
{
tag = ;
break;
}
if(!tag)
puts("No solution");
else
{
printf("%c%d",ans[k-].first,ans[k-].second);
for(i=k-;i>=;i--)
printf(" %c%d",ans[i].first,ans[i].second);
printf("\n");
}
}
return ;
}
2014 Super Training #4 D Paint the Grid Again --模拟的更多相关文章
- 2014 Super Training #4 E Paint the Grid Reloaded --联通块缩点+BFS
原题: ZOJ 3781 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 题意: 给一个n*m的X,O构成的格子,对 ...
- ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds Me ...
- 2014 Super Training #8 B Consecutive Blocks --排序+贪心
当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了. 解法不想写了,可见:http://blog.csdn.net/u013368721/article/details/28071241 其实就 ...
- 2014 Super Training #8 A Gears --并查集
题意: 有N个齿轮,三种操作1.操作L x y:把齿轮x,y链接,若x,y已经属于某个齿轮组中,则这两组也会合并.2.操作Q x y:询问x,y旋转方向是否相同(等价于齿轮x,y的相对距离的奇偶性). ...
- 2014 Super Training #9 E Destroy --树的直径+树形DP
原题: ZOJ 3684 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3684 题意: 给你一棵树,树的根是树的中心(到其 ...
- 2014 Super Training #9 C E - Cup 2 --记忆化搜索
原题:ZOJ 3681 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3681 题意:给一个m,n,m表示m个人,可以把m个 ...
- 2014 Super Training #6 H Edward's Cola Plan --排序+二分
原题: ZOJ 3676 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3676 题意:给每个朋友一瓶可乐,可乐有普通和高 ...
- 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂
原题:ZOJ 3774 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...
- 2014 Super Training #7 C Diablo III --背包问题(DP)
原题: ZOJ 3769 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 一个带有一些限制的背包问题. 假设在没有限 ...
随机推荐
- 打印机问题win7 和xp
服务器端问题,重启如下服务 net stop "print spooler" net start "print spooler" gpedit.msc 本地计算 ...
- iOS 七牛云上传并获取图片----【客户端】
最近做了七牛云存储的有关内容,涉及到与后台交互获取验证的token,无奈,后台自命清高,不与理会,没办法呀,于是自己搞呗.首先呢在在七牛上注册一个账号,然后呢添加一个存储空间这时候空间名 ...
- javascript宿主对象之window.frames
window.frames属性是当前页面所有框架的集合.要注意的事,这里并没有frame和iframe做出区分.而且,无论页面存不存在框架,window.frames属性总是存在的,并总是指向wind ...
- 精简CSS代码
精简CSS代码可以帮助减小样式文件的大小,使代码清晰,方便维护. 使用简写属性及默认值 .header { margin-top: 10px; margin-right: 20px; margin-b ...
- absolute绝对定位可以实现相对定位
没有设置定位值的absolute元素是个普通又不普通的元素,普通之处在于其依旧在DOM tree中,对margin等属性敏感: 不普通在于其实际的高宽都丢失了.这非常类似于浮动(float),浮动的本 ...
- 转载 BCS 的好文章 1 - 怎么创建和使用BCS
http://www.sharepointfabian.com/2010/04/16/how-to-create-configure-consume-sharepoint-2010-secure-st ...
- SharePoint部署工具SPSD
SharePoint Solution Deployer,绝对属于必备的SharePoint工具之一了. 下载,解压这个工具,会有如下的目录(没有Assemblies和DeployGAC.bat)解压 ...
- R Graphics Cookbook 第3章 – Bar Graphs
3.1 基本条形图 library(ggplot2) library(gcookbook) pg_mean #这是用到的数据 group weight 1 ctrl 5.032 2 tr ...
- 编译hadoop eclipse的插件(hadoop1.0)
原创文章,转载请注明: 转载自工学1号馆 欢迎关注我的个人博客:www.wuyudong.com, 更多云计算与大数据的精彩文章 在hadoop-1.0中,不像0.20.2版本,有现成的eclipse ...
- iOS仿京东分类菜单之UICollectionView内容
在上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列 ...