博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Another Ball Killer
阅读量:6656 次
发布时间:2019-06-25

本文共 8042 字,大约阅读时间需要 26 分钟。

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit     

Description

Contestants often wonder what jury members do during a contest. Someone thinks that they spend all the contest fixing bugs in tests. Others say that the jury members watch the contest excitedly and even bet on who will win. However, in reality, the jury members prefer to play computer games, giving a complete control of the contest to heartless machines.
Another Ball Killer is one of the favorite games of the jury. Its rules are very simple:
  1. The game is played by one person on a rectangular field of size n × m. At the initial moment, each cell of the field contains a ball of one of five colors: blue, green, red, white, or yellow.
  2. At each move, the player chooses some figure (a connected group of two or more balls of the same color; balls are called connected if their cells have a common side) and removes it from the field. After that the balls that were above the removed balls fall down. If a column without the balls appears, then all the columns on its right are shifted to the left. 
    The image below shows how the field changes after the removal of the largest figure. 
    The player is awarded k × (k − 1) points for his move, where k is the size of the removed figure, i.e. the number of balls in it.
  3. The game is finished when there are no figures left on the field. The goal is to get as many points as possible by the end of the game.
Problem illustration
Lazy jury members play Another Ball Killer using the following algorithm:
01  Choose the color of one of the balls in the field as the main color.02  While there is at least one figure:03      While there is at least one figure of a color different from the main color:04          Remove the largest figure of a color different from the main color.05      If there is a figure of the main color:06          Remove the largest figure of the main color.
If there are several ways to remove the figure in lines 04 and 06, one should choose the largest figure containing the bottommost ball (if there are several such figures, then one should choose among them the figure that contains the leftmost of such balls).
Chairman is the laziest person in the jury. He doesn't even think about which color he should choose as the main one. By pressing one key, he launches a program that calculates for every color present in the field the number of points that will be awarded if this color is chosen as the main one. Your task is to write such a program.

Input

The first line contains the dimensions of the field 
n and 
m (1 ≤ 
n
m ≤ 50). Each of the following 
n lines contains 
m letters denoting the color of the ball in the corresponding cell of the field (B for blue, G for green, R for red, W for white, and Y for yellow). The rows of the playing field are given in the order from the top row to the bottom row.

Output

Output one line for each color present in the field: first output the letter denoting the color, then a colon, a space, and the number of points the chairman of the jury will get if he chooses this color as the main one. The colors must be considered in the following order: blue, green, red, white, yellow.

Sample Input

input output
3 6WWWGBGWBGGGBGGGGBB
B: 74G: 92W: 74
1 #include
2 #include
3 4 int n,m; 5 char maps[56][56]; 6 int r[5]={
0,-1,0,1,0},c[5]={
0,0,-1,0,1}; 7 int mapfigure[56][56],s,vmap[56][56]; 8 int copymap[56][56],bottommost[56][56],leftmost[56][56],bottomm,leftm; 9 10 void serch(int a,int b) 11 { 12 int i,j; 13 if(vmap[a][b]!=0 || copymap[a][b]==0) 14 return; 15 s++;mapfigure[a][b]=s;vmap[a][b]=1; 16 if(a>bottomm) 17 bottomm=a; 18 if(b
=1;i--) 55 { 56 if(copymap[i][j]==0) 57 { 58 for(k=i-1;k>=1;k--) 59 { 60 if(copymap[k][j]!=0) 61 { 62 copymap[i][j]=copymap[k][j]; 63 copymap[k][j]=0; 64 break; 65 } 66 } 67 } 68 } 69 } 70 for(j=1;j<=m;j++) 71 { 72 if(copymap[n][j]==0) 73 { 74 for(k=j;k
=1;i--)142 {143 for(j=1;j<=m;j++)144 {145 s=0,bottomm=1,leftm=m;146 serch(i,j);147 }148 }149 int ok=0;150 for(i=1;i<=n;j++)151 {152 if(ok==1) break;153 for(j=1;j<=m;j++)154 {155 if(mapfigure[i][j]>1)156 {157 ok=1;158 break;159 }160 }161 }162 if(ok==0)163 break;164 165 while(1)166 {167 168 memset(vmap,0,sizeof(vmap));169 memset(bottommost,0,sizeof(bottommost));170 memset(leftmost,0,sizeof(leftmost));171 for(i=n;i>=1;i--)172 {173 for(j=1;j<=m;j++)174 {175 s=0,bottomm=1,leftm=m;176 serch(i,j);177 }178 }179 int largestfigure=0,lagi,lagj;180 for(i=1;i<=n;i++)181 {182 for(j=1;j<=m;j++)183 {184 if(copymap[i][j]!=maincolor)185 {186 if(mapfigure[i][j]>largestfigure)187 {188 largestfigure=mapfigure[i][j];189 lagi=i,lagj=j;190 }191 else if(mapfigure[i][j]==largestfigure && bottommost[i][j]>bottommost[lagi][lagj])192 {193 largestfigure=mapfigure[i][j];194 lagi=i,lagj=j;195 }196 else if(mapfigure[i][j]==largestfigure && bottommost[i][j]==bottommost[lagi][lagj] && leftmost[i][j]
=1;i--)215 {216 for(j=1;j<=m;j++)217 {218 s=0,bottomm=1,leftm=m;219 serch(i,j);220 }221 }222 int mainfigure=0,maini,mainj;223 for(i=1;i<=n;i++)224 {225 for(j=1;j<=m;j++)226 {227 if(copymap[i][j]==maincolor && mapfigure[i][j]>mainfigure)228 {229 mainfigure=mapfigure[i][j];230 maini=i,mainj=j;231 }232 }233 }234 if(mainfigure>1)235 {236 ans=ans+mainfigure*(mainfigure-1);237 clearr(maini,mainj);238 move();239 }240 241 }242 243 244 if(maincolor==1)245 printf("B: ");246 else if(maincolor==2)247 printf("G: ");248 else if(maincolor==3)249 printf("R: ");250 else if(maincolor==4)251 printf("W: ");252 else if(maincolor==5)253 printf("Y: ");254 printf("%d\n",ans);255 }256 }257 return 0;258 }
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4651803.html

你可能感兴趣的文章
cdq分治入门学习 cogs 1752 Mokia nwerc 2015-2016 G 二维偏序
查看>>
OCCI开发环境的安装和配置
查看>>
C语言初级进阶2
查看>>
一种坠落的无知感---祭奠、致敬、反思三年生涯之曾经以为拥有全世界(二)...
查看>>
前端常用的正则表达式
查看>>
2018软工实践第一次作业
查看>>
ARM平台上蓝牙协议栈Bluez的移植使用和配置
查看>>
day02-字符及字符编码
查看>>
前端面试准备
查看>>
python爬虫-正则表达式
查看>>
开源原型设计工具Indigo Studio发布v2.0 全面支持HTML5
查看>>
jsp-EL表达式简介
查看>>
20120516分析三层中的null的处理
查看>>
入门级----黑盒测试、白盒测试、手工测试、自动化测试、探索性测试、单元测试、性能测试、数据库性能、压力测试、安全性测试、SQL注入、缓冲区溢出、环境测试...
查看>>
four rules for embracing a working team from home culture
查看>>
android 混淆配置
查看>>
ubuntu16.04安装mysql5.6
查看>>
在博客园学习成长
查看>>
前后端协调处理checkbox
查看>>
Code signing is required for product type 'Application' in SDK 'iOS 11.4'
查看>>