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 方块游戏(模拟)的更多相关文章

  1. hust 1590 - 方块游戏 数学

    1590 - 方块游戏 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/problem/show/1590 D ...

  2. 初涉「带权并查集」&&bzoj3376: [Usaco2004 Open]Cube Stacking 方块游戏

    算是挺基础的东西 Description     约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱.    游戏开始后,约翰会给贝茜发出P(1≤P ...

  3. [Usaco2004 Open]Cube Stacking 方块游戏

    题面:     约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱.    游戏开始后,约翰会给贝茜发出P(1≤P≤100000)个指令.指令有两种 ...

  4. BZOJ3376: [Usaco2004 Open]Cube Stacking 方块游戏

    [传送门:BZOJ3376] 简要题意: 约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 游戏开始后,约翰会给贝茜发出P(1≤P≤100000 ...

  5. 洛谷P5092 [USACO2004OPEN]Cube Stacking 方块游戏 (带权并查集)

    题目描述 约翰和贝茜在玩一个方块游戏.编号为 1\ldots n 1-n 的 n n ( 1 \leq n \leq 30000 1≤n≤30000 )个方块正放在地上,每个构成一个立方柱. 游戏开始 ...

  6. 第八讲:HTML5中canvas实现小球击打小方块游戏

    源码:http://download.csdn.net/detail/liumingm900913/7469969 游戏开发流程: 1.创建画布: 将画布放在div标签里面,这样能够控制画布居中的位置 ...

  7. NOIP2011Mayan游戏(模拟)

    Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个77 行\times 5×5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.游戏通关是指 ...

  8. 【ccf2017-12-2】游戏(模拟)

    问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向. 游戏开始,从1号小朋 ...

  9. 仿苹果电脑任务栏菜单&&拼图小游戏&&模拟表单控件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. 【SpringMVC】SpringMVC系列4之@RequestParam 映射请求参数值

    4.@RequestParam 映射请求参数值 4.1.概述     Spring MVC 通过分析处理方法的签名,将 HTTP 请求信息绑定到处理方法的相应人参中.Spring MVC 对控制器处理 ...

  2. maven项目,导入的jar包,没有包含在pom文件中,install失败

    [INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[ ...

  3. Java for LeetCode 040 Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  4. Java for LeetCode 027 Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  5. DP:Coins(POJ 1742)

      用硬币换钱 题目大意:就是有面值为A1,A2,A3....的硬币,各有C1,C2,C3...的数量,问在钱数为m的范围内,能换多少钱?(不找零) 这题看名字就知道是完全背包,但是这题又有点不一样, ...

  6. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  7. BP神经网络模型与学习算法

    一,什么是BP "BP(Back Propagation)网络是1986年由Rumelhart和McCelland为首的科学家小组提出,是一种按误差逆传播算法训练的多层前馈网络,是目前应用最 ...

  8. caffe 无GPU 环境搭建

    root@k-Lenovo:/home/k# sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-d ...

  9. Tomcat JMX

    http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#Enabling_JMX_Remote

  10. ***阿里云linux 下怎么配置虚拟主机

    最近有个问题,本人在阿里云买了linux服务器,用wordpress做了一个博客网站www.bravetiger.cn,现在想加一个电商系统进去,假设二级域名为:shop.bravetiger.cn, ...