因为 烟花的最大范围是各个方向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的更多相关文章

  1. codeforces 750D New Year and Fireworks【DFS】

    题意:烟花绽放时分为n层,每层会前进ti格,当进入下一层是向左右45°分开前进. 问在网格中,有多少网格至少被烟花经过一次? 题解:最多30层,每层最多前进5格,烟花的活动半径最大为150,每一层的方 ...

  2. 【codeforces 750D】New Year and Fireworks

    time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...

  3. 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 ...

  4. Codefroces 750D:New Year and Fireworks(BFS)

    http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...

  5. 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 ...

  6. 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 ...

  7. 【简洁易懂】CF372C Watching Fireworks is Fun dp + 单调队列优化 dp优化 ACM codeforces

    题目大意 一条街道有$n$个区域. 从左到右编号为$1$到$n$. 相邻区域之间的距离为$1$. 在节日期间,有$m$次烟花要燃放. 第$i$次烟花燃放区域为$a_i$ ,幸福属性为$b_i$,时间为 ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. 通用mapper的generator

    <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-genera ...

  2. AJPFX实现兔子问题

    有一对小兔子,从第三个月长成开始每个月生一对小兔子,新出生的小兔子从第三个月长成开始每个月也生一对小兔子,假设所有的兔子都不会死,问每个月兔子的总数?(月数可以是6,12).大神看看我笨方法谢的对吗? ...

  3. ios 微信环境 axios请求 status 0

    做了一个支付页面,调用post请求但是请求status 0,出现这个的原因居然是https的网页请求http的数据. 但是这个再ios里面不会报错,安卓正常. 记录一下客户端的这个特征!

  4. 使用Recast.AI创建具有人工智能的聊天机器人

    很多SAP顾问朋友们对于人工智能/机器学习这个话题非常感兴趣,也在不断思考如何将这种新技术和SAP传统产品相结合.Jerry之前的微信公众号文章C4C和微信集成系列教程曾经介绍了Partner如何利用 ...

  5. Python基础3 函数 变量 递归 -DAY3

    本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 温故知新 1. 集合 主要作用: 去重 关系测 ...

  6. java中等待所有线程都执行结束

    转自:http://blog.csdn.net/liweisnake/article/details/12966761 今天看到一篇文章,是关于java中如何等待所有线程都执行结束,文章总结得很好,原 ...

  7. ASP.NetCore 错误 NU1605 检测到包降级: Microsoft.Data.Sqlite 从 2.2.1 降级到 2.1.0

    找到使用的.csproj文件 将 <PackageReference Include="Microsoft.Data.Sqlite" Version="2.1.0& ...

  8. Ztree 多选,显示勾选的路径

    项目要求,需要向后台传递已经勾选的路径,如 l1-a, l1-l3-c,l1-l3-d;(如果是全选状态则只传递全选状态的路径,不传子节点). 具体可以参考jQ  Ztree 的 v3.5 版本 Me ...

  9. mysql语句中判断是否包含某字符串的方法

    当我们需要对数据做筛选和查询的时候,往往会涉及到一些限制条件的判断,今天就分享一个判断字符串的技巧. like 相信大家对like的用法肯定都很熟悉了,它可以匹配字段以某字符串开始,以某字符串结尾,包 ...

  10. Python 3.52官方文档翻译 http://usyiyi.cn/translate/python_352/library/index.html 必看!

    Python 3.52官方文档翻译   http://usyiyi.cn/translate/python_352/library/index.html 觉得好的麻烦点下推荐!谢谢!