2010年9月17日 星期五

ACM 10443 - Rock

#include <stdio.h>

int comp(char c1, char c2)
{
if (c1 == c2) return 0;
if (c1 - c2 != 3 && c1 > c2 || c2 - c1 == 3) return -1;
return 1;
}

char reverse(char c1)
{
if (c1 == 'S') return 'R';
if (c1 == 'R') return 'P';
return 'S';
}

int main()
{
int days, row, col, caseNum;
int i, j, k, isRev;
char ch;

scanf("%d", &caseNum);
while (caseNum --)
{
scanf("%d %d %d", &row, &col, &days);
char change[days + 1][row][col + 1];
for (i = 0; i < row; i ++)
scanf("%s", change[0][i]);
for (k = 1; k <= days; k ++)
for (i = 0; i < row; i ++)
for (j = 0; j < col; j ++)
{
isRev = 0;
ch = change[k - 1][i][j];
if (i - 1 >= 0 && comp(ch, change[k - 1][i - 1][j]) == -1)
isRev = 1;
if (j - 1 >= 0 && comp(ch, change[k - 1][i][j - 1]) == -1)
isRev = 1;
if (i + 1 < row && comp(ch, change[k - 1][i + 1][j]) == -1)
isRev = 1;
if (j + 1 < col && comp(ch, change[k - 1][i][j + 1]) == -1)
isRev = 1;
if (isRev) change[k][i][j] = reverse(ch);
else change[k][i][j] = ch;
}
for (i = 0; i < row; i ++)
change[days][i][col] = '\0', printf("%s\n", change[days][i]);

if (caseNum) printf("\n");

}
return 0;
}


回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...