pid=5374">题目链接:hdu 5374 Tetris

模拟。每次进行操作时推断操作是否合法,合法才运行,否则跳过。每次一个token落地,推断一下是否有消除整行。

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; /******* Token **********/
const int C[3] = {1, 2, 4};
const int T[3][4][4][2] = {
{{{0, 0}, {0, 1}, {1, 0}, {1, 1}}, {}, {}, {}},
{{{0, 0}, {0, 1}, {0, 2}, {0, 3}}, {{0, 0}, {1, 0}, {2, 0}, {3, 0}}, {}, {}},
{{{0, 0}, {0, 1}, {1, 0}, {2, 0}}, {{0, 0}, {0, 1}, {0, 2}, {1, 2}}, {{0, 1}, {1, 1}, {2, 0}, {2, 1}}, {{0, 0}, {1, 0}, {1, 1}, {1, 2}}}
}; void put (const int a[4][2]) {
int g[4][4];
memset(g, 0, sizeof(g)); for (int i = 0; i < 4; i++)
g[a[i][0]][a[i][1]] = 1; for (int i = 3; i >= 0; i--) {
for (int j = 0; j < 4; j++)
printf("%c", g[j][i] ? '#' : '.');
printf("\n");
}
printf("\n");
}
/************************/ const int maxn = 1005; int N, M, P, B[maxn], G[15][15];
char order[maxn]; bool judge (int x, int y, const int t[4][2]) {
for (int i = 0; i < 4; i++) {
int p = x + t[i][0];
int q = y + t[i][1];
if (G[p][q])
return false;
}
return true;
} void tag (int x, int y, const int t[4][2]) {
for (int i = 0; i < 4; i++) {
int p = x + t[i][0];
int q = y + t[i][1];
G[p][q] = 1;
}
} void play(int t) {
int x = 4, y = 9, c = 0;
while (P < M) {
if (order[P] == 'w') {
if (judge(x, y, T[t][(c + 1) % C[t]]))
c = (c + 1) % C[t];
} else if (order[P] == 'a') {
if (judge(x - 1, y, T[t][c]))
x = x - 1;
} else if (order[P] == 's') {
if (judge(x, y - 1, T[t][c]))
y = y - 1;
} else if (order[P] == 'd') {
if (judge(x + 1, y, T[t][c]))
x = x + 1;
}
P++; if (!judge(x, y - 1, T[t][c]))
break;
y = y - 1;
}
tag(x, y, T[t][c]);
} int remove () {
int ret = 0;
for (int j = 1; j <= 9; j++) {
bool flag = true;
for (int i = 1; i <= 9; i++) {
if (G[i][j] == 0) {
flag = false;
break;
}
} if (flag) {
ret++;
for (int x = j; x < 12; x++) {
for (int i = 1; i <= 9; i++)
G[i][x] = G[i][x+1];
}
j--;
}
}
return ret;
} int solve () {
scanf("%d%s", &N, order);
P = 0;
M = strlen(order); memset(G, 0, sizeof(G));
for (int i = 0; i < 15; i++)
G[i][0] = G[0][i] = G[10][i] = -1; int ret = 0, t;
for (int i = 1; i <= N; i++) {
scanf("%d", &t);
play(t);
ret += remove();
}
return ret;
} int main () {
int cas;
scanf("%d", &cas);
for (int kcas = 1; kcas <= cas; kcas++) {
printf("Case %d: %d\n", kcas, solve ());
}
return 0;
}

最新文章

  1. Python之路【第二十一篇】Django ORM详解
  2. JavaScript的学习3
  3. Java读取mat文件
  4. 出现 could not open jvm.cfg 的解决办法
  5. DOCTYPE与浏览器模式详解(标准模式&amp;混杂模式)
  6. shadowgun的飘扬旗帜shader
  7. 2015第10周日CSS—3
  8. POJ 2892 Tunnel Warfare (SBT + stack)
  9. java 线程方法join的简单总结
  10. C# 插入、删除Excel分页符
  11. nodemon 热更新
  12. ES6走一波 数组的扩展
  13. CF1139D Steps to One(DP,莫比乌斯反演,质因数分解)
  14. release git tag easy use
  15. python中常用的模块二
  16. SQL-16 统计出当前各个title类型对应的员工当前薪水对应的平均工资。结果给出title以及平均工资avg。
  17. vistual studio 去除 git 源代码 绑定
  18. 48. Rotate Image(旋转矩阵)
  19. JS代码大全(都是网上看到自己整理的)
  20. xampp 中 mysql的相关配置

热门文章

  1. Coherence的NameService
  2. ylbtech-LanguageSamples-ComInteropPart2(COM 互操作第二部分)
  3. 深入理解AMD和RequireJS!
  4. go 中goroutine 的使用
  5. Rails generate的时候不生成assets和test
  6. 香蕉派 Banana pi BPI-M1+ 双核开源单板计算机. 板载WIFI
  7. FileZilla_Server如何配置
  8. web 前端 常见操作 将时间戳转成日期格式 字符串截取 使用mui制作选项卡
  9. hdu1863 畅通project(判定最小生成树)
  10. 关于窗体跟随与 PointToScreen