The Same Game
The game named ``Same'' is a single-person game played on a 10 The Same Game |

- 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:

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.
Miguel A. Revilla
2000-02-09
simulation
#include<stdio.h>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define DBG 0
using namespace std;
int N=15,M=10,LEFT,cases=1,total,score,move;
bool erase[15][10],erase2[15][10];
char dir[4][2];
vector<string>vc;
void init(){
dir[0][0]=1,dir[1][0]=-1,dir[2][1]=1,dir[3][1]=-1;
}
bool isValid(int r,int c){return r>=0&&r<vc.size()&&c>=0&&c<vc[r].size();}
void flood(int r,int c,char tar){
int a,b;
if(erase[r][c])return;
if(DBG)printf("(flood) %d,%d %c\n",r,c,vc[r][c]);
total++;
erase[r][c]=erase2[r][c]=1;
rep(i,4){
a=r+dir[i][0],b=c+dir[i][1];
if(isValid(a,b)&&vc[a][b]==tar)
flood(a,b,tar);
}
}
void del(bool erase[][10]){
int b,c,i,rsize=vc.size();
rep(k,rsize){
i=rsize-1-k;
c=vc[i].size();
rep(j,c)
if(erase[i][c-1-j]){
//if(DBG)printf("erase %d %d\n",i,c-1-j);
vc[i].erase(vc[i].begin()+c-1-j);
if(!vc[i].size())vc.erase(vc.begin()+i);;
}
}
}
void print(){
int c;
rep(i,M){
c=M-i;
rep(j,vc.size()){
if(j>0)printf(" ");else printf(" ");
if(vc[j].size()>=c)printf("%c",vc[j][c-1]);
else printf(" ");
}
printf("\n");
}
}
bool go(){
bool er[15][10];
memset(erase,0,sizeof(erase));
total=0;
int m=0,mr,mc;
rep(i,15)rep(j,10){
if(vc.size()>i&&vc[i].size()>j
&&!erase[i][j]){
memset(erase2,0,sizeof(erase2));
if(DBG){printf("flood %d,%d %c\n",i,j,vc[i][j]);}
total=0;
flood(i,j,vc[i][j]);
if(DBG)printf("rt\n");
if(DBG)printf("totol %d\n",total);
if(total>1&&m<total)memcpy(er,erase2,sizeof(er)),m=total,mr=i,mc=j;
}
}
if(m>1){
int sc=(m-2)*(m-2);
printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points.\n",
move++,mc+1,mr+1,m,vc[mr][mc],sc);
del(er);
LEFT-=m,score+=sc;
if(DBG)printf("LFET %d\n",LEFT);
if(DBG)print();
}
return m;
}
int main(){
int n;
bool ll=0;
char chs[20];
init();
cin>>n;
rep(i,n){
LEFT=10*15,score=0;
move=1;
string s(10,'0');
vc.assign(15,s);
rep(i,10){
scanf("%s",chs);
rep(j,strlen(chs))vc[j][10-1-i]=chs[j];
}
if(ll)printf("\n");ll=1;
printf("Game %d:\n\n",cases++);
while(LEFT&&go());
if(LEFT==0)score+=1000;
printf("Final score: %d, with %d balls remaining.\n",score,LEFT);
}
}
沒有留言:
張貼留言