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 ...
随机推荐
- 所有DOM元素加载之前执行的页面加载事件[jquery]
<script type="text/javascript"> (function() { alert("DOM还没加载"); })(jQuery) ...
- SqlSessionFactory
源码: public interface SqlSessionFactory { SqlSession openSession(); SqlSession openSession(boolean va ...
- Java集合类工具CollectionUtils的操作方法
集合判断: 例1: 判断集合是否为空:CollectionUtils.isEmpty(null): trueCollectionUtils.isEmpty(new ArrayList()): true ...
- java 读取txt,java读取大文件
java 读取txt,java读取大文件 package com.bbcmart.util; import java.io.File;import java.io.RandomAccessFile;i ...
- Java递归调用改成非递归
在java语言中,使用递归调用时,如果过多的调用容易造成java.lang.StackOverflowError即栈溢出和程序执行过慢.这是一个潜在Bug和影响程序执行效率问题,需要谨慎使 ...
- windows系统下查看或删除自己电脑的共享文件以及文件夹
(1)查看所有共享 net share (2)删除指定共享 例如:删除C盘共享 net share C$ /delete net share 共享名 /delete (/del)
- Outlook 数据文件(.pst 和 .ost)简介
使用 Microsoft Outlook 时,电子邮件.日历.任务和其他项目保存在邮件服务器或计算机上,或者同时保存在这两个位置.如果 Outlook 项目保存在计算机上,则它们保存在 Outlook ...
- 原创 :单刷深渊 在Linux中系统安装mysql实战直播
[root@web108 tools]# ###开始装mysql 1添加用户 [root@web108 tools]# useradd -s /sbin/nologin -M mysql 2解压 [r ...
- oracle补丁类型
名称 说明 Release ¤ 标准产品发布.如Oracle Database 10g Release 2的第一个发行版本为10.2.0.1,可以在OTN.edelivery等站点上公开下载 Patc ...
- ref版的 摄像头 读取 因为id的时候,id不能重复 还要用时间戳,比较麻烦
<!-- * @description 摄像头vue版实例 * @fileName cameraObject.vue * @author 彭成刚 * @date // :: * @version ...