P2105 k Queen Topic Description
Little Z recently picked up a chessboard, and he wanted to put a K-queen on the board. He wanted to know how many squares on the board were not to be attacked after he had finished the K-Queens.
(Ps: A Queen will attack the line where the Queen is located, that column, and two diagonal lines)
Input output Format input format:
The first line of three positive integers n,m,k, indicating the row of the chessboard, as well as small Z placed K Queens.
The next K-line, two positive integers per line, x, Y, indicates that the Queen was placed in line x, column y, and the data guaranteed that no two queens would be placed in the same lattice.
Output format:
An integer line that indicates how much of the board is not being attacked by the grid.
Input and Output Sample input example # #:
12 13 610 412 101 12 33 22 6
Sample # # of output:
25
Description
"Data size and conventions"
For 30% of data, 1≤n,m≤5000,1≤k≤500.
For another 10% of the data, K = 1.
For 100% of data, 1≤n,m≤20000,1≤k≤500.
"Time Limit"
1s/16m
Enumerate a row
{
Enumerate a Queen
{
The Queen's Line of control is this line continue
A column in the Queen's control exists in the position of this line has not been discussed ans++, Mark
The Queen's control of a diagonal exists in the position of this line has not been discussed ans++, Mark
The Queen's control of another diagonal exists in the position of this line has not been discussed ans++, Mark
}
}
#include <cstdio>#include<cstdlib>#include<cstring>using namespacestd;intx[501],y[501],h[20001];intMain () {intn,m,k,i,j,ans,t; scanf ("%d%d%d",&n,&m,&k); memset (H,0,sizeof(h)); for(i=1; i<=k;i++) scanf ("%d%d",&x[i],&Y[i]); Ans=0; for(i=1; i<=n;i++) {T=m; for(j=1; j<=k;j++) if(x[j]==i) {t=0; Break; } Else { if(h[y[j]]!=i) {H[y[j]]=i; T--; } if((I+y[j]-x[j]) >0&& (I+y[j]-x[j]) <=m && h[i+y[j]-x[j]]!=i) {h[i+y[j]-x[j]]=i; T--; } if((y[j]+x[j]-i) >0&& (y[j]+x[j]-i) <=m && h[y[j]+x[j]-i]!=i) {h[y[j]+x[j]-i]=i; T--; }} ans+=T; } printf ("%d\n", ans); return 0;}
Rokua 2105 k Queen