Competition3: terrible cosmic rays

Title Description
As we all know, God has reached the Swiss CS undergraduate ceiling, but everyone knows there is day, there are people outside Gou. In the vastness of the universe, there is a biological called Gou dog, the creature born will be able to reach the level of knowledge of human graduate, and naturally good at CSP, and even the first level of the country! But the most frightening thing is that it can emit cosmic rays! Cosmic rays can destroy a person's IQ, down-Chi fight!

Cosmic rays propagation (FIG can be seen as a two-dimensional grid) in an infinite two-dimensional plane, the default initial upward direction. Cosmic rays will emit some distance after splitting, approximately 45 ° to the direction of the two split cosmic rays, while the power of the same! Cosmic rays will split n times, each time division unit lengths ai will advance in the direction of splitting.

Swiss now God wants to bring his little brothers dog challenge Gou, but Rui God do not want their IQ drops so ordinary undergraduate level course, so Rui God to ask you to help him calculate the total number of positions will be "down Chi combat. "

Input format
input of the first line contains a positive integer n (n <= 30), n represents cosmic rays will split views.

The second line contains n positive integers a1, a2 ... an, ai represents the i-th to i-th division number of cosmic rays per unit length of stay on its original direction.

Output format
output a number ans, indicates how many positions will be reduced intellectual combat.

Input Example

4
4 2 2 3

Output Example

39

Example Explanation
Here Insert Picture Description
Note that the initial point is not the point.

Problem-solving ideas
a look at the subject, ah, this is about two flowering look, like most of the bfs smile.
So this question is obviously to do with bfs out
we can set up a two-dimensional array map, whether to record cosmic rays reach a point there too.
The remaining is bfs, and the direction of the position of the queue after each processing of the current direction of cosmic rays will arrive and split out at the finish two small on the line.
So we can use a structure to store each ray.

At that time the game was score 40 points, the other burst memory:

#include<iostream>
#include<queue>
#include<cstring>

using namespace std;

int map[350][350];
const int dirction[8]={0,1,2,3,4,5,6,7};
const int dx[8]={0,1,1,1,0,-1,-1,-1};
const int dy[8]={1,1,0,-1,-1,-1,0,1};

struct point
{
	int x,y;//坐标
	int dir;//0 1 2 3 4 5 6 7
	int a;//位移长度
	int l;//层级
	
	point(int _x,int _y,int _d, int _a,int _l)
	{
		x=_x;
		y=_y;
		dir=_d;
		a=_a;
		l=_l;
	}
};

int a[30];

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	
	memset(map,0,sizeof(map));
	
	queue<point>q;
	point first(250,250,0,a[0],0);
	q.push(first);
	
	while(!q.empty())
	{
		point now=q.front();
		q.pop();
		
		int tx=now.x,ty=now.y;
		//map[tx][ty]=1;
		for(int j=0;j<now.a;j++)
		{
			tx+=dx[now.dir];
			ty+=dy[now.dir];
			map[tx][ty]=1;
		}

		
		int offset[2];
		if(now.dir==0)
		{
			offset[0]=1;offset[1]=7;
		}
		else if(now.dir==7)
		{
			offset[0]=0,offset[1]=6;
		}
		else
		{
			offset[0]=now.dir+1;
			offset[1]=now.dir-1;
		}
		
		if(now.l!=n-1)
		for(int i=0;i<=1;i++)
		{
			q.push(point(tx,ty,offset[i],a[now.l+1],now.l+1));
		}
	}
	
	int sum=0;
	for(int i=0;i<500;i++)
	for(int j=0;j<500;j++)
		if(map[i][j]==1)
			sum++;
	
	cout<<sum<<endl;
}

After the end of the game found that this stuff can be found in the example of FIG see that, this seems to be the axis of symmetry of the graphic ...?
Then we can deal with only one side of it! Finally, in addition to the other axial point value × 2 points are on the line.
But think of this when oj has been turned off, so do not stick to turn over the code, and modify it is also quite simple.

Published 21 original articles · won praise 3 · Views 411

Guess you like

Origin blog.csdn.net/qq_44506233/article/details/104982021