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 ...
随机推荐
- SpringMVC下Ajax请求的方法,@Responsebody如果返回的是布尔值,ajax不会接到任何回传数据
SpringMVC框架下,如果用ajax向后台请求得方法如果使用@Responsebody返回布尔值的话,ajax得不到任何的回传数据. 但是如果返回String类型,就是正常的. 测试了下代码写得没 ...
- SpingMvc中的异常处理
一.处理异常的方式 Spring3.0中对异常的处理方法一共提供了两种: 第一种是使用HandlerExceptionResolver接口. 第二种是在Controller类内部使用@Exc ...
- <hr>标签不止创建html水平线也可以画圆噢
看到上面这张图,第一反应是用photoshop类似作图软件画出来的,但那是华丽丽的错觉.一个简单的<hr>标签就能完成漂亮的效果,而不仅仅是创建html水平线.想知道怎么实现吗?Let's ...
- .NET积累
2016-10-27 给视图中的select赋值: 控制器: public ActionResult Add() { List<SelectListItem> ClassName = ne ...
- android-获得".apk"文件的相关信息。包名、版本号等等
String filePath = "/sdcard/feijiedemo.apk"; PackageManager packageManager = getPackageMana ...
- java模拟post方式提交表单实现图片上传【转】
转自:http://blog.csdn.net/5iasp/article/details/8669644 模拟表单html如下: <form action="up_result ...
- OpencV2.4.13前景提取示例代码
OpenCV2编译 基于高斯混合模型 #include<fstream> #include<iostream> #include<iostream> #inclu ...
- canvas简介
一.canvas简介 1.1 什么是canvas?(了解) 是HTML5提供的一种新标签 <canvas></canvas> 英 ['kænvəs] 美 ['kænvəs] 帆 ...
- Activity系列讲解---三大基本状态与七大生命周期函数
简介:四大组件之一,在应用中一个Activity可以用来表示一个界面,可以理解为用户可视化界面,一个android应用必须通过Activity来运行和启动. 1.三大基本状态与七大生命周期函数 2.代 ...
- python之路十八
1.JS 正则 test - 判断字符串是否符合规定的正则 rep = /\d+/; rep.test("asdfoiklfasdf89asdfasdf ...