The Same Game


Time Limit: 1000MS Memory Limit: 10000K

Description

The game named “Same” is a single person game played on a 10 \Theta 15 board. Each square contains a ball colored red (R), green (G), or blue (B). Two balls belong to the same cluster if they have the same color, and one can be reached from another by following balls of the same color in the four directions up, down, left, and right. At each step of the game, the player chooses a ball whose cluster has at least two balls and removes all balls in the cluster from the board. Then, the board is “compressed” in two steps:

1. Shift the remaining balls in each column down to fill the empty spaces. The order of the balls in each column is preserved.

2. If a column becomes empty, shift the remaining columns to the left as far as possible. The order of the columns is preserved.

For example, choosing the ball at the bottom left corner in the sub-board below causes:



The objective of the game is to remove every ball from the board, and the game is over when every ball is removed or when every cluster has only one ball. The scoring of each game is as follows. The player starts with a score of 0. When a cluster of m balls is removed, the player’s score increases by (m-2)^2 . A bonus of 1000 is given if every ball is removed at the end of the game.

You suspect that a good strategy might be to choose the ball that gives the largest possible cluster at each step, and you want to test this strategy by writing a program to simulate games played using this strategy. If there are two or more balls to choose from, the program should choose the leftmost ball giving the largest cluster. If there is still a tie, it should choose the bottommost ball of these leftmost balls.

Input

You will be given a number of games in the input. The first line of input contains a positive integer giving the number of games to follow. The initial arrangement of the balls of each game is given one row at a time, from top to bottom. Each row contains 15 characters, each of which is one of “R”, “G”, or “B”, specifying the colors of the balls in the row from left to right. A blank line precedes each game.

Output

For each game, print the game number, followed by a new line, followed by information about each move, followed by the final score. Each move should be printed in the format:

Move x at (r,c): removed b balls of color C, got s points.

where x is the move number, r and c are the row number and column number of the chosen ball, respectively. The rows are numbered from 1 to 10 from the bottom, and columns are numbered from 1 to 15 from the left. b is the number of balls in the cluster removed. C is one of “R”, “G”, or “B”, indicating the color of the balls removed. s is the score for this move. The score does not include the 1000 point bonus if all the balls are removed after the move.

The final score should be reported as follows:

Final score: s, with b balls remaining.

Insert a blank line between the output of each game. Use the plural forms “balls” and “points” even if the corresponding value is 1.

Sample Input

3

RGGBBGGRBRRGGBG

RBGRBGRBGRBGRBG

RRRRGBBBRGGRBBB

GGRGBGGBRRGGGBG

GBGGRRRRRBGGRRR

BBBBBBBBBBBBBBB

BBBBBBBBBBBBBBB

RRRRRRRRRRRRRRR

RRRRRRGGGGRRRRR

GGGGGGGGGGGGGGG

RRRRRRRRRRRRRRR

RRRRRRRRRRRRRRR

GGGGGGGGGGGGGGG

GGGGGGGGGGGGGGG

BBBBBBBBBBBBBBB

BBBBBBBBBBBBBBB

RRRRRRRRRRRRRRR

RRRRRRRRRRRRRRR

GGGGGGGGGGGGGGG

GGGGGGGGGGGGGGG

RBGRBGRBGRBGRBG

BGRBGRBGRBGRBGR

GRBGRBGRBGRBGRB

RBGRBGRBGRBGRBG

BGRBGRBGRBGRBGR

GRBGRBGRBGRBGRB

RBGRBGRBGRBGRBG

BGRBGRBGRBGRBGR

GRBGRBGRBGRBGRB

RBGRBGRBGRBGRBG

Sample Output

Game 1:

Move 1 at (4,1): removed 32 balls of color B, got 900 points.

Move 2 at (2,1): removed 39 balls of color R, got 1369 points.

Move 3 at (1,1): removed 37 balls of color G, got 1225 points.

Move 4 at (3,4): removed 11 balls of color B, got 81 points.

Move 5 at (1,1): removed 8 balls of color R, got 36 points.

Move 6 at (2,1): removed 6 balls of color G, got 16 points.

Move 7 at (1,6): removed 6 balls of color B, got 16 points.

Move 8 at (1,2): removed 5 balls of color R, got 9 points.

Move 9 at (1,2): removed 5 balls of color G, got 9 points.

Final score: 3661, with 1 balls remaining.

Game 2:

Move 1 at (1,1): removed 30 balls of color G, got 784 points.

Move 2 at (1,1): removed 30 balls of color R, got 784 points.

Move 3 at (1,1): removed 30 balls of color B, got 784 points.

Move 4 at (1,1): removed 30 balls of color G, got 784 points.

Move 5 at (1,1): removed 30 balls of color R, got 784 points.

Final score: 4920, with 0 balls remaining.

Game 3:

Final score: 0, with 150 balls remaining.

Source

East Central North America 1999

题意:在一个固定大小为10x15的矩形区域A内被RGB三种颜色的小球填满。

现在按如下步骤操作:

1. 删除区域A内最大的一片区域M(任意颜色都可以,只要其占有区域最大)

2. 删除M后,自然会出现空的位置,在M区域上方的小球自然下落;

当删除M后出现空列时,右边的列往左填充。

注意是以“列”为单位填充,非空列只能整列往空列移动。

移动后,各个小球之间的相对顺序 与 移动前一样。

3. 当区域A剩余小球数为0,或A内的最大区域为1时,游戏结束。否则返回1。

输出每一步的得分,最后输出总得分。**

简单的模拟,没有什么坑点

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
const int n = 10;
const int m = 15;
char str[15][20];
int X,Y,num,sorce,t;
int dir[][2]={{1,0},{-1,0},{0,1},{0,-1}};
bool vis[15][20];
bool Judge(int Fx,int Fy,char s)
{
if(Fx>=0&&Fx<n&&Fy>=0&&Fy<m&&str[Fx][Fy]==s)
{
return true;
}
return false;
}
int dfs(int x,int y,char s)
{
vis[x][y] = true;
int ans= 1 ;
for(int i=0;i<4;i++)
{
int Fx = x+dir[i][0];
int Fy = y+dir[i][1];
if(Judge(Fx,Fy,s)&&!vis[Fx][Fy])
{
ans += dfs(Fx,Fy,s);
}
}
return ans;
}
bool BFS()
{
memset(vis,false,sizeof(vis));
int Max= 0,ans;
for(int j=0;j<15;j++)
{
for(int i=0;i<10;i++)
{
if(!vis[i][j]&&str[i][j]!=0)
{
ans = dfs(i,j,str[i][j]);
if(ans>Max)
{
X = i;
Y = j;
Max = ans;
}
}
}
}
if(Max>=2)
{
num+=Max;
sorce+=(Max-2)*(Max-2);
printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points. \n",t++,X+1,Y+1,Max,str[X][Y],(Max-2)*(Max-2));
}
return Max>=2;
}
void DFS(int x,int y,char s)
{
str[x][y] = 0;
for(int i=0;i<4;i++)
{
int Fx = x + dir[i][0];
int Fy = y + dir[i][1];
if(Judge(Fx,Fy,s))
{
DFS(Fx,Fy,s);
}
}
}
void Union()
{
char s[15][20];
bool visy[20];
memset(visy,false,sizeof(visy));
memset(s,0,sizeof(s));
for(int i=0;i<m;i++)
{
int M = 0;
for(int j=0;j<n;j++)
{
if(str[j][i]!=0)
{
s[M++][i]=str[j][i];
}
}
if(M==0)
{
visy[i]=true;
}
}
memset(str,0,sizeof(str));
int M = 0;
for(int i=0;i<m;i++)
{
if(!visy[i])
{
for(int j=0;j<n;j++)
{
str[j][M]=s[j][i];
}
M++;
}
}
}
int main()
{
int T;
int z = 1;
scanf("%d",&T);
while(T--)
{
for(int i=9;i>=0;i--)
{
scanf("%s",str[i]);
}
if(z!=1)
{
printf("\n");
}
printf("Game %d:\n\n",z++);
t=1,num = 0,sorce = 0;
while(BFS())
{
DFS(X,Y,str[X][Y]);
Union();
}
if(num == 150)
{
sorce+=1000;
}
printf("Final score: %d, with %d balls remaining. \n",sorce,150-num);
}
return 0;
}

The Same Game-POJ1027模拟的更多相关文章

  1. POJ1027 The Same Game

    题目来源:http://poj.org/problem?id=1027 题目大意: 题目说的就是现在蛮流行的手机小游戏popstar,求用贪心方法能得到多少分. 小球有三种颜色:R/G/B.横向.纵向 ...

  2. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  3. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  4. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  5. HTML 事件(四) 模拟事件操作

    本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4.  ...

  6. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

  7. webapp应用--模拟电子书翻页效果

    前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...

  8. javascript动画系列第一篇——模拟拖拽

    × 目录 [1]原理介绍 [2]代码实现 [3]代码优化[4]拖拽冲突[5]IE兼容 前面的话 从本文开始,介绍javascript动画系列.javascript本身是具有原生拖放功能的,但是由于兼容 ...

  9. C++ 事件驱动型银行排队模拟

    最近重拾之前半途而废的C++,恰好看到了<C++ 实现银行排队服务模拟>,但是没有实验楼的会员,看不到具体的实现,正好用来作为练习. 模拟的是银行的排队叫号系统,所有顾客以先来后到的顺序在 ...

  10. MSYS2——Windows平台下模拟linux环境的搭建

    最近从MSYS1.0迁移到了MSYS2.0,简单讲,MSYS2.0功能更强大,其环境模拟更加符合linux.虽然本身来自cygwin,但其集成了pacman软件管理工具,很有linux范,并且可以直接 ...

随机推荐

  1. 键盘事件触发的兼容tips

    在firefox中 退格键 enter del tab 这些非字符触发编码为0 然而在Safari3以下 是8

  2. 分布式缓存Memcached---开篇的话

    大数据.高并发这是最近一段时间内被IT行业提的最为火热的概念,看过<大数据时代>的同学应该不会陌生大数据的概念,尤其是对于互联网行业来说,大数据是每天都要接触的问题,简单通俗地说,每天得大 ...

  3. ios - kvo观察者示例

    首先创建Person分类 #import <Foundation/Foundation.h> @interface Person : NSObject @property (nonatom ...

  4. 一些有意思的VR设备介绍

    1.计算机(Computers) 不久以前,一个VR系统需要百万美元的超级计算机:而如今顶级的VR系统正在使用桌面便携式计算机簇,极大的降低了价格和维护成本. 2.跟踪器(Tracking) 为了能与 ...

  5. C++之路进阶codevs1242(布局)

    1242 布局 2005年USACO  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold    <:section class="hbox" ...

  6. windows批处理的介绍

    扩展名是bat(在nt/2000/xp/2003下也可以是cmd)的文件就是批处理文件. 首先批处理文件是一个文本文件,这个文件的每一行都是一条DOS命令(大部分时候就好象我们在DOS提示符下执行的命 ...

  7. paper 120:计算距离矩阵的函数的pdist和pdist2函数

    matlab中自带的计算距离矩阵的函数有两个pdist和pdist2.前者计算一个向量自身的距离矩阵,后者计算两个向量之间的距离矩阵.基本调用形式如下: D = pdist(X) D = pdist2 ...

  8. 非常强大的table根据表头排序,点击表头名称,对其内容排序

    js代码: /** * 通过表头对表列进行排序 * * @param sTableID * 要处理的表ID<table id=''> * @param iCol * 字段列id eg: 0 ...

  9. JQuery 筛选器

    1.选择对象1).基本·#id 根据给定的ID匹配一个元素.例如:$("#id")·element 根据给定的元素名匹配所有元素.例如:$("div")·.cl ...

  10. MATLAB的GUI

    % 常使用的对象查看和设置函数 % .get.set函数 ) % 获得句柄值为0的对象的属性,即显示器对象属性 plot([:]); % 绘制一幅图 title('示例'); % 增加text对象 % ...