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