"topic link"Click here~~
" The main idea" gives you a n*m chess board, and given the T-fixed position of the queen (horizontal axis, ordinate known), to find the next legal place to put the queen possible number
"Problem-solving ideas"
Because it is only the position of the next queen, not all other possibilities, it can be done as follows:
the n*n matrix is mapped and converted to a single-line mode of 1* (N+M).
1. Rows and columns can be mapped directly.
2. There are two cases of diagonal (drawing verification)
1.1. Map to X+y mode (13 interval)
2..1 map to X-y+y mode (24 interval) (Note!) The preceding x is the mapped row, and Y is the column)
Code
/* AUTHOR:HRW maps the n*n matrix and converts it to a single-line mode of 1* (N+M). 1. Rows and columns can be mapped directly. 2, there are two cases of diagonal (drawing verification) 1. Map to X+y mode (13 interval) 2. Map to X-y+y mode (24 interval) (Note!) The preceding x is the mapped row, and Y is the column) */#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 30000 + 10;int u SEDX[MAXN], USEDY[MAXN], Usedl[maxn+maxn],usedr[maxn+maxn];//int Shuru ()//{//int sum=0;//char ch;//while ((ch=g Etchar ()) < ' 0 ' | | Ch> ' 9 '); sum=ch-' 0 ';//while ((Ch=getchar ()) >= ' 0 ' &&ch<= ' 9 ') sum=sum*10+ch-' 0 ';//return Sum;//}int main () {in T X,y,n; while (Cin >> X >> Y >> n,x) {memset (usedl,0,sizeof (Usedl)); memset (usedr,0,sizeof (USEDR)); memset (usedx,0,sizeof (Usedx)); memset (usedy,0,sizeof (usedy)); for (int i = 0; i < N; ++i) {int x, y; cin>>x>>y; ++USEDX[X]; Map Line ++usedy[y]; Map column ++usedl[y+x-y]; 2,4 interval ++usedr[x+y]; 1,3 Zone} LL ans= 0; for (int i = 1, i <= X; ++i) {for (int j = 1; j <= Y; ++j) {if (!usedx[i] &&!usedy[j ] &&!usedl[i-j+y] &&!usedr[i+j]) ans++; }} cout << ans << endl; } return 0;}
"Team Race # #" BNU 4299 God Save the i-th Queen (array map)