CodeForces - 750D New Year and Fireworks
因为 烟花的最大范围是各个方向150格
所以 最大的空间应该是 300*300
BFS和DFS均可
模拟每一个烟花爆炸的过程 但是要注意 需要一个数组来排重
在某一个爆炸点 如果爆炸的方向 和爆炸的层数是相同的 那么就不再讨论这个爆炸点
因此 这个排重数组需要记录的信息: x, y, dir, step
以下是BFS代码
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue> using namespace std; int n, t[], cnt = ;
int sky[][];
bool mark[][][][];
int d[][] = { {, }, {, }, {, }, {-, }, {-, }, {-, -}, {, -}, {, -} }; struct Node
{
int x, y;
int dir, step;
};
void bfs(int x, int y)
{
Node start;
start.x = x;
start.y = y;
start.dir = ;
start.step = ;
queue<Node> que;
int nx, ny;
que.push(start);
mark[x][y][start.step][start.dir] = ;//一定要 否则内存超 数组去重
while (!que.empty())
{
Node crt = que.front();
que.pop();
nx = crt.x;
ny = crt.y;
for (int i = ; i < t[crt.step]; i++)
{
nx += d[crt.dir][];
ny += d[crt.dir][];
// mark[nx][ny][crt.dir][crt.step] = 1;
if (!sky[nx][ny])
{
cnt++;
sky[nx][ny] = ;
}
}
if (crt.step == n-) continue;
Node next;
next.x = nx;
next.y = ny;
next.step = crt.step+;
next.dir = (crt.dir+)%;
if (!mark[nx][ny][next.dir][next.step])
{
mark[nx][ny][next.dir][next.step] = ;//注意去重数组的位置
que.push(next);
}
next.dir = (crt.dir+)%;
if (!mark[nx][ny][next.dir][next.step])
{
mark[nx][ny][next.dir][next.step] = ;
que.push(next);
}
}
return ;
} int main()
{
freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int i = ; i < n; i++)
{
scanf("%d", &t[i]);
}
memset(sky, , sizeof(sky));
memset(mark, , sizeof(mark));
cnt = ;
bfs(, );
printf("%d\n", cnt);
return ;
}
CodeForces - 750D New Year and Fireworks的更多相关文章
- codeforces 750D New Year and Fireworks【DFS】
题意:烟花绽放时分为n层,每层会前进ti格,当进入下一层是向左右45°分开前进. 问在网格中,有多少网格至少被烟花经过一次? 题解:最多30层,每层最多前进5格,烟花的活动半径最大为150,每一层的方 ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- Codeforces Round #219 (Div. 2) E. Watching Fireworks is Fun
http://codeforces.com/contest/373/problem/E E. Watching Fireworks is Fun time limit per test 4 secon ...
- Codefroces 750D:New Year and Fireworks(BFS)
http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...
- Codeforces Round #219 (Div. 1) C. Watching Fireworks is Fun
C. Watching Fireworks is Fun time limit per test 4 seconds memory limit per test 256 megabytes input ...
- C. Watching Fireworks is Fun(Codeforces 372C)
C. Watching Fireworks is Fun time limit per test 4 seconds memory limit per test 256 megabytes input ...
- 【简洁易懂】CF372C Watching Fireworks is Fun dp + 单调队列优化 dp优化 ACM codeforces
题目大意 一条街道有$n$个区域. 从左到右编号为$1$到$n$. 相邻区域之间的距离为$1$. 在节日期间,有$m$次烟花要燃放. 第$i$次烟花燃放区域为$a_i$ ,幸福属性为$b_i$,时间为 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- mysql索引原理及创建与查询
索引介绍 一:为什么要有索引 索引是用来优化查询效率(速度)的 没有索引的话,对于大数据的表,就只能每次都遍历一遍,数据量越大,耗时越多有索引的话,可以提升好几个数量级的速度 一般的应用系统,读写比例 ...
- 【学习笔记】C++ cout 输出小数点后指定位数
在C中我们可以使用 printf("%.2lf",a);但在C++中是没有格式操作符的,该如何操作: C++使用setprecision()函数,同时必须包含头文件iomanip, ...
- Android Studio3.0 Error:Execution failed for task ':app:javaPreCompileDebug' 错误
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be expli ...
- android 防止bitmap 内存溢出
在android开发过程中经常会处理网络图片发送内存溢出,那么怎么解决这种问题? 思路: 下载到本地 通过网络获取和文件下载存放到手机中目录 代码: // 获取网络 public InputStrea ...
- express搭建平台
1.nodeJs的安装(npm的安装) nodejs官方下载地址:https://nodejs.org 2.express的安装( $ npm install -g express #全局安装expr ...
- apache配置多域名
环境:mac,其他环境也可做参考 hosts配置 eg:sudo vim /etc/hosts 127.0.0.1 www.testphalcon.com apache配置 找到apache对应安装目 ...
- IOS动画之抖动
-(void)shakeView:(UIView*)viewToShake { CGFloat t =2.0; CGAffineTransform translateRight =CGAffineT ...
- 关于maven source1.5报错
是因为maven 默认是1.5编译的 <build>//加上这个配置,把编译给改掉试试 <pluginManagement> <plugins> <plugi ...
- js Math 对象
Math 对象方法 方法 描述 abs(x) 返回数的绝对值. acos(x) 返回数的反余弦值. asin(x) 返回数的反正弦值. atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值 ...
- iview modal 点击打开窗口,打开前先销毁里面的内容再打开
<Modal v-model="addSubOrgModal" @on-cancel="addSubOrgCancel" @on-visible-chan ...