题目链接: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; }

hdu 5374 Tetris(模拟)相关推荐

  1. HDU 5374 Tetris 模拟俄罗斯方块

    题目大意: 就是俄罗斯方块然后旋转, 向左右移动, 向下掉, 然后模拟求按照给定序列的操作能消除多少行... 大致思路: 就是模拟一下各个步骤的操作...按照题目说的steep1, 2, 3, 4一步 ...

  2. HDU 5374 模拟俄罗斯方块

    模拟俄罗斯方块游戏 完全按照俄罗斯方块的规则来做 注意规则即可: 1:每种图形开始出现时绿点均在(4,9)位置 2:先做变换,再下降一格 3:若碰到操作无法被执行的则不执行,依次进行下个操作 #inc ...

  3. HDU 4121 Xiangqi 模拟题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4121 首先对标题赞一个,非要叫 "Xiangqi" 而不是 "中国象棋&q ...

  4. HDU 4262 Juggler (模拟+线段树优化)

    转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove http://acm.hdu.e ...

  5. HDU 4121 Xiangqi --模拟

    题意: 给一个象棋局势,问黑棋是否死棋了,黑棋只有一个将,红棋可能有2~7个棋,分别可能是车,马,炮以及帅. 解法: 开始写法是对每个棋子,都处理处他能吃的地方,赋为-1,然后判断将能不能走到非-1的 ...

  6. hdu 5071 Chat(模拟|Splay)

    Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Sub ...

  7. HDU 4431 Mahjong(模拟题)

    题目链接 写了俩小时+把....有一种情况写的时候漏了...代码还算清晰把,想了很久才开写的. 1 #include <cstdio> 2 #include <cstring> ...

  8. HDU 4545 (模拟) 魔法串

    题目链接 Problem Description 小明和他的好朋友小西在玩一个新的游戏,由小西给出一个由小写字母构成的字符串,小明给出另一个比小西更长的字符串,也由小写字母组成,如果能通过魔法转换使小 ...

  9. hdu 5671(模拟)

    Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

最新文章

  1. 卡巴斯基:远程工具Ammyy Admin被用来盗取银行账户
  2. LeetCode 819. Most Common Word
  3. 源字符集与执行字符集
  4. objective-c 2.0编程语言,Objective-C 2.0程序设计(原书第2版) 中文PDF扫描版[15MB]
  5. Hibernate优化策略
  6. jpa mysql脚本迁移_JPA通过LOAD DATA LOCAL INFILE大批量导入数据到MySQL
  7. c 初始化char**_C/C++内存模型
  8. Leecode刷题热题HOT100(12)——整数转罗马数字
  9. fir数字滤波器设计与软件实现_基于FPGA低通滤波器的FIR的设计
  10. 点击率预估与冷启动(一)
  11. android gridview 滚动条位置,android-gridview单元格视图位置在滚动后发生...
  12. 【Coding】C++诡异问题之一
  13. Windows下C++计算代码段运行时间
  14. 网站防采集不防搜索引擎策略
  15. 随笔小杂记(一)——更改整个文件夹内的命名
  16. TeaVM的samples/benchmark范例运行办法
  17. macOS “不能安装该软件,因为当前无法从软件更新服务器获得” 解决方法
  18. 植被覆盖度的遥感估算
  19. 悼念博客专家雷霄骅七律诗一首
  20. 7-176 数列求和

热门文章

  1. 了解快照隔离和行版本控制
  2. NYMEX ACCESS电子交易系统来
  3. 用户控件事件使用delegate
  4. 谷歌翻译 google translation api
  5. CAS 乐观锁和ABA问题
  6. python——asyncio模块实现协程、异步编程(二)
  7. PyCharm设置背景颜色
  8. ubuntu 14.04.03 LTS(64bit) 安装PyCharm
  9. Anaconda安装(ubuntu 14.04.03 LTS 64bit)
  10. C++ new一个数组时,指针移动程序崩溃问题