Problem F. Tetris
Brief description:
模拟俄罗斯方块游戏。
Analysis:
Dead-do
const int N = 12, M = 9;
bool G[20][20];
bool inGrid(int x, int y){
return x >= 0 && y >= 0 && x < N && y < M;
}
struct T{
VVII p; int x, y, z;
void ww(){
int zz = z;
++zz; if (zz == p.size()) zz = 0;
ECH(it, p[zz]){
int xx = x + it->fi, yy = y + it->se;
if (!inGrid(xx, yy) || G[xx][yy]) return;
}
z = zz;
}
void aa(){
//if (y == 0) return;
--y; ECH(it, p[z]){
int xx = x + it->fi, yy = y + it->se;
if (!inGrid(xx, yy) || G[xx][yy]){
++y;
return;
}
}
}
void dd(){
//if (y != M-1) return;
++y; ECH(it, p[z]){
int xx = x + it->fi, yy = y + it->se;
if (!inGrid(xx, yy) || G[xx][yy]){
--y;
return;
}
}
}
bool ss(){
//cout << "!?" << endl;
++x; ECH(it, p[z]){
int xx = x + it->fi, yy = y + it->se;
if (!inGrid(xx, yy) || G[xx][yy]){
--x;
// cout << "aaa" << endl;
return false;
}
}
//cout << "aaa" << endl;
return true;
}
void go(char c){
if (c == 'w') ww();
else if (c == 'a') aa();
else if (c == 'd') dd();
else if (c == 's') ss();
}
int eli(){
//cout << "1" << endl;
ECH(it, p[z]){
int xx = x + it->fi, yy = y + it->se;
//cout << z << " " << it->fi << " " << it->se << endl;
//cout << xx << " " << yy << endl;
G[xx][yy] = true;
}
//cout << "2" << endl;
int z = 0; x = N-1; do{
int j; REP_N(j, M) if (!G[x][j]) break;
if (j == M){
++z; DWN_1(i, x, 1) REP(j, M) G[i][j] = G[i-1][j];
REP(j, M) G[0][j] = 0;
}
else{
--x;
}
} while (x >= 0);
//cout << "3" << endl;
return z;
}
void init(int t){
x = 3, y = 3; z = 0; p.clear(); VII pp;
if (t == 0){
pp.PB(MP(0, 0));
pp.PB(MP(0, 1));
pp.PB(MP(-1, 0));
pp.PB(MP(-1, 1));
p.PB(pp);
}
else if (t == 1){
pp.PB(MP(0, 0));
pp.PB(MP(-1, 0));
pp.PB(MP(-2, 0));
pp.PB(MP(-3, 0));
p.PB(pp);
pp.clear();
pp.PB(MP(0, 0));
pp.PB(MP(0, 1));
pp.PB(MP(0, 2));
pp.PB(MP(0, 3));
p.PB(pp);
}
else{
pp.PB(MP(0, 0));
pp.PB(MP(-1, 0));
pp.PB(MP(0, 1));
pp.PB(MP(0, 2));
p.PB(pp);
pp.clear();
pp.PB(MP(0, 0));
pp.PB(MP(-1, 0));
pp.PB(MP(-2, 0));
pp.PB(MP(-2, 1));
p.PB(pp);
pp.clear();
pp.PB(MP(-1, 0));
pp.PB(MP(-1, 1));
pp.PB(MP(-1, 2));
pp.PB(MP(0, 2));
p.PB(pp);
pp.clear();
pp.PB(MP(0, 0));
pp.PB(MP(0, 1));
pp.PB(MP(-1, 1));
pp.PB(MP(-2, 1));
p.PB(pp);
}
}
} T;
char cmd[1009];
int Run(){
RST(G); int n; RD(n); RS(cmd); int o = 0, s = 0; REP(i, n){
T.init(RD()); do{
if (!cmd[o]) return s;
T.go(cmd[o++]);
} while (T.ss());
s += T.eli();
/*REP(i, N){
REP(j, M){
bool bj = false;
ECH(it, T.p[T.z]){
int x = T.x + it->fi, y = T.y + it->se;
if (i == x && y == j){
cout << "x";
bj = true;
}
}
if (!bj)
cout << G[i][j];
}
cout << endl;
}
cout << endl;*/
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
Rush{
OT(Run());
}
}




Alca
Amber
Belleve Invis
Chensiting123
Edward_mj
Fotile96
Hlworld
Kuangbin
Liyaos
Lwins
LYPenny
Mato 完整版
Mikeni2006
Mzry
Nagatsuki
Neko13
Oneplus
Rukata
Seter
Sevenkplus
Sevenzero
Shirleycrow
Vfleaking
wangzhpp
Watashi
WJMZBMR
Wywcgs
XadillaX
Yangzhe
三途川玉子
About.me
Vijos
