pku 2339 Rock, Scissors, Paper 水题啊水题

由于是水题,就描述题意然后贴代码了。。
有3种生物R,S,P,占领了网格图中的某些格子,每天,3种生物在交界处打架,打赢的在凌晨将打输的驱逐出那个格子,并且占领那个格子。问K天后网格图中的状况。
 1 # include <cstdio>
 2 # include <cstring>
 3 # define legal(a,b) ((a)>=0&&(a)<r&&(b)>=0&&(b)<c)
 4 using namespace std;
 5 char map[105][105];
 6 char tmp[105][105];
 7 int main()
 8 {
 9     int testcase;
10     scanf("%d",&testcase);
11     while(testcase--)
12     {
13         int r,c,n;
14         scanf("%d%d%d",&r,&c,&n);
15         for(int i=0;i<r;i++)
16           scanf("%s",map[i]);
17         for(int i=1;i<=n;i++)
18         {
19             memcpy(tmp,map,sizeof(map));
20             for(int ii=0;ii<r;ii++)
21               for(int jj=0;jj<c;jj++)
22                  switch(map[ii][jj])
23                  {
24                     case 'R':
25                          if(legal(ii-1,jj)&&map[ii-1][jj]=='P')
26                             tmp[ii][jj]='P';
27                          if(legal(ii+1,jj)&&map[ii+1][jj]=='P')
28                             tmp[ii][jj]='P';
29                          if(legal(ii,jj+1)&&map[ii][jj+1]=='P')
30                             tmp[ii][jj]='P';
31                          if(legal(ii,jj-1)&&map[ii][jj-1]=='P')
32                             tmp[ii][jj]='P';
33                          break;
34                     case 'S':
35                          if(legal(ii-1,jj)&&map[ii-1][jj]=='R')
36                             tmp[ii][jj]='R';
37                          if(legal(ii+1,jj)&&map[ii+1][jj]=='R')
38                             tmp[ii][jj]='R';
39                          if(legal(ii,jj+1)&&map[ii][jj+1]=='R')
40                             tmp[ii][jj]='R';
41                          if(legal(ii,jj-1)&&map[ii][jj-1]=='R')
42                             tmp[ii][jj]='R';
43                          break;
44                     case 'P':
45                          if(legal(ii-1,jj)&&map[ii-1][jj]=='S')
46                             tmp[ii][jj]='S';
47                          if(legal(ii+1,jj)&&map[ii+1][jj]=='S')
48                             tmp[ii][jj]='S';
49                          if(legal(ii,jj+1)&&map[ii][jj+1]=='S')
50                             tmp[ii][jj]='S';
51                          if(legal(ii,jj-1)&&map[ii][jj-1]=='S')
52                             tmp[ii][jj]='S';
53                          break;
54                  };
55             memcpy(map,tmp,sizeof(map));
56         }
57         for(int i=0;i<r;i++)
58            printf("%s\n",map[i]);
59         printf("\n");
60     }
61     //scanf("%d",&testcase);
62     return 0;
63 }
64 


posted on 2010-10-22 02:04 yzhw 阅读(172) 评论(0)  编辑 收藏 引用 所属分类: simple problem~


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年11月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

公告

统计系统

留言簿(1)

随笔分类(227)

文章分类(2)

OJ

最新随笔

搜索

积分与排名

最新评论

阅读排行榜