题目链接: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. Why did I have a recovery trip

    For more than a decade, I felt most at ease living out of a suitcase, never quite sure where I might ...

  2. OpenFOAM&Gmsh&CFD圆柱绕流(两个圆柱)

    问题: 圆柱绕流问题,模拟仿真有两个圆柱.一个源的流体变化情况. 解决步骤: 1.使用Gmsh画出网格,并保存cylindertwo.msh 2.以Cavity为基础创建新的Case:Cylinder ...

  3. GET和POST有什么区别?及为什么网上的多数答案都是错的

    如果有人问你,GET和POST,有什么区别?你会如何回答? 最普遍的答案 回来之后寻思了很久,他到底是想问我什么?我一直就觉得GET和POST没有什么除了语义之外的区别,自打我开始学习Web编程开始就 ...

  4. vim 添加php自动补全 并格式化代码

    自动补全,修改/etc/vimrc的配置 vim /etc/vimrc 添加: filetype plugin on autocmd FileType php set omnifunc=phpcomp ...

  5. MongoDB安装配置示例

    参考 http://www.runoob.com/mongodb/mongodb-window-install.html http://www.cnblogs.com/lecaf/archive/20 ...

  6. Codeforces 731C Socks 并查集

    题目:http://codeforces.com/contest/731/problem/C 思路:并查集处理出哪几堆袜子是同一颜色的,对于每堆袜子求出出现最多颜色的次数,用这堆袜子的数目减去该值即为 ...

  7. PYTHON文件操作(二)

    class file(object) def close(self): # real signature unknown; restored from __doc__ 关闭文件 "" ...

  8. 自己常用的webstrom快捷键

    1.ctrl+"d" 复制正行 2.ctrl+"y" 删除正行 3.ctrl+"-" 缩小整块 4.ctrl+"+" 扩 ...

  9. Java并发1——线程创建、启动、生命周期与线程控制

    内容提要: 线程与进程 为什么要使用多线程/进程?线程与进程的区别?线程对比进程的优势?Java中有多进程吗? 线程的创建与启动 线程的创建有哪几种方式?它们之间有什么区别? 线程的生命周期与线程控制 ...

  10. C#数字日期装换为中文日期

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...