HDU 5374 Tetris (2015年多校比赛第7场)
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场)的更多相关文章
- HDU 5411 CRB and Puzzle (2015年多校比赛第10场)
1.题目描写叙述:pid=5411">点击打开链接 2.解题思路:本题实际是是已知一张无向图.问长度小于等于m的路径一共同拥有多少条. 能够通过建立转移矩阵利用矩阵高速幂解决.当中,转 ...
- HDU5374 Tetris (2015年多校比赛第7场)大模拟
思路: 先写好了几个函数.旋转,四种操作,推断能否够进行合并消除 题中有好几处要考虑的细节问题,如 自然下落究竟部时不进行合并的推断,而是当自然下落非法时才推断 假设消除一行,这一行上面的所以方块仅仅 ...
- HDU 5399 Too Simple (2015年多校比赛第9场)
1.题目描写叙述:点击打开链接 2.解题思路:本题分情况讨论.比赛时候真是想的太简单了.以为就是(n!)^(cnt-1). 终于无限WA. 本题有几个特殊情况须要额外推断. 首先,假设输入的时候.有某 ...
- HDU 5414 CRB and String (2015年多校比赛第10场)
1.题目描写叙述:点击打开链接 2.解题思路:本题要求推断字符串s是否能通过加入若干个字符得到字符串t. 首先,能够知道,s必须是t的一个子串(注意:不是连续子串). 第二.因为插入的新字符和它前面的 ...
- HDU 5384 Danganronpa (2015年多校比赛第8场)
1.题目描写叙述:点击打开链接 2.解题思路:本题利用字典树解决.本题要求查找全部的B[j]在A[i]中出现的总次数.那么我们能够建立一颗字典树,将全部的B[j]插入字典树,因为一个串的全部字串相当于 ...
- hdu 5374 Tetris(模拟)
pid=5374">题目链接:hdu 5374 Tetris 模拟.每次进行操作时推断操作是否合法,合法才运行,否则跳过.每次一个token落地,推断一下是否有消除整行. #inclu ...
- 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)的 ...
- hdu5379||2015多校联合第7场1011 树形统计
pid=5379">http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is ...
- 【杂题总汇】HDU多校赛第十场 Videos
[HDU2018多校赛第十场]Videos 最后一场比赛也结束了…… +HDU传送门+ ◇ 题目 <简要翻译> 有n个人以及m部电影,每个人都有一个快乐值.每场电影都有它的开始.结束时间和 ...
随机推荐
- TDictionary字典 记录 的赋值。
type TRen = record age: Integer; //把name定义成结构的属性. private Fname: string; procedure Setname(const Val ...
- TreeMap和TreeSet的区别与联系
TreeMap 和 TreeSet 是 Java Collection Framework 的两个重要成员,其中 TreeMap 是 Map 接口的常用实现类,而 TreeSet 是 Set 接口的常 ...
- Shell 括号辨识(转http://blog.csdn.net/taiyang1987912/article/details/39551385)
一.小括号,圆括号() 1.单小括号 () ①命令组.括号中的命令将会新开一个子shell顺序执行,所以括号中的变量不能够被脚本余下的部分使用.括号中多个命令之间用分号隔开,最后一个命令可以没有 ...
- 洛谷 P1014 Cantor表【蛇皮矩阵/找规律/模拟】
题目描述 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … ...
- HDU 6229 Wandering Robots(2017 沈阳区域赛 M题,结论)
题目链接 HDU 6229 题意 在一个$N * N$的格子矩阵里,有一个机器人. 格子按照行和列标号,左上角的坐标为$(0, 0)$,右下角的坐标为$(N - 1, N - 1)$ 有一个机器人, ...
- 洛谷——P2040 打开所有的灯
P2040 打开所有的灯 题目背景 pmshz在玩一个益(ruo)智(zhi)的小游戏,目的是打开九盏灯所有的灯,这样的游戏难倒了pmshz... 题目描述 这个灯很奇(fan)怪(ren),点一下就 ...
- Java多线程总结之由synchronized说开去
更新完毕,结贴,以后有新的想法再开新帖 这几天不断添加新内容,给个大概的提纲吧,方面朋友们阅读,各部分是用分割线隔开了的: synchronized与wait()/notify() JMM与synch ...
- Synchronized 实现原理
记得刚刚开始学习Java的时候,一遇到多线程情况就是synchronized.对于当时的我们来说,synchronized是如此的神奇且强大.我们赋予它一个名字"同步",也成为我们 ...
- 2016北京集训测试赛(十六)Problem C: ball
Solution 这是一道好题. 考虑球体的体积是怎么计算的: 我们令\(f_k(r)\)表示\(x\)维单位球的体积, 则 \[ f_k(1) = \int_{-1}^1 f_{k - 1}(\sq ...
- html特殊字符编码问题导致的细节问题
今天在写前端html时,一个a标签的链接地址,由于链接地址需要给后台传参数,因此带了部分url参数: 在html源码里写的连接地址是: http://域名/bidder/noticesearch?no ...