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;
}

hdu 5374 Tetris(模拟)的更多相关文章

  1. HDU 5374 Tetris (2015年多校比赛第7场)

    1.题目描写叙述:点击打开链接 2.解题思路:本题要求模拟俄罗斯方块游戏.然而比赛时候写了好久还是没过. 后来补题发现原来是第四步的逻辑实现写错了... 题目中要求假设一整行能够消除,那么仍然运行该步 ...

  2. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  3. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  4. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  5. HDU 2568[前进]模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...

  6. hdu 4964 恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...

  7. HDU 5965 枚举模拟 + dp(?)

    ccpc合肥站的重现...一看就觉得是dp 然后强行搞出来一个转移方程 即 根据第i-1列的需求和i-1 i-2列的枚举摆放 可以得出i列摆放的种类..加了n多if语句...最后感觉怎么都能过了..然 ...

  8. HDU 5083 Instruction --模拟

    题意:给出汇编指令,解释出编码或者给出编码,解释出汇编指令. 解法:简单模拟,按照给出的规则一步一步来就好了,主要是注意“SET”的情况,还有要输出的东西最好放到最后一起输出,中间如果一旦不对就可以及 ...

  9. HDU 1707 简单模拟 Spring-outing Decision

    Spring-outing Decision Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

随机推荐

  1. Oracle JET 起步

    Oracle JET介绍 Oracle JET是一个用于经验丰富的JavaScript开发人员构建客户端的基于JavaScript的应用程序的工具包.(抱歉本人对JavaScript绝对是从零开始) ...

  2. iOS:使用集成的支付宝SDK的支付流程

    基本步骤: 1.先与支付宝签约,获得商户的ID(partner)和账号ID(seller),这一部分主要是又公司负责: 2.下载相应的公钥私钥文件,用来给签名进行加密: 3.下载支付宝集成的SDK,网 ...

  3. CentOS7.x 通过mail命令发,使用465端口(smtps协议)发送邮件

    #创建证书mkdir -p /root/.certs/echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CE ...

  4. 常用vim命令合集

    移动命令: h:左移 l:右移 k:上移 j:下移 ^:移动到本行第一个非空白字符上 0:移动到本行第一个字符上 gg:移动到文件头 G = shift + g:移动到文件尾 %:从一个"{ ...

  5. 倍福TwinCAT(贝福Beckhoff)应用教程11.1 TwinCAT应用小程序1 如何读写数字量模拟量输入输出(DI,DO,AI,AO)

    常见的模拟量模块(还有更高端和更低端的,使用方法都一样) EL3054和EL4024(4路模拟量输入和输出模块)   常见的数字量模块(还有更高端和更低端的,使用方法都一样) EL1809和EL280 ...

  6. Python——Code Like a Pythonista: Idiomatic Python

    Code Like a Pythonista: Idiomatic Python 如果你有C++基础,那学习另一门语言会相对容易.因为C++即面向过程,又面向对象.它很底层,能像C一样访问机器:它也很 ...

  7. Linux命令常用命令

    查看主机IP ifconfig 切换目录 cd cd /home cd /path cd ../path cd 退到home目录 cd .. 退到上层目录 cd / 退到根目录  ls -l 列出数据 ...

  8. 信号处理的好书Digital Signal Processing - A Practical Guide for Engineers and Scientists

    诚心给大家推荐一本讲信号处理的好书<Digital Signal Processing - A Practical Guide for Engineers and Scientists>[ ...

  9. javacript计时

    简单的计时: var t=setTimeout("alert('5 秒!')",5000) 无限计时: var c=0 var t function timedCount() { ...

  10. c++ istream(ostream)是如何转换为bool的

    http://www.cplusplus.com/reference/ios/ios/operator_not/ http://stackoverflow.com/questions/8117566/ ...