Https://vijos.org/p/1791
For brute force attacks, we only think of BFS, and then it is estimated that the status is over 20 points.
Hacker, why cannot we think of Qaq as simple as brute force ..... This idea is good.
After reading this question, I have to say that I did not expect it ..
Why BFS .. BFS is not required for this path-finding dependency on the front edge!
Because BFS is infinitely expanded, and the status is very large, this question is eight decisions, and the status reaches 8 ^ n .... Sad ..
We can think like this, because the status is moving forward, and the current status only depends on the previous status, then we can use the DP idea .. Enumerate the current status and check whether the status is reached based on the previous status. Mark the status ..
I am too weak. Qaq
(Although this is still violent, I have not been able to make a positive solution, but this idea is worth writing this blog, orz
#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>#include <queue>using namespace std;#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%d", a)#define dbg(x) cout << (#x) << " = " << (x) << endl#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }#define printarr1(a, b) for1(_, 1, b) cout << a[_] << ‘\t‘; cout << endlinline const int getint() { int r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const int max(const int &a, const int &b) { return a>b?a:b; }inline const int min(const int &a, const int &b) { return a<b?a:b; }const int N=40, dx[]={-1, -2, -2, -1, 1, 2, 2, 1}, dy[]={-2, -1, 1, 2, 2, 1, -1, -2};int vis[2][N][N], n, T, X, Y, cnt, a[N][N];int main() {read(n); read(T); read(X); read(Y);for1(i, 1, n) for1(j, 1, n) read(a[i][j]);CC(vis, -1);vis[0][X][Y]=0; int flag=0;for1(t, 1, T) {for1(i, 1, n) for1(j, 1, n) if(t%a[i][j]==0) {rep(k, 8) {int fx=dx[k]+i, fy=dy[k]+j;if(fx<1 || fy<1 || fx>n || fy>n || vis[flag][fx][fy]!=t-1) continue;vis[!flag][i][j]=t;break;}}flag=!flag;}for1(i, 1, n) for1(j, 1, n) if(vis[flag][i][j]==T) ++cnt;printf("%d\n", cnt);for1(i, 1, n) for1(j, 1, n) if(vis[flag][i][j]==T) printf("%d %d\n", i, j);return 0;}
Description
"Knight Travel" is a recently popular board game. On the N * n board, we place a knight on the grid of row X and column Y at moment 0. At each time point, the server guard moves one step according to the rule, that is, one coordinate changes two units, and the other coordinates changes one unit. In game rules, each grid on the board is not always usable. Specifically, each grid is assigned a positive integer, only when the current time is a multiple of the positive integer, this grid can be used. Of course, at every moment of the game, the server guard must be on a usable grid. Players need to carefully design the mobile solution of the server guard for the game to proceed.
Give you an initial game situation, that is, the size of the Board, the position of the 0-server-guard at the moment, and the positive integer assigned to each grid, please calculate whether you can perform t operations on the server guard (that is, whether the game can perform t operations at the moment ). If yes, locate all possible locations of T server guard.
Format input format
The row 1st contains two positive integers, N and T, indicating the size of the Board and the number of operations.
The second row contains two positive integers x and y, indicating the position of the 0 server guard at the moment.
3rd ~ N + 2 rows. Each line contains n positive integers not greater than 10 ^ 9. The j integer of the I + 2 row indicates the integer assigned to the grid of the I row and J column on the board.
Output Format
The first line contains a non-negative integer m, indicating the total number of locations that the server guard may appear after the T operation.
In the next m row, each row contains two positive integers, indicating the possible location of a server guard. These locations are output sequentially according to the row numbers (the row numbers are incremented by column numbers at the same time.
Example 1 input 1 [copy]
3 21 11 3 22 3 23 1 1
Sample output 1 [copy]
21 11 3
Restrictions
1 s
Prompt
For 30% of data, 1 ≤ T ≤ 50,000;
For 100% of data, there are 3 ≤ n ≤ 30, 1 ≤ T ≤ 1,000,000, 1 ≤ x, y ≤ n.
Source
Coci 2011/2012
[Vijos] 1791 knight travel (Special tips)