Time Limit: 1000MS    Memory limit: 65536K

题目描述

Years before Candy Crush became the wildly popular game that may lead developer Saga to a multi-billion dollar IPO, there was an online game named Cash Cow, which remains part of the Webkinz platform.

This single-player game has a board with 12 rows and 10 columns, as shown in Figure 1. We label the rows 1 through 12, starting at the bottom, and the columns a through j, starting at the left. Each grid location can either have a colored circle or be empty. (We use uppercase characters to denote distinct colors, for example with B=blue, R=red, and Y=yellow.) On each turn, the player clicks on a circle. The computer determines the largest "cluster" to which that circle belongs, where a cluster is defined to include the initial circle, any of its immediate horizontal and vertical neighbors with matching color, those circles\' neighbors with matching colors, and so forth. For example, if a user were to click on the blue circle at cell (h10) in Figure 1, its cluster consists of those cells shown with empty circles in Figure 2.
              

Processing a click on cell h10.

The player\'s turn is processed as follows. If the indicated grid cell belongs to a cluster of only one or two circles (or if there is no circle at that cell), the turn is wasted. Otherwise, with a cluster of 3 or more circles, all circles in the cluster are removed from the board. Remaining circles are then compacted as follows:

  1. Circles fall vertically, to fill in any holes in their column.
  2. If one or more columns have become empty, all remaining columns slide leftward (with each nonempty column remaining intact), such that they are packed against the left edge of the board.

For example, Figure 3 shows the board after the cluster of Figure 2 was removed after the click on (h10).

As another example, Figure 4 below, portrays the processing of a subsequent click on cell (j1). During that turn, column (e) becomes empty, and the resulting columns (f) through (j) slide to become columns (e) through (i), respectively. Figure 5 provides one further example in which several columns are compacted.
                      
                            

输入

The input will consist of multiple games, each played with a new board. For each game, the input begins with a number T that denotes the number of turns that the player will be making, with 1 ≤ T ≤ 20. Following that will be an initial board configuration, which always has 12 rows and 10 columns per row, with uppercase letters used to denote distinct colors. There will never be empty cells within the initial board. Following the presentation of the initial board will be T additional lines of input, each designating a cell of the grid; we rely on the coordinate system illustrated in the above figures, with a lowercase letter, from a to j, denoting a column and a number from 1 to 12 that denotes a row. We note that if a player clicks on a grid cell that does not currently have any circle, that turn is simply wasted.

The end of the entire input will be designated by a line with the number 0.

输出

For each game, output a single line designating the the number of circles that remain on the board after all of the player\'s turns are processed.

示例输入

3
RYBBRBYYRY
RRRBBBBBRR
YRRBRBBBBR
RYYBRYYRYY
BRBBRBRBRY
YYBYRBBRRB
RYBBBBRYYY
YBRBRBRYRB
RYBBBBBBBY
YBBRRRRRBB
RBBRRBRYRR
BBBRRYYYRR
h 10
j 1
g 2
3
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYBYYBBBBB
YYBYYBBBBB
c 2
c 12
g 1
2
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYYYYBBBBB
YYBYYBBBBB
YYBYYBBBBB
g 1
c 12
0

示例输出

33
62
2

提示

来源

中国海洋大学第四届朗讯杯高级组

http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2721&cid=1203

这个题不难,用dfs标记周围同色的方块。然后需要消去这些方块,也就是上面的方块需要落下来,如果某列为空,那么需要右面非空的几列移动过来。

题目里面的坐标跟c++的二维数组不一样这点需要注意。

仔细一点就行了。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <climits>
#define MAXN 25
#define INF 2139062143
#define inf -2139062144
#define ll long long
using namespace std;
char grid[MAXN][MAXN];
bool vis[MAXN][MAXN];
int cnt;
bool ok;
bool num[MAXN];
int M[4][2]= {{1,0},{0,1},{0,-1},{-1,0}};
void dfs(int x,int y,char c)
{if(x<1||y<1||x>12||y>10) return ;if(c!=grid[x][y]) return ;if(vis[x][y]) return ;cnt++;vis[x][y]=true;for(int i=0; i<4; ++i)dfs(x+M[i][0],y+M[i][1],c);
}
void move(int a,int b)
{for(int i=1; i<=12; ++i)grid[i][a]=grid[i][b];
}
void fillx(int x)
{for(int i=1; i<=12; ++i)grid[i][x]='x';
}
int count()
{int ans=0;for(int i=1; i<=12; ++i)for(int j=1; j<=10; ++j)if(grid[i][j]!='x')ans++;return ans;
}
bool check(int x)
{for(int i=1; i<=12; ++i)if(grid[i][x]!='x') return false;return true;
}
int main()
{int t;while(scanf("%d",&t)&&t){for(int i=12; i>=1; --i)scanf("%s",grid[i]+1);memset(num,1,sizeof(num));while(t--){memset(vis,0,sizeof(vis));char tt[4];int sx,sy;scanf("%s%d",tt,&sy);sx=tt[0]-'a'+1;cnt=0;dfs(sy,sx,grid[sy][sx]);if(cnt<3) continue;for(int i=1; i<=10; ++i){int len=1;for(int j=1; j<=12; ++j){if(!vis[j][i])grid[len++][i]=grid[j][i];}for(int j=len; j<=12; ++j)grid[j][i]='x';}for(int i=1; i<=10; ++i)if(check(i)) num[i]=false;for(int i=1; i<=10; ++i)if(!num[i]){int now=i;for(int j=i+1; j<=10; ++j)if(!num[now]&&num[j]){move(now,j);num[now]=num[j];now++;num[j]=0;}for(int j=now; j<=10; ++j)fillx(j);}}int ans=count();printf("%d\n",ans);}return 0;
}

中国海洋大学第四届朗讯杯高级组 Cash Cow相关推荐

  1. 中国海洋大学第四届朗讯杯高级组 Playing Fair with Cryptography

    Playing Fair with Cryptography Time Limit: 1000MS    Memory limit: 65536K 题目描述 Encryption is the pro ...

  2. 中国海洋大学第四届朗讯杯高级组 The Urge to Merge

    The Urge to Merge Time Limit: 1000MS Memory limit: 65536K 题目描述 The Acme Consulting Group has sent yo ...

  3. 中国海洋大学第四届朗讯杯高级组 I Cuckoo for Hashing

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2719&cid=1203 题意 :意思就是哈希来的,具体大意就是说有两个哈希表,然后有这样 ...

  4. 中国海洋大学第四届朗讯杯高级组 A 2718 Rocky(模拟)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718 题意:优先直走,右 左 后.... ...

  5. 多项式求和(中国海洋大学第三届“朗讯杯”编程比赛高级组试题)

    Problem Description 多项式描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 -- 先请你求出多项式前n项的和. Input 第一行输入一个数T代表测试数据 ...

  6. 中国海洋大学c语言题库,2014级中国海洋大学C语言上机题库与答案.docx

    2014级中国海洋大学C语言上机题库与答案 2014中国海洋大学C语言上机考试题库以及答案(20套)编写函数long fun(long x),它的功能是:将长整型参数x中每一位上为偶数的数依次取出,构 ...

  7. 阿尔卡特-朗讯合并背后的中国威胁

    华尔街日报中文网络版报道,法国一家一流电讯设备制造商日前传出要与其长期以来的美国竞争对手合并的消息,而促使该公司考虑这宗交易的正是来自中国企业的日甚一日的威胁. 总部位于巴黎的阿尔卡特公司(Alcat ...

  8. 卓望控股公司CEO谢峰:让卓望成为朗讯

    卓望专门为移动梦网打造数据业务管理平台,这个市场有百亿之大,目前只有卓望公司一家在做 卓望领导层力排众议,提出一个拿公司10%的估值作为股份向全体员工发放期权的计划 ,为上市融资排除了最后障碍 谢峰, ...

  9. 2021年中国海洋大学计算机及电子信息考研成绩分析

    考研时间跨度: 海大计算机考研老哥qq:1151039635 初试时间: 2020年9月16发布海大招生专业目录 网上报名时间为2020年10月10日至10月31日,每天9:00-22:00. 网上预 ...

最新文章

  1. NS2源码图示---数据链路层 (转帖)
  2. 华硕笔记本:Ubuntu 18.04安装Nvidia驱动
  3. Socket常用语法与socketserver实例
  4. inurl news.php id,news.php
  5. 微课|中学生可以这样学Python(例11.4):tkinter版图片查看器
  6. 求生之路2联机服务器没有响应,求生之路2联机卡,为什么求生之路2联机进不去...
  7. iOS 自定义视频播放器
  8. 政府会计制度——行政事业单位会计科目和报表(2019年1月1日施行)
  9. vbs实现软件自动登录(以谷歌浏览器打开网站并登陆为例)
  10. sleuth zipkin reporter-sender 分析
  11. SAP中的贷项凭证、借项凭证
  12. WebView 拦截广告 简单实现
  13. fmc接口定义_FMC接口说明
  14. 运用java爬虫和python做词云图
  15. Android适配器作用
  16. 斯坦福大学开放课程:编程方法.02/第二课练习:karel 跳墙
  17. 第十八篇:针对2022年网络系统管理赛项国赛样题的分析与思考
  18. [ZZ]浅谈中国B2C珍珑棋局
  19. 合宙ESP32C3上手使用
  20. 自定义微信小程序底部导航栏

热门文章

  1. CSP Darknet53
  2. 【六一为孩子建模吧】沐风老师3DMAX建模雕刻插件SculptTool使用教程
  3. 上交计算机考研录取分数线,上海交通大学研究生录取分数线
  4. UMOUNT NAS报错No space left on device和was not found in /proc/mounts
  5. IDC报告第一名,工业质检就是这么飒!
  6. 用计算机设计电路图,基于51单片机的计算器设计(含电路图,程序)
  7. jenkins构建python代码_Jenkins+Python完整版
  8. oracle转trs,ORACLE常规恢复之应用数据文件丢失
  9. 部署到Linux服务器系列教材- 阿里云 - 服务器选择
  10. Mac图片去水印软件Teorex Inpaint值得推荐的五大理由