hdu 5374 Tetris(模拟)
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(模拟)的更多相关文章
- HDU 5374 Tetris (2015年多校比赛第7场)
1.题目描写叙述:点击打开链接 2.解题思路:本题要求模拟俄罗斯方块游戏.然而比赛时候写了好久还是没过. 后来补题发现原来是第四步的逻辑实现写错了... 题目中要求假设一整行能够消除,那么仍然运行该步 ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
- HDU 2568[前进]模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...
- hdu 4964 恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...
- HDU 5965 枚举模拟 + dp(?)
ccpc合肥站的重现...一看就觉得是dp 然后强行搞出来一个转移方程 即 根据第i-1列的需求和i-1 i-2列的枚举摆放 可以得出i列摆放的种类..加了n多if语句...最后感觉怎么都能过了..然 ...
- HDU 5083 Instruction --模拟
题意:给出汇编指令,解释出编码或者给出编码,解释出汇编指令. 解法:简单模拟,按照给出的规则一步一步来就好了,主要是注意“SET”的情况,还有要输出的东西最好放到最后一起输出,中间如果一旦不对就可以及 ...
- HDU 1707 简单模拟 Spring-outing Decision
Spring-outing Decision Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
随机推荐
- POJ 3020 Antenna Placement 最大匹配
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 3182 ...
- MySQL5.6 怎样优化慢查询的SQL语句 -- SQL优化
上篇:MySQL5.6 怎样优化慢查询的SQL语句 -- 慢日志介绍 在实际的日志分析中,通常慢日志的log数量不少,同一时候同样的查询被记录的条数也会非常多.这里就须要怎样从慢日志查询中找到最有问题 ...
- ClassNotFoundException和 NoClassDefFoundError区别验证
首先NoClassDefFoundError是一个错误,而ClassNotFoundException是一个异常 NoClassDefFoundError产生的原因: 如果JVM或者Classload ...
- kubelet分析
kubelet是k8s中节点上运行的管理工具,它负责接受api-server发送的调度请求,在Node上创建管理pod,并且向api-server同步节点的状态.这篇文章主要讲讲kubelet组件如何 ...
- JMS-activeMq发布订阅模式(非持久订阅)
Publisher的代码: import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Deli ...
- Extjs grid 遍历store
var projectMemberGrid = Ext.getCmp("projectMemberGrid"); var selFuns = []; projectMemberGr ...
- Crontab命令--Linux
Crontab命令--定时任务 命令格式 Example:
- POJ1037 A decorative fence 【动态规划】
A decorative fence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6489 Accepted: 236 ...
- C-类型转换(陷阱)
getchar() 返回值为int类型 1.自动类型转换(运算符两边变量类型不同时) 1).两个变量类型自动转换成一样的类型(会根据参数类型自动转换, 而不是直接位转换), 且运算结果也是转换后的类型 ...
- RabbitMQ消息队基本概念
RabbitMQ简介 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计.消息中间件主要用于组件之间的 ...