【wikioi】1108 方块游戏(模拟)
http://wikioi.com/problem/1108/
这题有点变态,因为他根本没有策略!
还是说这题不是实时的?反正这题很变态,是在一个时间段同时消除所有的行列斜边,同一时间!!!!!!
所以直接模拟找出所有这些行列就行了。
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define rep(i, n) for(int i=0; i<(n); ++i)
- #define for1(i,a,n) for(int i=(a);i<=(n);++i)
- #define for2(i,a,n) for(int i=(a);i<(n);++i)
- #define for3(i,a,n) for(int i=(a);i>=(n);--i)
- #define for4(i,a,n) for(int i=(a);i>(n);--i)
- #define CC(i,a) memset(i,a,sizeof(i))
- #define read(a) a=getnum()
- #define print(a) printf("%d", a)
- #define dbg(x) cout << #x << " = " << x << endl
- #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
- inline int getnum() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
- inline const int max(const int &a, const int &b) { return a>b?a:b; }
- inline const int min(const int &a, const int &b) { return a<b?a:b; }
- const int fx[4]={1, 1, 0, -1}, fy[4]={0, 1, 1, 1}, N=70;
- int n, m, vis[N][N], flag;
- char a[N][N];
- inline const bool cmp(const char &a, const char &b, const char &c) { if(a==b && b==c && a!=' ') return true; return false; }
- inline void lian(int x, int y, const int &i, const char &c) { for(x+=fx[i], y+=fy[i]; x>=0 && x<n && y>=0 && y<m && a[x][y]==c; x+=fx[i], y+=fy[i]) vis[x][y]=1; }
- inline void xiao(const int &x, const int &y) {
- int x1, x2, y1, y2;
- rep(i, 4) {
- x1=x+fx[i]; y1=y+fy[i];
- x2=x1+fx[i]; y2=y1+fy[i];
- if(x2>=0 && x2<n && y2>=0 && y2<m && cmp(a[x][y], a[x1][y1], a[x2][y2])) {
- lian(x2, y2, i, a[x][y]);
- vis[x][y]=vis[x1][y1]=vis[x2][y2]=1;
- flag=1;
- }
- }
- }
- inline void clean() {
- CC(vis, 0); flag=0;
- rep(i, n) rep(j, m) xiao(i, j);
- if(flag) rep(i, n) rep(j, m) if(vis[i][j]) a[i][j]=' ';
- }
- inline void fix() {
- int k;
- rep(j, m) {
- k=n;
- for(int i=n-1; i>=0; --i) if(a[i][j]!=' ') a[--k][j]=a[i][j];
- while(k) a[--k][j]=' ';
- }
- }
- int main() {
- read(n); read(m);
- rep(i, n) scanf("%s", a[i]);
- while(1) {
- clean(); fix();
- if(!flag) break;
- }
- rep(i, n) printf("%s\n", a[i]);
- return 0;
- }
题目描述 Description
有红(R)、绿(G)、蓝(B)、黑(A)、白(W)五种颜色的方块放在一个M*N(M,N<=50)的方框中。现要求消去同色相连大于3的所有方块。消去过程为:一次同时消去同一直线上(横、竖、斜线)同色相连大于、等于3的块。在消去过程中,同一方块可在不同方向上重复使用。方块消去后,上面的块自动下落,重复消去过程,直至不能消去为止。
输入描述 Input Description
输入文件game.in格式:第一行为M N,以下是M*N的字母矩阵。
举例:设有5*5的方框,其方块的分布如下所示:
R
R
R
A
A
W
R
A
A
W
A
W
B
A
B
W
R
B
W
W
B
B
W
W
A
输出描述 Output Description
输出文件game.out须输出消去所有可消去的方块后,剩余在方框中的方块信息。
样例输入 Sample Input
game.in:
5 5
RRRAA
WRAAW
AWBAB
WRBWW
BBWWA
样例输出 Sample Output
Game.out:
A
WRA W
AWB B
WRBWW
BBWWA
数据范围及提示 Data Size & Hint
【wikioi】1108 方块游戏(模拟)的更多相关文章
- hust 1590 - 方块游戏 数学
1590 - 方块游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/problem/show/1590 D ...
- 初涉「带权并查集」&&bzoj3376: [Usaco2004 Open]Cube Stacking 方块游戏
算是挺基础的东西 Description 约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 游戏开始后,约翰会给贝茜发出P(1≤P ...
- [Usaco2004 Open]Cube Stacking 方块游戏
题面: 约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 游戏开始后,约翰会给贝茜发出P(1≤P≤100000)个指令.指令有两种 ...
- BZOJ3376: [Usaco2004 Open]Cube Stacking 方块游戏
[传送门:BZOJ3376] 简要题意: 约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 游戏开始后,约翰会给贝茜发出P(1≤P≤100000 ...
- 洛谷P5092 [USACO2004OPEN]Cube Stacking 方块游戏 (带权并查集)
题目描述 约翰和贝茜在玩一个方块游戏.编号为 1\ldots n 1-n 的 n n ( 1 \leq n \leq 30000 1≤n≤30000 )个方块正放在地上,每个构成一个立方柱. 游戏开始 ...
- 第八讲:HTML5中canvas实现小球击打小方块游戏
源码:http://download.csdn.net/detail/liumingm900913/7469969 游戏开发流程: 1.创建画布: 将画布放在div标签里面,这样能够控制画布居中的位置 ...
- NOIP2011Mayan游戏(模拟)
Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个77 行\times 5×5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.游戏通关是指 ...
- 【ccf2017-12-2】游戏(模拟)
问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向. 游戏开始,从1号小朋 ...
- 仿苹果电脑任务栏菜单&&拼图小游戏&&模拟表单控件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- 写时复制技术(Copy-on-write)
COW技术初窥: 在Linux程序中,fork()会产生一个和父进程完全相同的子进程,但子进程在此后多会exec系统调用,出于效率考虑,linux中引入了"写时复制" ...
- ntpdate公司测试
[root@i158 ~]# ntpdate -u time.uuwatch.com 9 Jul 11:18:50 ntpdate[853]: no server suitable for synch ...
- 如何分割一个utf8字符串(保证单个汉字的完整性)
std::list<std::string> split_utf8_string(const std::string& text) { std::list<std::stri ...
- php配置文件语法
2013年12月11日 09:21:58 ; The syntax of the file is extremely simple. Whitespace and lines ; beginning ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- CUDA学习笔记(一)——CUDA编程模型
转自:http://blog.sina.com.cn/s/blog_48b9e1f90100fm56.html CUDA的代码分成两部分,一部分在host(CPU)上运行,是普通的C代码:另一部分在d ...
- Ajax案例(使用ajax进行加法运算)
此案例功能实现了一边看视频一边进行加法运算,而加法运算时页面不会刷新请求 ajax代码: <script type="text/javascript" src="j ...
- jquery easy ui 1.3.4 按钮(button)(6)
6.1.linkbutton linkbutton是将一个<a>标签包装成一个能显示图片.文字.的超链接按钮 如何给linkbutton添加一个事件? 使用JQ的方式就能给linkbutt ...
- callsession新功能版
可以getopt解析参数. 也实现了将参数用空格分隔,来传给进程. 注意string和LPSTR数据类型的转换方法: LPSTR(lpCmdLine.c_str()) #include <win ...
- hdu 1286:找新朋友(数论,欧拉函数)
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...