HDOJ5540 Secrete Master Plan
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5540
问一张纸片旋转后能不能和另外一张完全一样,枚举所有情况即可。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 int x[4]; 23 int y[4]; 24 25 int main() { 26 // freopen("in", "r", stdin); 27 int T; 28 int n; 29 scanf("%d", &T); 30 for(int _ = 1; _ <= T; _++) { 31 for(int i = 0; i < 4; i++) scanf("%d", &x[i]); 32 for(int i = 0; i < 4; i++) scanf("%d", &y[i]); 33 int flag = 0; 34 if(x[0] == y[0] && x[1] == y[1] && x[2] == y[2] && x[3] == y[3]) flag = true; 35 else if(x[0] == y[1] && x[1 ]== y[3] && x[2] == y[0] && x[3] == y[2]) flag = true; 36 else if(x[0] == y[2] && x[1 ]== y[0] && x[2] == y[3] && x[3] == y[1]) flag = true; 37 else if(x[0] == y[3] && x[1 ]== y[2] && x[2] == y[1] && x[3] == y[0]) flag = true; 38 39 printf("Case #%d: ", _); 40 if(flag) printf("POSSIBLE\n"); 41 else printf("IMPOSSIBLE\n"); 42 } 43 }
HDOJ5546 Ancient Go
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5546
问下一步是否可以吃掉o,搜索o的所有连通块的旁边是否只有一个.即可。额外开一个数组来记下当前连通块附近所有的.的位置。注意每找到一次连通块要初始化这个数组。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 const int dd[4][2] = {1,0,0,1,-1,0,0,-1}; 23 char G[11][11]; 24 bool vis[11][11]; 25 bool pos[11][11]; 26 int cnt, flag; 27 28 void init() { 29 memset(G, 0, sizeof(G)); 30 memset(vis, 0, sizeof(vis)); 31 memset(pos, 0, sizeof(pos)); 32 cnt = 0; 33 flag = 0; 34 } 35 36 void dfs(int x, int y) { 37 for(int i = 0; i < 4; i++) { 38 int xx = x + dd[i][0]; 39 int yy = y + dd[i][1]; 40 if(G[xx][yy] == '.' && !pos[xx][yy]) { 41 if(xx >= 0 && xx < 9 && yy >= 0 && yy < 9) { 42 cnt++; 43 pos[xx][yy] = 1; 44 } 45 } 46 } 47 for(int i = 0; i < 4; i++) { 48 int xx = x + dd[i][0]; 49 int yy = y + dd[i][1]; 50 if(G[xx][yy] == 'o' && !vis[xx][yy]) { 51 if(xx >= 0 && xx < 9 && yy >= 0 && yy < 9) { 52 vis[xx][yy] = 1; 53 dfs(xx, yy); 54 } 55 } 56 } 57 } 58 59 int main() { 60 // freopen("in", "r", stdin); 61 int T; 62 scanf("%d", &T); 63 for(int _ = 1; _ <= T; _++) { 64 init(); 65 for(int i = 0; i < 9; i++) { 66 scanf("%s", G[i]) ; 67 } 68 // for(int i = 0; i < 9; i++) { 69 // printf("%s\n", G[i]); 70 // } 71 for(int i = 0; i < 9; i++) { 72 for(int j = 0; j < 9; j++) { 73 if(G[i][j] == 'o' && !vis[i][j]) { 74 memset(pos, 0, sizeof(pos)); 75 vis[i][j] = 1; 76 cnt = 0; 77 dfs(i, j); 78 if(cnt == 1) { 79 flag = 1; 80 break; 81 } 82 } 83 } 84 if(flag) break; 85 } 86 printf("Case #%d: ", _); 87 if(flag) printf("Can kill in one move!!!\n"); 88 else printf("Can not kill in one move!!!\n"); 89 } 90 }
HDOJ5547 Sudoku
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5547
4*4的数独游戏,对角线上的数可以相同,但是每一个2*2的小方格(一共四个)中的数字必须不一样。回溯暴力可过。判重可以使用三个数组分别记录行列和块中各数的出现情况。(判断小格内重复的方法写搓了,好丑QAQ)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 char G[10][10]; 23 bool row[10][10]; 24 bool col[10][10]; 25 bool square[10][10]; 26 27 bool flag; 28 29 void init() { 30 memset(G, 0, sizeof(G)); 31 memset(row, 0, sizeof(row)); 32 memset(col, 0, sizeof(col)); 33 memset(square, 0, sizeof(square)); 34 flag = 0; 35 } 36 37 int s(int r, int c) { 38 if((r == 0 ||r == 1) && (c == 0 || c == 1)) return 1; 39 if((r == 0 ||r == 1) && (c == 2 || c == 3)) return 2; 40 if((r == 2 ||r == 3) && (c == 0 || c == 1)) return 3; 41 if((r == 2 ||r == 3) && (c == 2 || c == 3)) return 4; 42 } 43 44 bool check(int r, int c, int n) { 45 if(row[r][n]) return 0; 46 if(col[c][n]) return 0; 47 if(square[s(r,c)][n]) return 0; 48 return 1; 49 } 50 51 void dfs(int cur) { 52 if(cur == 16) { 53 flag = 1; 54 return; 55 } 56 int r = cur / 4; 57 int c = cur % 4; 58 if(G[r][c] == '*') { 59 for(int i = 1; i <= 4; i++) { 60 if(check(r, c, i)) { 61 G[r][c] = i + '0'; 62 row[r][i] = 1; 63 col[c][i] = 1; 64 square[s(r,c)][i] = 1; 65 dfs(cur + 1); 66 if(flag) break; 67 G[r][c] = '*'; 68 row[r][i] = 0; 69 col[c][i] = 0; 70 square[s(r,c)][i] = 0; 71 } 72 } 73 } 74 else dfs(cur + 1); 75 } 76 77 int main() { 78 // freopen("in", "r", stdin); 79 // freopen("out", "w", stdout); 80 int T; 81 scanf("%d", &T); 82 for(int _ = 1; _ <= T; _++) { 83 init(); 84 for(int i = 0; i < 4; i++) { 85 scanf("%s", G[i]); 86 } 87 for(int i = 0; i < 4; i++) { 88 for(int j = 0; j < 4; j++) { 89 if(G[i][j] != '*') { 90 row[i][G[i][j]-'0'] = 1; 91 col[j][G[i][j]-'0'] = 1; 92 square[s(i,j)][G[i][j]-'0'] = 1; 93 } 94 } 95 } 96 printf("Case #%d:\n", _); 97 dfs(0); 98 for(int i = 0; i < 4; i++) { 99 for(int j = 0; j < 4; j++) { 100 printf("%c", G[i][j]); 101 } 102 printf("\n"); 103 } 104 } 105 }
HDOJ5551 Huatuo's Medicine
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5551
本场最水,给你n个字符,让你用这n个字符排列出最小的奇数长度的回文串。2*n-1
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 int main() { 23 int T; 24 int n; 25 scanf("%d", &T); 26 for(int i = 1; i <= T; i++) { 27 scanf("%d", &n); 28 printf("Case #%d: %d\n", i, 2 * n - 1); 29 } 30 }
つづく