Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- char boards[105][105];
- int locRow[105], locCol[105];
- char goal[11] = "ICPCASIASG";
- int flag2 = 0;
- //maybe i dont need to make the array?
- void knight(int k, int row, int col, int N){
- if(k >= 10){
- flag2 = 1;
- return;
- } else {
- if(boards[row-2][col-1] == goal[k] && row - 2 >= 1 && col - 1 >= 1) knight(k+1, row-2, col-1, N);
- if(boards[row-2][col+1] == goal[k] && row - 2 >= 1 && col + 1 <= N) knight(k+1, row-2, col+1, N);
- if(boards[row-1][col+2] == goal[k] && row - 1 >= 1 && col + 2 <= N) knight(k+1, row-1, col+2, N);
- if(boards[row+1][col+2] == goal[k] && row + 1 <= N && col + 2 <= N) knight(k+1, row+1, col+2, N);
- if(boards[row+2][col+1] == goal[k] && row + 2 <= N && col + 1 <= N) knight(k+1, row+2, col+1, N);
- if(boards[row+2][col-1] == goal[k] && row + 2 <= N && col - 1 >= 1) knight(k+1, row+2, col-1, N);
- if(boards[row+1][col-2] == goal[k] && row + 1 <= N && col - 2 >= 1) knight(k+1, row+1, col-2, N);
- if(boards[row-1][col-2] == goal[k] && row - 1 >= 1 && col - 2 >= 1) knight(k+1, row-1, col-2, N);
- }
- return;
- }
- int main(){
- int N, len = 10, flag = 1;
- int m = 0, n = 0, cntI = 0;
- char str[10001];
- scanf("%d", &N);
- scanf("%s", str);
- for(int i = 1 ; i <= N; i++){
- for(int j = 1; j <= N; j++){
- boards[i][j] = str[m];
- m++;
- if(boards[i][j] == 'I'){
- locRow[n] = i;
- locCol[n] = j;
- n++;
- }
- }
- }
- cntI = n;
- for(n = 0; n < cntI; n++){
- knight(1, locRow[n], locCol[n], N);
- if(flag2 == 1){
- flag = 1;
- puts("YES");
- break;
- } else {
- flag = 0;
- }
- }
- if(flag == 0) puts("NO");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement