码迷,mamicode.com
首页 > 其他好文 > 详细

模拟 CSU 1562 Fun House

时间:2015-04-20 22:17:49      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

  1 /*
  2     题意:光线从 ‘*‘ 发射,遇到 ‘/‘ 或 ‘\‘ 进行反射,最后射到墙上,将 ‘x‘ 变成 ‘&‘
  3     模拟:仔细读题,搞清楚要做什么,就是i,j的移动,直到撞到墙,模拟一下一次AC,不要被题目吓怕了:)
  4 */
  5 #include <cstdio>
  6 #include <iostream>
  7 #include <algorithm>
  8 #include <stack>
  9 #include <cmath>
 10 #include <cstring>
 11 #include <vector>
 12 using namespace std;
 13 
 14 const int MAXN = 1e4 + 10;
 15 const int INF = 0x3f3f3f3f;
 16 char g[22][22];
 17 
 18 int main(void)        //CSU 1562 Fun House
 19 {
 20     //freopen ("B.in", "r", stdin);
 21 
 22     int n, m, cas = 0;
 23     while (scanf ("%d%d", &m, &n) == 2)
 24     {
 25         if (n == 0 && m == 0)    break;
 26 
 27         for (int i=0; i<n; ++i)
 28         {
 29             scanf ("%s", &g[i]);
 30         }
 31 
 32         printf ("HOUSE %d\n", ++cas);
 33 
 34         int sx = -1, sy = -1;
 35         int num = 0;
 36         for (int i=0; i<n; ++i)
 37         {
 38             for (int j=0; j<m; ++j)
 39             {
 40                 if (g[i][j] == *)
 41                 {
 42                     if (j == 0) num = 1;
 43                     else if (j == m-1)    num = 2;
 44                     else if (i == 0)    num = 3;
 45                     else if (i == n-1)    num = 4;
 46                     sx = i;    sy = j;
 47                     break;
 48                 }
 49             }
 50         }
 51 
 52         while (1)
 53         {
 54             if (num == 1)
 55             {
 56                 ++sy;
 57                 if (g[sx][sy] == /)    num = 4;
 58                 else if (g[sx][sy] == \\)    num = 3;
 59                 else if (g[sx][sy] == x)
 60                 {
 61                     g[sx][sy] = &;    break;
 62                 }
 63             }
 64             else if (num == 2)
 65             {
 66                 --sy;
 67                 if (g[sx][sy] == /)    num = 3;
 68                 else if (g[sx][sy] == \\)    num = 4;
 69                 else if (g[sx][sy] == x)
 70                 {
 71                     g[sx][sy] = &;    break;
 72                 }
 73             }
 74             else if (num == 3)
 75             {
 76                 ++sx;
 77                 if (g[sx][sy] == /)    num = 2;
 78                 else if (g[sx][sy] == \\)    num = 1;
 79                 else if (g[sx][sy] == x)
 80                 {
 81                     g[sx][sy] = &;    break;
 82                 }
 83             }
 84             else if (num == 4)
 85             {
 86                 --sx;
 87                 if (g[sx][sy] == /)    num = 1;
 88                 else if (g[sx][sy] == \\)    num = 2;
 89                 else if (g[sx][sy] == x)
 90                 {
 91                     g[sx][sy] = &;    break;
 92                 }
 93             }
 94         }
 95 
 96         for (int i=0; i<n; ++i)
 97         {
 98             for (int j=0; j<m; ++j)
 99             {
100                 printf ("%c", g[i][j]);
101             }
102             puts ("");
103         }
104     }
105 
106     return 0;
107 }
108 
109 /*
110 HOUSE 1
111 xxxxxxxxxxx
112 x../..\...x
113 x..../....x
114 *../......x
115 x.........x
116 xxxxxx&xxxx
117 HOUSE 2
118 xxxxx
119 *...&
120 x...x
121 x...x
122 xxxxx
123 HOUSE 3
124 xxxxx
125 x./\x
126 *./.x
127 x..\&
128 xxxxx
129 HOUSE 4
130 xxx*xx
131 x/...x
132 x....x
133 x/./.&
134 x\./.x
135 xxxxxx
136 HOUSE 5
137 xxxxxxxxxx
138 x.../\...x
139 x........x
140 x........x
141 &.../\..\x
142 *...\/../x
143 x........x
144 x........x
145 x...\/...x
146 xxxxxxxxxx
147 */

 

模拟 CSU 1562 Fun House

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4442609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!