Super Bouncing Beads

Source: Internet
Author: User

Title Source: http://codevs.cn/problem/2994/

Title Description Description

Cows have recently bought a set of simulated egg game equipment from the famous cow toy maker Tycow. Bessie the lawn where they played the game as a matrix of n*n units, while listing the position of her K opponent on the lawn. And then she came to you with this watch, hoping you could help her figure out a piece of data.

In this game, cows can fire bullets in any direction in 8 directions (east, south, due west, north, northeast, southeast, northwest, southwest) with a pinball gun. Bessie wants you to tell her how many options she has if she wants to stand on a grid that can shoot all her opponents. Of course, Bessie can stand on the same grid as one opponent, in which case Bessie can also shoot the opponent.

Enter a description Input Description

First line: Two integers separated by a space: N K

Second to K+1 line: line i+1 There are two spaces separated by the integer r-i and c-i, describing the position of the first cow, indicating that she stood on the R-i row, c-i column.

Output description Output Description

Only one line: Outputs an integer that represents the number of squares that the Bessie can select.

Sample input Sample Input

4 3

2 1

2 3

4 1

Sample output Sample Output

5

Data range and Tips Data Size & Hint

1<=n<=500

1<=k<=100 000

Sample Description

Bessie can choose to stand in any one of the lattice: (2,1), (2,3), (3,2), (bis), (4,3). In the image below, Bessie is labeled as "*" in the same grid as the other cows.

.   .   .                            .   .   .   . .

B.      B.   =======> *. *  .

.  B.      .   =======>.   B. .

B.                            B.   *  . B.

Ideas:

You can use backtracking to run out of all situations, or you can change the way the enemy can be beaten to mark. Anyway, the search can be done anyway.

varF:Array[1.. -,1.. -] ofLongint; X1,x2,x,y:Array[- -.. -] ofLongint;    N,k,i,a,b,j:longint; Ans:longint=0;beginread (n,k);  fori:=1  toK Do    beginRead (A, b);        Inc (X[a]);        Inc (Y[b]); Inc (X1[a+b]); Inc (X2[a-b]); F[A,B]:=1; End;  fori:=1  toN Do         forj:=1  toN Do            begin                ifx[i]+y[j]+x1[i+j]+x2[i-j]-3*f[i,j]=k ThenInc (ANS); End; Writeln (ans);End.
View Code

Super Bouncing Beads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.