1.题目描写叙述:点击打开链接

2.解题思路:本题要求模拟俄罗斯方块游戏。然而比赛时候写了好久还是没过。

后来补题发现原来是第四步的逻辑实现写错了。。。

题目中要求假设一整行能够消除,那么仍然运行该步。否则才回到第一步。可是我的代码却是不论能否够消除,都回到第一步。。

。补题时候还发现一个地方我的理解出错了。。

(可能是我脑洞真的有点大)。题目中说假设一整行能够消除,那么它上面的方格要下落。我的理解是下落的方格要一直降落到第一行或者某个支撑物上,最后发现依照这样写,例子都算不正确==。调试了一下别人的代码才发现是仅仅下落一个。无论它以下是否有支撑物==。或许是非常久都没玩过的原因吧,玩法都忘了。。看来模拟题还是要弄清细节才干动手。否则真是WARush。

本题的实现能够考虑使用常量数组。通过题目描写叙述能够知道一共同拥有7种不同的状态。如果我们以special square为參考,那么每一个状态相对于special square的坐标是能够唯一确定的,最好还是用dx[7][4],dy[7][4]分开表示。另一个技巧。移动或者旋转的时候仅仅须要用一个vector来存储操作后的全部坐标就可以。不必每次真的画到图上,仅仅须要画出终于的位置就可以。

3.代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<functional>
using namespace std; #define me(s) memset(s,0,sizeof(s))
#define pb push_back
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> P; const int N = 15; int dx[7][4] = { { 0, 0, 1, 1 }, { 0, 0, 0, 0 }, { 0, 1, 2, 3 },
{ 0, 0, 1, 2 }, { 0, 0, 0, 1 }, { 0, 1, 2, 2 }, { 0, 1, 1, 1 }
};
int dy[7][4] = { { 0, 1, 0, 1 }, { 0, 1, 2, 3 }, { 0, 0, 0, 0 },
{ 0, 1, 0, 0 }, { 0, 1, 2, 2 }, { 1, 1, 1, 0 }, { 0, 0, 1, 2 }
};
int first[] = { 0, 1, 3 };//每一类俄罗斯方块的初始状态的编号
int g[N][N];
int a[100000];
vector<P>pos;//用一个vector存储每次操作完的全部坐标
int sx, sy, cur;//(sx,sy)表示special square的坐标。cur表示当前的状态(0~6的某一种) void init(int id)//初始化状态
{
pos.clear();
sx = 4, sy = 9, cur = first[id];
for (int i = 0; i < 4; i++)
pos.push_back(P(sx + dx[cur][i], sy + dy[cur][i]));
} bool inside(int x, int y)
{
return x >= 1 && x <= 9 && y >= 1 && y <= 12;
} bool can_move(int dx, int dy)
{
int len = pos.size();
for (int i = 0; i < len; i++)
{
int nx = pos[i].first + dx, ny = pos[i].second + dy;
if (!inside(nx, ny) || g[nx][ny])return false;
}
return true;
} bool can_rotate(int type)
{
if (type == 1)
{
int goal = 3 - cur;
for (int i = 0; i < 4; i++)
if (!inside(sx + dx[goal][i], sy + dy[goal][i]) || g[sx + dx[goal][i]][sy + dy[goal][i]])return false;
}
else if (type == 2)
{
int goal = (cur == 6) ? 3 : cur + 1;
for (int i = 0; i < 4; i++)
if (!inside(sx + dx[goal][i], sy + dy[goal][i]) || g[sx + dx[goal][i]][sy + dy[goal][i]])return false;
}
return true;
} void move(int dx, int dy)
{
int len = pos.size();
for (int i = 0; i < len; i++)
{
int nx = pos[i].first + dx, ny = pos[i].second + dy;
pos[i] = P(nx, ny);
}
sx += dx, sy += dy;
} void rotate(int type)
{
if (!type)return;
else if (type == 1)
{
cur = 3 - cur; //更新状态
int len = pos.size();
pos.clear();
for (int i = 0; i < 4; i++)
pos.push_back(P(sx + dx[cur][i], sy + dy[cur][i]));
}
else if (type == 2)
{
cur = (cur == 6) ? 3 : cur + 1;
pos.clear();
for (int i = 0; i < 4; i++)
pos.push_back(P(sx + dx[cur][i], sy + dy[cur][i]));
}
} void draw()
{
int len = pos.size();
for (int i = 0; i < len; i++)
{
int x = pos[i].first, y = pos[i].second;
g[x][y] = 1;
}
} void operate(char op, int id)
{
if (op == 'w')
{
if (can_rotate(id))rotate(id);
}
else if (op == 'a')
{
if (can_move(-1, 0))move(-1, 0);
}
else if (op == 's')
{
if (can_move(0, -1))move(0, -1);
}
else if (op == 'd')
{
if (can_move(1, 0))move(1, 0);
}
} int can_fall()
{
int y;
for (y = 1; y <= 12; y++)
{
int ok = 1;
for (int i = 1; i <= 9; i++)
if (!g[i][y]){ ok = 0; break; }
if (ok)return y;
}
return 0;
}
int main()
{
int T;
int rnd = 0;
scanf("%d", &T);
while (T--)
{
int n;
string cmd;
scanf("%d", &n);
cin >> cmd;
me(g); me(a); pos.clear();
int len = cmd.length();
int ans = 0, p = 0;
for (int i = 0; i < n; i++)scanf("%d", &a[i]);
for (int i = 0; i < n; i++)
{
init(a[i]);
while (1)
{
if (p < len)
operate(cmd[p++], a[i]);
if (can_move(0, -1)) move(0, -1);//不能下落
else break;
}
draw();//画出终于的位置
int q, ok;
while ((q = can_fall())>0)//直到没有完整的一行时才退出
{
ans++;
for (int i = 1; i <= 9; i++)
{
g[i][q] = 0;
for (int j = q + 1; j <= 12; j++)
if (g[i][j])
g[i][j - 1] = 1, g[i][j] = 0; //仅仅下落一格。 。。 不要多想
}
}
}
printf("Case %d: %d\n", ++rnd, ans);
}
}

HDU 5374 Tetris (2015年多校比赛第7场)的更多相关文章

  1. HDU 5411 CRB and Puzzle (2015年多校比赛第10场)

    1.题目描写叙述:pid=5411">点击打开链接 2.解题思路:本题实际是是已知一张无向图.问长度小于等于m的路径一共同拥有多少条. 能够通过建立转移矩阵利用矩阵高速幂解决.当中,转 ...

  2. HDU5374 Tetris (2015年多校比赛第7场)大模拟

    思路: 先写好了几个函数.旋转,四种操作,推断能否够进行合并消除 题中有好几处要考虑的细节问题,如 自然下落究竟部时不进行合并的推断,而是当自然下落非法时才推断 假设消除一行,这一行上面的所以方块仅仅 ...

  3. HDU 5399 Too Simple (2015年多校比赛第9场)

    1.题目描写叙述:点击打开链接 2.解题思路:本题分情况讨论.比赛时候真是想的太简单了.以为就是(n!)^(cnt-1). 终于无限WA. 本题有几个特殊情况须要额外推断. 首先,假设输入的时候.有某 ...

  4. HDU 5414 CRB and String (2015年多校比赛第10场)

    1.题目描写叙述:点击打开链接 2.解题思路:本题要求推断字符串s是否能通过加入若干个字符得到字符串t. 首先,能够知道,s必须是t的一个子串(注意:不是连续子串). 第二.因为插入的新字符和它前面的 ...

  5. HDU 5384 Danganronpa (2015年多校比赛第8场)

    1.题目描写叙述:点击打开链接 2.解题思路:本题利用字典树解决.本题要求查找全部的B[j]在A[i]中出现的总次数.那么我们能够建立一颗字典树,将全部的B[j]插入字典树,因为一个串的全部字串相当于 ...

  6. hdu 5374 Tetris(模拟)

    pid=5374">题目链接:hdu 5374 Tetris 模拟.每次进行操作时推断操作是否合法,合法才运行,否则跳过.每次一个token落地,推断一下是否有消除整行. #inclu ...

  7. 2015年多校联合训练第一场OO’s Sequence(hdu5288)

    题意:给定一个长度为n的序列,规定f(l,r)是对于l,r范围内的某个数字a[i],都不能找到一个相应的j使得a[i]%a[j]=0.那么l,r内有多少个i,f(l,r)就是几. 问全部f(l,r)的 ...

  8. hdu5379||2015多校联合第7场1011 树形统计

    pid=5379">http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is ...

  9. 【杂题总汇】HDU多校赛第十场 Videos

    [HDU2018多校赛第十场]Videos 最后一场比赛也结束了…… +HDU传送门+ ◇ 题目 <简要翻译> 有n个人以及m部电影,每个人都有一个快乐值.每场电影都有它的开始.结束时间和 ...

随机推荐

  1. java编码,乱码问题详解

    一.常见的编码格式 1.ASCII 基础编码,英文和西欧字符. 用一个字节的低7位表示,一共128个. 0~13是控制字符如换行.回车.删除等,32~126是打印字符,键盘输入. 2.IOS-8859 ...

  2. bonds

    Linux--多网卡的7种Bond模式 http://www.cnblogs.com/lcword/p/5914089.html 七种网卡绑定模式详解:  http://blog.csdn.net/w ...

  3. js-Flexbox盒子布局

    这个年轻的时候,我在项目中其实很少用到: 现在老了,发现了他的好处,我就开始慢慢用到了: 但是其实我对他还是不熟悉的,很陌生,在此做个笔记,加油

  4. ZOJ 3593.One Person Game-扩展欧几里得(exgcd)

    智障了,智障了,水一水博客. 本来是个水题,但是for循环遍历那里写挫了... One Person Game Time Limit: 2 Seconds      Memory Limit: 655 ...

  5. 强连通分量(Tarjan)模板

    贴模板,备忘. 模板1: #include<iostream> #include<cstring> #include<cmath> #include<cstd ...

  6. Python环境安装与配置

    1.官网下载:https://www.python.org/选择不同的版本 2.进入运行:使用pip安装selenium 3.设置pip的环境变量 4.安装后使用pip(一个Python包管理工具)安 ...

  7. Careercup | Chapter 1

    1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...

  8. Java面试中的多线程问题

    很多核心 Java 面试题来源于多线程(Multi-Threading)和集合框架(Collections Framework),理解核心线程概念时,娴熟的实际经验是必需的.这篇文章收集了 Java ...

  9. JSP介绍与语法-java之JSP学习第一天(非原创)

    文章大纲 一.JSP 简介二.JSP 生命周期三.JSP 语法四.学习资料下载五.参考文章   一.JSP 简介 1. 什么是Java Server Pages? JSP全称Java Server P ...

  10. 关于Android方法数量限制的问题

    限制Android方法数量的原因是: Android应用以DEX文件的形式存储字节码文件,在Dalvik字节码规范里,方法引用索引method referenceindex只有16位,即65536个. ...