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

来源:互联网 发布:网站的域名和空间 编辑:程序博客网 时间:2024/04/29 16:16

 

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.

示例输入

3RYBBRBYYRYRRRBBBBBRRYRRBRBBBBRRYYBRYYRYYBRBBRBRBRYYYBYRBBRRBRYBBBBRYYYYBRBRBRYRBRYBBBBBBBYYBBRRRRRBBRBBRRBRYRRBBBRRYYYRRh 10j 1g 23YYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYBYYBBBBBYYBYYBBBBBc 2c 12g 12YYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYYYYBBBBBYYBYYBBBBBYYBYYBBBBBg 1c 120

示例输出

33622

提示

来源

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

 

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 longusing 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;}


 

原创粉丝点击