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. fastjson用法&Gson

    <dependency>    <groupId>com.google.code.gson</groupId>   <artifactId>gson&l ...

  2. 鸟哥的linux私房菜服务器架设篇第五章linux常用网络指令

    ifconfig主要可以手动启动观察修改网络接口的相关参数 ifdown,ifup用来启动和关闭接口,后面直接接接口名称 两部主机两点沟通:ping 两主机之间各节点分析 traceroute 查看本 ...

  3. http://blog.csdn.net/hahalzb/article/details/5889545

    http://blog.csdn.net/hahalzb/article/details/5889545

  4. float:center???

    老规矩,先上图(请忽略图中文字^V^): 乍一看感觉是对中间的图片使用了float:center;可是细致一想float属性是没有center这个值的. 那是怎么实现的呢?我一步一步拆给大家看. 1. ...

  5. [Angular] Control the dependency lookup with @Host, @Self, @SkipSelf and @Optional

    Very differently to AngularJS (v1.x), Angular now has a hierarchical dependency injector. That allow ...

  6. Django——20141014深入理解Django HttpRequest HttpResponse的类和实例

    深入理解Django HttpRequest HttpResponse的类和实例 了解META选项 了解中间件 理清所有模板传输模板变量的方式,并作出选择 Django模板系统:如何利用Django模 ...

  7. odoo8.0条形码改为js方式处理

    群里网友@上海-gavin 提供的odoo条形码处理,将原来的图片生成方式改为js处理方式. <div class="row text-center"> <div ...

  8. 【Android布局】在程序中设置android:gravity 和 android:layout_Gravity属性——位置设置偏向

    LinearLayout有两个非常相似的属性: android:gravity与android:layout_gravity. 他们的区别在于: android:gravity 属性是对该view中内 ...

  9. 数组传到后台 string[] 获取

    调试的 时候js  断点到后台 js上面也可以查看 传到后台的数据 方便查看~~

  10. 自己动手一步一步安装hadoop(含编译hadoop的native本地包)

    近期项目须要用到hadoop.边学习边应用,第一步无疑是安装hadoop.我安装的是hadoop-2.4.1.以下是具体步骤,做备忘以后查看 一.下载依赖软件 1.java hadoop官网说明仅仅支 ...