Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
有没有这样写的,同志们举手呀#include <stdio.h> #include <string.h> int r, c, n; char s[2][0x80][0x80]; // 用两倍空间来回更新 char t[128]; // 其实就是个hash,将三个字母一一对应进去,就不用每次判断了 inline void update(int k, int i, int j) { char c = t[s[k][i][j]]; // 判断上下左右有没有相克的 if (s[k][i-1][j] == c || s[k][i+1][j] == c || s[k][i][j-1] == c || s[k][i][j+1] == c) s[(k + 1) & 1][i][j] = c; else s[(k + 1) & 1][i][j] = s[k][i][j]; } int main() { int i, cs, j, k; t['R'] = 'P'; t['P'] = 'S'; t['S'] = 'R'; memset(s, 0, sizeof(s)); scanf("%d", &cs); while (cs--) { scanf("%d %d %d", &r, &c, &n); for (i = 1; i <= r; i++) scanf(" %s", s[0][i] + 1); //从下标1处开始存取,方便比较 for (k = 0; k < n; k++) { int p = k & 1; for (i = 1; i <= r; i++) for (j = 1; j <= c; j++) update(p, i, j); // 对每个点进行更新 } k &= 1; for (i = 1; i <= r; i++) printf("%s\n", s[k][i] + 1); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator