Untitled
Never
#include <stdio.h> void print(void); void solve(int Queen_num, int Rook_num, int y); int check_Q(int x, int y); int check_R(int x, int y); int chessboard_len; int count = 0; int chessboard[9]; char chess[9][9]; char chess_type[9]; void solve(int Queen_num, int Rook_num, int y){ if(y == chessboard_len){ count++; return; } if(Queen_num){ for(int x = 0; x < chessboard_len; x++){ if(check_Q(x, y)){ chessboard[y] = x; chess[x][y] = 'Q'; chess_type[y] = 'Q'; solve(Queen_num - 1, Rook_num, y + 1); chessboard[y] = -1; chess[x][y] = '\0'; chess_type[y] = '\0'; } } } if(Rook_num){ for(int x = 0; x < chessboard_len; x++){ if(check_R(x, y)){ chessboard[y] = x; chess[x][y] = 'R'; chess_type[y] = 'R'; solve(Queen_num, Rook_num - 1, y + 1); chessboard[y] = -1; chess[x][y] = '\0'; chess_type[y] = '\0'; } } } } int check_Q(int x, int y){ int data; for(int i = 0; i < y; i++){ if(chessboard[i] == -1) continue; data = chessboard[i]; if(x == data) return 0; else if ((i + data) == (y + x)) return 0; else if ((i - data) == (y - x)) return 0; } return 1; } int check_R(int x, int y){ if(chessboard[y]) return 0; int data; char type; for(int i = 0; i < chessboard_len; i++){ if(chessboard[i] == -1) continue; data = chessboard[i]; type = chess_type[i]; if(type == 'Q'){ if(x == data) return 0; else if ((i + data) == (y + x)) return 0; else if ((i - data) == (y - x)) return 0; } else{ if(x == data) return 0; } } return 1; } void print(void){ for (int y = 0; y < chessboard_len; y++){ for (int x = 0; x < chessboard_len; x++){ if(chess[x][y]) printf("%c", chess[x][y]); else printf("0"); } printf("\n"); } printf("================\n"); } int main(void){ int N, M; while(scanf(" %d %d", &N, &M) == 2){ chessboard_len = N + M; for(int i = 0; i < chessboard_len; i++) chessboard[i] = -1; solve(N, M, 0); printf("%d\n", count); count = 0; } return 0; }
Raw Text
-
nbuergbheuirybgheirg
1 min ago
-
Untitled
13 min ago
-
Cuckold licks pussy of his whore girlfriend and eats lover cum
24 min ago
-
my friend gave me a present
54 min ago
-
Fucking the boss's wife at a party to orgasm. She moans with pleasure and takes cum in her mout
1 hour ago
-
https://go90-keto-gummies-get.company.site/
1 hour ago
-
https://go90-keto-gummies-get.company.site/
1 hour ago
-
weltowel
1 hour ago
-
MA'e
1 hour ago
-
https://go90-keto-gummies-get.company.site/
1 hour ago