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 ...
随机推荐
- 阿里Canal框架(数据同步中间件)初步实践
最近在工作中需要处理一些大数据量同步的场景,正好运用到了canal这款数据库中间件,因此特意花了点时间来进行该中间件的的学习和总结. 背景介绍 早期,阿里巴巴B2B公司因为存在杭州和美国双机房部署,存 ...
- RPC之远程过程调用
一. 简介 将一个函数运行在远程计算机上并且等待获取那里的结果,这个称作远程过程调用(Remote Procedure Call)或者 RPC. RPC是一个计算机通信协议. 1. 类比: 将计算机服 ...
- 关于Java虚拟机
先占个坑,可以参考以下两篇文档来进行初步的学习 http://www.cnblogs.com/fingerboy/p/5456371.html http://www.importnew.com/244 ...
- ubuntu下安装apcu扩展
apcu前身是apc,apc分为系统缓存和用户缓存 1.系统缓存是指PHP执行时增加缓存,减少PHP文件的反复检查和编译,从而达到系统加速的目的. 2.用户缓存是指,PHP代码中将数据写入缓存,是用户 ...
- Selenium私房菜系列--总章
前言 在这段期间,我一直在找关于服务器的端测试方案,自动化工具等等,无意间我发现了Selenium这个工具.在试用一段时间后,觉得Selenium确实是一个很不错的Web测试工具.在和强大的QTP比较 ...
- nginx 安全配置文档
1.配置文档中有多处明确写出了nginx的配置文件路径,该路径是测试环境中的路径,线上系统的nginx配置文件与文档中所写的路径可能不一样,在进行相关配置时,应以线上配置文件的实际路径为准. 线上系统 ...
- jquery命名冲突
nodeName是jquery的关键字
- 暑假集训 || 2-SAT
推荐论文:https://blog.csdn.net/zixiaqian/article/details/4492926 2-SAT问题是2判定性问题,给出n个集合,每个集合中有两个元素,两个元素之一 ...
- 错误的语法:"create view必须是批处理中仅有的语句"
编写脚本提示: 错误的语法:"create view必须是批处理中仅有的语句" FROM sys.views WHERE name = 'v_CS_UserRoleNames' ) ...
- github下拉刷新与上拉加载地址
https://github.com/chrisbanes/Android-PullToRefresh