Good Bye 2016 - D
题目链接: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的更多相关文章
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- 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 ...
- Codeforces Good Bye 2016 E. New Year and Old Subsequence
传送门 题意: 给出一个长度为\(n\)的串,现在有\(q\)个询问,每个询问是一个区间\([l,r]\),要回答在区间\([l,r]\)中,最少需要删多少个数,满足区间中包含\(2017\)的子序列 ...
- Good Bye 2016
A - New Year and Hurry (water) #include <bits/stdc++.h> using namespace std; int main() { ]; ; ...
- Good Bye 2016 - C
题目链接:http://codeforces.com/contest/750/problem/C 题意:在CF中,每个人都有个Rank值. 当Rank>=1900时,为DIV1.Rank< ...
- Good Bye 2016 - B
题目链接:http://codeforces.com/contest/750/problem/B 题意:地球的子午线长度为40000,两极点的距离为20000.现在你从北极出发,按照题目输入方式来走. ...
- Good Bye 2016 - A
题目链接:http://codeforces.com/contest/750/problem/A 题意:有n场比赛要打,第i场比赛需要花i*5分钟来完成,比赛从20:00开始.然后新年派对24:00开 ...
- Good Bye 2016 //智商再次下线,边界爆炸.....
A B很水就略了.. C.又是一次wannafly一样的判断区间的..... 边界设为2000000 正好GG...... fst的时候立马想到上次也是这么wa过的...... 所以下次遇到这种题 ...
- Codeforces Good Bye 2016 D 模拟搜索?
给出烟花的爆炸方式和爆炸次数 问最后有多少个格子会被炸到 如果dfs的话会超时... 利用模拟每一层来搜索..? 思想就是一开始有一个爆炸点向上 然后模拟完第一段 会产生一个爆炸点 朝两个方向 就用v ...
随机推荐
- python --> 递归 以及装饰器
一.递归知识 函数迭套执行,逐层执行之后,满足某个条件之后就会停止执行,将return值返回上层的函数,上层函数再逐层返回,最终返回给最初始函数. 递归在斐波那契数列的应用[斐波那契数列特点:前两个数 ...
- jq 个性的隔行变色
效果图大致这样: 我的html格式部分这样:/*不过他们都说我的dom结构不太合理,同意.BUT,我就是不想写表格而写成的这样的,所以后面jq部分也要迁就了*/ <div class=&qu ...
- Oracle的外部表
一.外部表特性 数据文件位于操作系统之外,并且具有一定的格式分割的文本文件或其他类型文件.ORACLE的外部表通过SQL的形式访问数据文件中的数据,数据并不需要加载到数据库中且数据是可读的,所以不用D ...
- saltstack 把数据返回到mysql服务器
环境:http://www.cnblogs.com/zzzhfo/p/5790918.html master端需要安装MySQL-python和mysql-server mysql-server用于存 ...
- 深入理解android:id以及@+id/name和@id/name的区别联系
今天为了好好研究了下@+id/name和@id/name的区别以及联系,又翻了翻文档/guide/topics/resources/layout-resource.html中关于 android:id ...
- headroom.js –在不需要页头时将其隐藏
官方网站 http://www.bootcss.com/p/headroom.js/
- JS判断字符串长度(中文长度为2,英文长度为1)
目的:计算字符串长度(英文占1个字符,中文汉字占2个字符) 方法一: String.prototype.gblen = function() { var len = 0; for (var i=0; ...
- Repeater、地址栏传值、Response--2016年12月30日
Repeater Repeater支持以下5种模板 ● ItemTemplate : 对每一个数据项进行格式设置 [Formats each item from the data sou ...
- eclipse软件创建servlet
网上找了好多资料,eclipse创建servlet后,发到tomcat下发布,不能编译,生产class文件. 很多回答的都是一知半解,太气人了,看书.把资料找了一天,才发现是没有servlet-api ...
- 20个Mac用户必须掌握的触摸手势
我第一次接触MacBook时,最令我惊叹的就是MacBook的触摸板,通过各种手势,完全可以不用鼠标,且有些时候更加的快捷和方便.那么都有哪些手势呢?可以通过 -> 来查看学习各种手势的使用,下 ...