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. sun.misc.BASE64Decoder导入异常及处理思路

    Java后台保存base64图片数据 使用byte[] bytes = new BASE64Decoder().decodeBuffer(str);需要引入sun.misc.BASE64Decoder ...

  2. UVA-10603-Fill(BFS+优先队列)

    There are three jugs with a volume of a, b and c liters. (a, b, and c are positive integers not grea ...

  3. cs-Panination

    ylbtech-Unitity: cs-Panination Pager.cs IPagingOption.cs IPagedList.cs PagingOption.cs PagedList.cs ...

  4. Java Executor框架

    java.util.concurrent 包中包含灵活的线程池实现,但是更重要的是,它包含用于管理实现 Runnable 的任务的执行的整个框架,该框架称为 Executor 框架.该框架基于生产者- ...

  5. 怎样改动SharePoint管理中心的语言

    在安装了语言包之后,创建站点集的时候,就能够选择语言了. 可是SharePoint管理中心的语言没有变.这个时候.怎么才干让管理中心也使用新的语言呢? 能够依照下面方法. 首先去https://msd ...

  6. 深入理解C/C++ [Deep C (and C++)] (2)

    好.接着深入理解C/C++之旅.我在翻译第一篇的时候.自己是学到不不少东西,因此打算将这整个ppt翻译完成. 请看以下的代码片段: #include <stdio.h> void foo( ...

  7. Joomla详细安装图文教程

    Joomla 详细安装图文教程 第一步,配置网站信息 配置数据库:这里我选择MySQLi,可以根据自己的选择         安装-- 安装完成!

  8. Property with &#39;retain (or strong)&#39; attribute must be of object type

    AFNetworking 2.0 当Deployment Target 低于6.0时,AFURLConnectionOperation.h,AFURLSessionManager.h @propert ...

  9. linux入门基础——linux网络配置

    linux网络配置 以太网连接 在linux中,以太网接口被命名为:eth0.eth1等.0.1代表网卡编号 通过lspci命令能够查看网卡硬件信息(假设是usb网卡,则须要使用lsusb命令) 命令 ...

  10. curl Error : maximum redirects followed , 这种问题的一种原因 .

    在stack overflow 上查找到有些网站上需要返回一些cookie的,所以当我们curl当相应的网站时,必须要将返回的cookie保存起来. $cookie = tempnam (" ...