Codefroces 750D:New Year and Fireworks(BFS)
http://codeforces.com/contest/750/problem/D
题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数。
思路:n = 30, t = 5,所以最多推进150格。范围很小,开一个300*300的数组,初始位置在(150, 150),直接BFS。
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
#define N 310
typedef long long LL;
struct P {
int x, y, step, dir;
P () {}
P (int x, int y, int step, int dir) : x(x), y(y), step(step), dir(dir) {}
};
int ans, t[N];
bool mp[N][N];
bool vis[N][N][][];
int d[][] = {{, }, {, }, {, }, {, -}, {, -}, {-, -}, {-, }, {-, }};
// 八个方向顺时针
void BFS(int n) {
queue<P> que;
while(!que.empty()) que.pop();
memset(vis, , sizeof(vis));
memset(mp, , sizeof(mp));
ans = ;
vis[][][][] = ; // 初始位置
que.push(P(, , , ));
while(!que.empty()) {
P f = que.front(); que.pop();
int nx = f.x, ny = f.y, step = f.step, dd = f.dir;
for(int i = ; i <= t[step]; i++) { // 处理这一层的绽放情况
nx += d[dd][];
ny += d[dd][];
mp[nx][ny] = ;
}
if(step < n) { // 向左右绽放
int dl = ((dd - ) + ) % , dr = (dd + ) % ;
if(!vis[nx][ny][step+][dl]) {
vis[nx][ny][step+][dl] = ;
que.push(P(nx, ny, step + , dl));
}
if(!vis[nx][ny][step+][dr]) {
vis[nx][ny][step+][dr] = ;
que.push(P(nx, ny, step + , dr));
}
}
}
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
if(mp[i][j]) ans++;
} int main() {
int n;
cin >> n;
for(int i = ; i <= n; i++) cin >> t[i];
BFS(n);
printf("%d\n", ans);
return ;
}
Codefroces 750D:New Year and Fireworks(BFS)的更多相关文章
- Codefroces 750C:New Year and Rating(思维)
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...
- AcWing:172. 立体推箱子(bfs)
立体推箱子是一个风靡世界的小游戏. 游戏地图是一个N行M列的矩阵,每个位置可能是硬地(用”.”表示).易碎地面(用”E”表示).禁地(用”#”表示).起点(用”X”表示)或终点(用”O”表示). 你的 ...
- 题解报告:poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- Leetcode之广度优先搜索(BFS)专题-773. 滑动谜题(Sliding Puzzle)
Leetcode之广度优先搜索(BFS)专题-773. 滑动谜题(Sliding Puzzle) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary ...
- Leetcode之广度优先搜索(BFS)专题-127. 单词接龙(Word Ladder)
Leetcode之广度优先搜索(BFS)专题-127. 单词接龙(Word Ladder) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary Tre ...
- Leetcode之广度优先搜索(BFS)专题-752. 打开转盘锁(Open the Lock)
Leetcode之广度优先搜索(BFS)专题-752. 打开转盘锁(Open the Lock) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary ...
- Leetcode之广度优先搜索(BFS)专题-1162. 地图分析(As Far from Land as Possible)
Leetcode之广度优先搜索(BFS)专题-1162. 地图分析(As Far from Land as Possible) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. ...
- Leetcode之广度优先搜索(BFS)专题-994. 腐烂的橘子(Rotting Oranges)
Leetcode之广度优先搜索(BFS)专题-994. 腐烂的橘子(Rotting Oranges) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ar ...
- Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares)
Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ar ...
随机推荐
- Universal Link 笔记
如何实现Universal Link? 简单地说三步,1.把一个配置文件放在指定服务器根目录 2.在Xcode中设置AssociateDomain 3.安装app时,会根据Xcode中设置的Assoc ...
- Mvc自定义路由让支持.html的格式
前言 在大多时候,我们都需要自定义路由,当我们设置为/list/1.html的时候,有的时候会出现以下异常. routes.MapRoute( "category", // 路由名 ...
- django--models操作
1.models的功能 操作数据库 提交验证 在django的admin中,使用的是modelForms所以在验证的时候,尽管在models后有error_ message参数也不会根据此来提示.具体 ...
- 手势响应 ,避免点击多个cell同时响应同一手势多次,只响应第一个cell
http://www.cnblogs.com/wfwenchao/articles/3700205.html UIView除了负责展示内容给用户外还负责响应用户事件.本章主要介绍UIView用户交互相 ...
- 面向过程 vs 面向对象
从网上摘录了一些面向过程vs.面向对象的分析,先简单记录如下,稍后会继续整理. 为什么会出现面向对象分析方法? 因为现实世界太复杂多变,面向过程的分析方法无法实现. 面向过程 采用面向过程必须了解整个 ...
- 快速学习html、css的经典笔记
HTML语言剖析 Html简介-目录 全写: HyperText Mark-up Language 译名: 超文本标识语言 简释:一种为普通文件中某些字句加上标示的语言,其目的在于运用标签(tag ...
- LeetCode Remove Element
原题链接在这里:https://leetcode.com/problems/remove-element/ 题目: Given an array and a value, remove all ins ...
- 【尝新】微信小程序初体验
文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/?t=1474644089434 根据文档地址中下载微信开发工具后,按照文档指引可以创建一个快速体验的小d ...
- SpringMVC操作指南-登录功能与请求过滤
[1] Source http://code.taobao.org/p/LearningJavaEE/src/LearningSpringMVC005%20-%20Login%20and%20Filt ...
- css给div添加0.5px的边框
具体代码实现如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...