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 ...
随机推荐
- Spring数据访问1 - 数据源配置及数据库连接池的概念
无论你要选择哪种数据访问方式,首先你都需要配置好数据源引用. Spring中配置数据源的几种方式 通过在JDBC驱动程序定义的数据源: 通过JNDI查找的数据源: 连接池的数据源: 对于即将发布到生产 ...
- 一些关于Spring的随笔
Spring的IOC.AOP IOC(Inversion of Control): spring容器控制了所有的bean,不用spring以前,一个bean要依赖另一个bean就在这个bean里初始化 ...
- 初识Vivado
Vivado 设计套件包括高度集成的设计环境和新一代从系统到 IC 级的工具,这些均建立在共享的可扩展数据模型和通用调试环境基础上.这也是一个基于 AMBA AXI4 互联规范.IP-XACT IP ...
- EEPROM的存储大小
学习单片机时,常见的EEPROM如24C02的大小为2Kbit(有的也称2KB).这里的2KB到底能存储多少数据呢? 2KB中,B表示单位bit,K表示1024. 单片机编程中常用的数据类型为unsi ...
- 用户交互和if条件判断、嵌套
#a=input("提示语“)#接受的数据类型是字符串str#提示用户输入姓名 # a=input("请输入姓名") print(a) '''输出结果:请输入姓名小明 姓 ...
- regular expression matching DP
这个题目,我从前天晚上(8月6号晚上)调试到现在(8月8号16:21),太心酸了,不好好总结一下,就太对不起自己了! 这是题目: Implement regular expression matchi ...
- js数字转金额,ajax调用接口,后台返回html(完整页面),打开新窗口并写入html
一.转换成金额形式 function toMoney(num){ if(num){ if(isNaN(num)) { alert("金额中含有不能识别的字符"); return; ...
- springboot @test 使用
@RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) public class Springtest { ...
- Oracle数据库的基本使用
1.Linux安装 (略) 2.Oracle数据库监听命令: 监听状态:$lsnrctl status 启动监听:$lsnrctl start 关闭监听:$lsnrctl stop 重载监听:$l ...
- XML 解析 & 特殊字符报错
在xml文件中,有一些符号是具有特殊意义的,如果直接使用会导致xml解析报错,为了避免错误,我们需要将特殊的字符使用其对应的转义实体进行操作.这些字符如下 < == < > = ...