您的位置:首页 > 其它

HDU 5374 Tetris(模拟俄罗斯方块)

2015-08-11 17:47 387 查看
Tetris

God Wu enjoy coding some trivial games like Tetris.His Tetris is made up by 9 columns and 12 rows. 



The game will prossess as following steps

1.a random token will appear ,and its special square will be on (4,9);

2.the player can send a signal which means up,left,right and down to control the tokens;(If the operation which means is illegal,the operation will be skipped)

3.the token will fall a unit.(If the fall is illegal,we prossess the 4th step.Otherwise,we prossess the 2nd step)

4.If there is a horizontal line of nine units without gaps,the line will disappear and the tokens above it will fall.If a line will disappear, we will get a score and prossess 4th step again.If there is not a horizontal line of nine units without gaps,we go
back to 1st step 

For the sake of debugging, God Wu just created three kinds of Tetris piece. Each type of piece do the same while receiving "left", "right" and "down" operation. specificly: 

Left: the entire piece moves left one square with the special square. 

Right: the entire piece moves right one square with the special square. 

Down: the entire piece moves down one square with the special square. 

Up: rotate 90 degree clockwise 

The original direction of each square will be same as the first pattern in each picture. 

More details see the following pictures 

and following is the detail about the "up" operatrion, notice the green square is the special square: 

1. O-type 



2. I-type 



3. J-type 



God Wu begins to test the game after finishing coding, and ran a lot of data. However, he find score record is omitted. So he ask you to finish it.

 

Input

Multiple testcase. The first line is an integer T, refers the case number, followed by T case, each case containing three lines:

The first line is n, refers the number of falling pieces.

Next line is a string s(|s|<=1000), which shows the operation God Wu made from the begining of the Game to the End of the last piece stop moving.

The third line has n integers, the ith integer ai represent the type of the ith piece.(0 is for O-type, 1 is for I-type and 2 is for J-type)

 

Output

For each test case, output the case number and the score obtained from operation sequence. Format should be "Case X: Y",X is the case number and Y is the score.

 

Sample Input

1
18
waaasspdwsspppwwdddssaaassswdddsswwaasssdddddswwwwwdssaaasssdddsssddasswwaasppddddssaaasssaassswssssddssss
1 1 2 2 1 2 0 2 2 1 0 2 0 2 0 2 1 1

 

Sample Output

Case 1: 6
Hint
w -- up
a -- left
s -- down
d -- right
p -- passed(no operation)

 

Source

2015 Multi-University Training Contest 7
#include <stdio.h>
#include <string.h>

int dir_of_diamond[3][4][8] = {{{ -1, 0, -1, 1, 0, 0, 0, 1}, { -1, 0, -1, 1, 0, 0, 0, 1},
{ -1, 0, -1, 1, 0, 0, 0, 1}, { -1, 0, -1, 1, 0, 0, 0, 1}}, //fk
{{ -3, 0, -2, 0, -1, 0, 0, 0}, {0, 0, 0, 1, 0, 2, 0, 3},
{ -3, 0, -2, 0, -1, 0, 0, 0}, {0, 0, 0, 1, 0, 2, 0, 3}}, //tx
{{ -1, 0, 0, 0, 0, 1, 0, 2}, { -2, 0, -2, 1, -1, 0, 0, 0},
{ -1, 0, -1, 1, -1, 2, 0, 2}, { -2, 1, -1, 1, 0, 0, 0, 1}}, //lx
};

char op[1005];
bool pic[15][15];
int sx, sy;
int k[1005];
int ans;

bool can(int x, int y, int i, int k)
{
for(int j = 0; j < 4; j++)
{
int nx, ny;
nx = x + dir_of_diamond[i][k][j * 2];
ny = y + dir_of_diamond[i][k][j * 2 + 1];
if(nx < 1 | ny < 1 || nx > 12 || ny > 9 || pic[nx][ny])
return 0;
}
return 1;
}

void rebulid(int x, int y, int i, int k)
{
int rowsum = 0;
for(int j = 0; j < 4; j++)
{
int nx, ny;
nx = x + dir_of_diamond[i][k][j * 2];
ny = y + dir_of_diamond[i][k][j * 2 + 1];
pic[nx][ny] = 1;
}
int ai;
for(ai = 1; ai < 13; ai++)
{
bool full = 1;
for(int j = 1; j < 10; j++)
{
if(!pic[ai][j])
{
full = 0;
break;
}
}
if(full)
{
rowsum++;
for(int k = ai - 1; k >= 1; k--)
{
for(int x = 1; x < 10; x++)
{
pic[k + 1][x] = pic[k][x];
pic[k][x] = 0;
}
}
}
}
ans += rowsum;
}

int main()
{
int t;
scanf("%d", &t);
for(int i = 1; i <= t; i++)
{
int n;
sx = sy = 4;
int fs = 0;
scanf("%d", &n);
getchar();
gets(op);
for(int j = 0; j < n; j++)
scanf("%d", &k[j]);
int len = strlen(op);
int c = 0;
ans = 0;
memset(pic, 0, sizeof(pic));
for(int z = 0; z < len; z++)
{
if(c == n) break;
if(op[z] == 'w')
{
if(can(sx, sy, k[c], (fs + 1) % 4))
fs = (fs + 1) % 4;
}
else if(op[z] == 'a')
{
if(can(sx, sy - 1, k[c], fs))
sy--;
}
else if(op[z] == 's')
{
if(can(sx + 1, sy, k[c], fs))
sx++;
}
else if(op[z] == 'd')
{
if(can(sx, sy + 1, k[c], fs))
sy++;
}
if(can(sx + 1, sy, k[c], fs))
sx++;
else
{
rebulid(sx, sy, k[c], fs);
sx = sy = 4;
fs = 0;
c++;
}
}
printf("Case %d: %d\n", i, ans);
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: