中国海洋大学第四届朗讯杯高级组 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:
- Circles fall vertically, to fill in any holes in their column.
- 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 end of the entire input will be designated by a line with the number 0.
输出
示例输入
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;}
- 中国海洋大学第四届朗讯杯高级组 Cash Cow
- 中国海洋大学第四届朗讯杯高级组 Playing Fair with Cryptography
- 中国海洋大学第四届朗讯杯高级组 Super Phyllis
- 中国海洋大学第四届朗讯杯高级组 The Urge to Merge
- 中国海洋大学考研
- 中国海洋大学 软件工程 考研交流
- 中国海洋大学各个校区都有什么专业
- SDUT 2721 Cash Cow BFS+坑爹输入
- cash
- 第四部分:高级话题
- 第四章高级查询
- 第四章 高级查询
- 第四章:高级查询
- 第四章 高级特性
- 第四篇 高级指针
- SQL高级 第四章 高级查询
- 新视野大学英语 第四册 翻译
- 《读大学 怎么读》 第四篇
- 《UNIX环境高级编程》笔记--孤儿进程组
- 省市数据库资源
- 没事儿找事儿————gtk学习(Hello World)
- ado.net 如何读取 excel
- HDU 4800 DP
- 中国海洋大学第四届朗讯杯高级组 Cash Cow
- 主板有哪些
- arm常用指令概述
- Please use Android Tools > Fix Project Properties.
- http://acm.hdu.edu.cn/showproblem.php?pid=1874
- Linux Shell高级技巧(一)
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- 1020 电梯问题
- 初学哈希函数