题目链接:http://codeforces.com/contest/750/problem/D

题意:新年烟花爆炸后会往两端45°差分裂。分裂完后变成2部分,之后这2部分继续按这种规则分裂。现在给你每一步分裂的个数。有可能几个部分都是分裂到一个位置,这种情况只算一个。问最后分裂完有多少个。

思路:模拟即可。由于n最多30,每次最多分裂5个。所以总体规模不是很大。但是需要记忆化一下防止TLE。G[][]表示被覆盖的格子。vis[k][i][j][d]表示第k次分裂在位置(i,j)方向为d时是否出现过。然后就BFS模拟。把八个方向以时钟方向表示从0~7。方向k每次分裂相当于分裂了两个方向为(k+1)%8和(k-1+8)%8。

注意可能内存会炸,所以用的bool型数组

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<time.h>
#include<cmath>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
int t[MAXN];
bool vis[][MAXN][MAXN][], G[MAXN][MAXN];
int Dir[][] = { , , , , , , -, , -, , -, -, , -, , - };
struct Node{
int x, y;
int dir;
int step;
Node(int _x = , int _y = , int _dir = , int _step = ) :x(_x), y(_y), dir(_dir), step(_step){};
};
int BFS(int n){
memset(G, , sizeof(G));
memset(vis, , sizeof(vis));
queue<Node>Q;
Q.push(Node(, , , )); //设起点为250,250
vis[][][][] = ;
for (int i = ; i < t[]; i++){ //预处理第1次
G[ + i*Dir[][]][ + i*Dir[][]] = ;
}
while (!Q.empty())
{
Node top = Q.front(); Q.pop();
if (top.step >= n){ break; }
Node next;
int k = (top.dir - + ) % ;
for (int i = ; i <= t[top.step]; i++){
G[top.x + i*Dir[k][]][top.y + i*Dir[k][]] = ;
}
next.x = top.x + t[top.step] * Dir[k][]; next.y = top.y + t[top.step] * Dir[k][]; next.step = top.step + ; next.dir = k;
if (!vis[next.step][next.x][next.y][next.dir]){ Q.push(next); vis[next.step][next.x][next.y][next.dir] = ; }
k = (top.dir + ) % ;
for (int i = ; i <= t[top.step]; i++){
G[top.x + i*Dir[k][]][top.y + i*Dir[k][]] = ;
}
next.x = top.x + t[top.step] * Dir[k][]; next.y = top.y + t[top.step] * Dir[k][]; next.step = top.step + ; next.dir = k;
if (!vis[next.step][next.x][next.y][next.dir]){ Q.push(next); vis[next.step][next.x][next.y][next.dir] = ; }
}
int ans = ;
for (int i = ; i < MAXN; i++){
for (int j = ; j < MAXN; j++){
ans += G[i][j];
}
}
return ans;
}
int main(){
//#ifdef kirito
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
//#endif
// int start = clock();
int n;
while (scanf("%d", &n) != EOF){
for (int i = ; i < n; i++){
scanf("%d", &t[i]);
}
printf("%d\n", BFS(n));
}
//#ifdef LOCAL_TIME
// cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
return ;
}

Good Bye 2016 - D的更多相关文章

  1. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  2. Good Bye 2016 A. New Year and Hurry【贪心/做题目每道题花费时间按步长为5等差增长,求剩余时间够做几道题】

    A. New Year and Hurry time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. Codeforces Good Bye 2016 E. New Year and Old Subsequence

    传送门 题意: 给出一个长度为\(n\)的串,现在有\(q\)个询问,每个询问是一个区间\([l,r]\),要回答在区间\([l,r]\)中,最少需要删多少个数,满足区间中包含\(2017\)的子序列 ...

  4. Good Bye 2016

    A - New Year and Hurry (water) #include <bits/stdc++.h> using namespace std; int main() { ]; ; ...

  5. Good Bye 2016 - C

    题目链接:http://codeforces.com/contest/750/problem/C 题意:在CF中,每个人都有个Rank值. 当Rank>=1900时,为DIV1.Rank< ...

  6. Good Bye 2016 - B

    题目链接:http://codeforces.com/contest/750/problem/B 题意:地球的子午线长度为40000,两极点的距离为20000.现在你从北极出发,按照题目输入方式来走. ...

  7. Good Bye 2016 - A

    题目链接:http://codeforces.com/contest/750/problem/A 题意:有n场比赛要打,第i场比赛需要花i*5分钟来完成,比赛从20:00开始.然后新年派对24:00开 ...

  8. Good Bye 2016 //智商再次下线,边界爆炸.....

    A B很水就略了.. C.又是一次wannafly一样的判断区间的.....  边界设为2000000  正好GG...... fst的时候立马想到上次也是这么wa过的...... 所以下次遇到这种题 ...

  9. Codeforces Good Bye 2016 D 模拟搜索?

    给出烟花的爆炸方式和爆炸次数 问最后有多少个格子会被炸到 如果dfs的话会超时... 利用模拟每一层来搜索..? 思想就是一开始有一个爆炸点向上 然后模拟完第一段 会产生一个爆炸点 朝两个方向 就用v ...

随机推荐

  1. js作用域

    一.js没有块级作用域 在c,java等语言中花括号里的代码都有自己的作用域,而js花括号没有块级作用域,经常会导致一些困惑,不明所以.例如: console.info(color); if(true ...

  2. Spring-test使用JUnit时,测试类autowired报错,create bean error

    Spring-test使用JUnit时,测试类里面使用autowired会报错, 报create bean error...... 但是controller里面@autowired可以正常运行的. 在 ...

  3. 在Centos中部署redis运行状态图形化监控工具 — RedisLive

    写在前面 前两天看到张善友老师的一篇文章<先定个小目标, 使用C# 开发的千万级应用>,里面给出了一张腾讯OA基础服务中redis运行情况的一张监控图,然后想到自己的项目中前不久也上了re ...

  4. Linux远程执行Shell命令或脚本

    ## 远程执行shell命令 ssh [user]@[server] '[command]' # eg. ssh root@192.168.1.1 'uptime' ## 远程执行本地shell脚本 ...

  5. CentOS添加用户并加入sudo权限

    # 新增用户 useradd username # 设置密码 passwd username # 加入sudo ## 打开sudo配置文件 visudo ## 找到下面这两行,并在下面新增红色部分 # ...

  6. Linux下编译安装MariaDB

    MariaDB是MySQL的一个开源分支,主要是社区在维护,并且完全兼容MySQL,并且可以很方便的称为MySQL的替代,MariaDB的诞生正是出自MySQL创始人Michael Widenius之 ...

  7. js_继承

    一,js中对象继承 js中有三种继承方式 1.js原型(prototype)实现继承 复制代码代码如下: <SPAN style="<SPAN style="FONT- ...

  8. foxmail邮箱,签名中如何添加当前日期

    菜单--工具--模板管理 当前HTML模板中光标定位在签名之前,然后进行操作:插入宏--当前日期,适当调整位置即可 最下方为新邮件选择HTML模板 新建一封邮件试试吧

  9. rsync参数及通信

    rsync 支持:  本机数据 <-------> 远程数据/本地数据 意义:  支持增量拷贝 --> 备份,节省带宽,时间   rsync -avL 一.常用选项  ******* ...

  10. 【http】四种常见的 POST 提交数据方式

    来源:http://www.cnblogs.com/aaronjs/p/4165049.html HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT ...