poj今天只做了3道水题...晚上被codeforce的团队练习占去了。几个小时后就是坑爹考试T_T
poj3295 - Tautology
大意:定义了一个新的逻辑体系,判断输入的语句是否是永真式。
题解:枚举所有未知数的值。。暴力。
1 #include <stdio.h> 2 3 int a[5]; 4 char str[500]; 5 6 int type(char c) { 7 if (c == ‘K‘ || c == ‘A‘ || c == ‘C‘ || c == ‘E‘) { 8 return 2; 9 } 10 if (c == ‘N‘) { 11 return 1; 12 } 13 return 0; 14 } 15 16 int calculate(char *s, int &r) { 17 int q = type(s[0]); 18 int z1, z2; 19 int k1, k2; 20 if (q == 2) { 21 k1 = calculate(s + 1, z1); 22 k2 = calculate(s + 1 + z1, z2); 23 r = z1 + z2 + 1; 24 switch (s[0]) { 25 case ‘K‘: 26 return k1 && k2; 27 case ‘A‘: 28 return k1 || k2; 29 case ‘C‘: 30 return !k1 || k2; 31 case ‘E‘: 32 return k1 == k2; 33 } 34 } else if (q == 1) { 35 k1 = calculate(s + 1, z1); 36 r = z1 + 1; 37 return 1 - k1; 38 } 39 r = 1; 40 switch (s[0]) { 41 case ‘p‘: 42 return a[0]; 43 case ‘q‘: 44 return a[1]; 45 case ‘r‘: 46 return a[2]; 47 case ‘s‘: 48 return a[3]; 49 } 50 return a[4]; 51 } 52 53 54 int search(int w) { 55 if (w == 5) { 56 int r; 57 if (calculate(str, r) != 1) { 58 return 0; 59 } 60 return 1; 61 } 62 for (int i = 0; i < 2; i++) { 63 a[w] = i; 64 if (!search(w + 1)) { 65 return 0; 66 } 67 } 68 return 1; 69 } 70 71 int main() { 72 while (~scanf("%s", str) && str[0] != ‘0‘) { 73 printf("%s\n", search(0) ? "tautology" : "not"); 74 } 75 return 0; 76 }
poj2996 - Help Me with the Game
大意:翻译chess棋盘。比较无语的是这题最上面的行号是8,依次减小。另外输出Black方时行递减而非递增。
输入例如:
+---+---+---+---+---+---+---+---+ |.r.|:::|.b.|:q:|.k.|:::|.n.|:r:| +---+---+---+---+---+---+---+---+ |:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.| +---+---+---+---+---+---+---+---+ |...|:::|.n.|:::|...|:::|...|:p:| +---+---+---+---+---+---+---+---+ |:::|...|:::|...|:::|...|:::|...| +---+---+---+---+---+---+---+---+ |...|:::|...|:::|.P.|:::|...|:::| +---+---+---+---+---+---+---+---+ |:P:|...|:::|...|:::|...|:::|...| +---+---+---+---+---+---+---+---+ |.P.|:::|.P.|:P:|...|:P:|.P.|:P:| +---+---+---+---+---+---+---+---+ |:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.| +---+---+---+---+---+---+---+---+
对应输出:
White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
题解:纯模拟。。
1 #include <stdio.h> 2 3 char s[100]; 4 char str[2][6] = {"White", "Black"}; 5 char ch[2][7] = {"KQRBNP", "kqrbnp"}; 6 int w[2][6]; 7 int ans[2][6][65][2]; 8 char f[9][9]; 9 10 void print(int k) { 11 int flag = 0; 12 printf("%s: ", str[k]); 13 for (int i = 0; i < 6; i++) { 14 for (int j = 0; j < w[k][i]; j++) { 15 if (flag) { 16 printf(","); 17 } 18 flag = 1; 19 if (i < 5) { 20 printf("%c", ch[0][i]); 21 } 22 printf("%c%d", ans[k][i][j][1] + ‘a‘, ans[k][i][j][0] + 1); 23 } 24 } 25 } 26 27 int type(char c) { 28 for (int i = 0; i < 2; i++) 29 for (int j = 0; j < 6; j++) { 30 if (ch[i][j] == c) { 31 return i * 10 + j; 32 } 33 } 34 return -1; 35 } 36 37 int main() { 38 for (int i = 0; i < 17; i++) { 39 scanf("%s", s); 40 if (i % 2) { 41 for (int j = 0; j < 8; j++) { 42 int z = j * 4 + 2; 43 f[7 - i / 2][j] = s[z]; 44 } 45 } 46 } 47 for (int i = 0; i < 8; i++) 48 for (int j = 0; j < 8; j++) { 49 int t = type(f[i][j]); 50 if (t != -1 && t < 10) { 51 ans[0][t][w[0][t]][0] = i; 52 ans[0][t][w[0][t]++][1] = j; 53 } 54 } 55 for (int i = 7; i >= 0; i--) 56 for (int j = 0; j < 8; j++) { 57 int t = type(f[i][j]); 58 if (t > 9) { 59 t -= 10; 60 ans[1][t][w[1][t]][0] = i; 61 ans[1][t][w[1][t]++][1] = j; 62 } 63 } 64 print(0); 65 printf("\n"); 66 print(1); 67 printf("\n"); 68 }
poj2993 - Emag eht htiw Em Pleh
大意:输入同上题的输出,然后给出上题的输入。虽然题目只说倒转了2996,但不同的是Black和White可能会换顺序,妥妥的骗人了= =
题解:纯模拟
1 #include <stdio.h> 2 #include <string.h> 3 4 char ch[2][7] = {"KQRBNP", "kqrbnp"}; 5 char s[20][50]; 6 char r[1000]; 7 8 int type(char c) { 9 for (int i = 0; i < 6; i++) { 10 if (ch[0][i] == c) { 11 return i; 12 } 13 } 14 return -1; 15 } 16 17 int main() { 18 for (int i = 0; i < 17; i++) { 19 if (!(i % 2)) { 20 for (int j = 0; j < 33; j++) { 21 s[i][j] = j % 4 ? ‘-‘ : ‘+‘; 22 } 23 } else { 24 for (int j = 0; j < 33; j++) { 25 if (j % 4) { 26 s[i][j] = (j / 4 % 2) ^ (i / 2 % 2)? ‘:‘ : ‘.‘; 27 } else { 28 s[i][j] = ‘|‘; 29 } 30 } 31 } 32 s[i][33] = ‘\0‘; 33 } 34 for (int i = 0; i < 2; i++) { 35 scanf("%s", r); 36 int u = r[0] == ‘B‘; 37 scanf("%s", r); 38 int n = strlen(r); 39 r[n] = ‘,‘; 40 int cun[2]; 41 int now = 0, d = 5; 42 for (int j = 0; j <= n; j++) { 43 int t = type(r[j]); 44 if (r[j] == ‘,‘) { 45 s[cun[1]][cun[0]] = ch[u][d]; 46 now = 0; 47 d = 5; 48 } else { 49 if (t == -1) { 50 cun[now] = now ? (‘8‘ - r[j]) * 2 + 1 : (r[j] - ‘a‘) * 4 + 2; 51 now++; 52 } else { 53 d = t; 54 } 55 } 56 } 57 } 58 for (int i = 0; i < 17; i++) { 59 printf("%s\n", s[i]); 60 } 61 return 0; 62 }
poj训练计划-3(3295/2993/2996),布布扣,bubuko.com
原文:http://www.cnblogs.com/nilmo/p/3571912.html