女装网站建设费用预算,制作网页需要什么技术,平台网站建设网站,wordpress快速汉化主题http://lx.lanqiao.org/problem.page?gpidT125 历届试题 兰顿蚂蚁 时间限制#xff1a;1.0s 内存限制#xff1a;256.0MB问题描述兰顿蚂蚁#xff0c;是于1986年#xff0c;由克里斯兰顿提出来的#xff0c;属于细胞自动机的一种。平面上的正方形格子被填上黑色或白色… http://lx.lanqiao.org/problem.page?gpidT125 历届试题 兰顿蚂蚁 时间限制1.0s 内存限制256.0MB 问题描述 兰顿蚂蚁是于1986年由克里斯·兰顿提出来的属于细胞自动机的一种。 平面上的正方形格子被填上黑色或白色。在其中一格正方形内有一只“蚂蚁”。 蚂蚁的头部朝向为上下左右其中一方。 蚂蚁的移动规则十分简单 若蚂蚁在黑格右转90度将该格改为白格并向前移一格 若蚂蚁在白格左转90度将该格改为黑格并向前移一格。 规则虽然简单蚂蚁的行为却十分复杂。刚刚开始时留下的路线都会有接近对称像是会重复但不论起始状态如何蚂蚁经过漫长的混乱活动后会开辟出一条规则的“高速公路”。 蚂蚁的路线是很难事先预测的。 你的任务是根据初始状态用计算机模拟兰顿蚂蚁在第n步行走后所处的位置。 输入格式 输入数据的第一行是 m n 两个整数3 m, n 100表示正方形格子的行数和列数。 接下来是 m 行数据。 每行数据为 n 个被空格分开的数字。0 表示白格1 表示黑格。 接下来是一行数据x y s k, 其中x y为整数表示蚂蚁所在行号和列号行号从上到下增长列号从左到右增长都是从0开始编号。s 是一个大写字母表示蚂蚁头的朝向我们约定上下左右分别用UDLR表示。k 表示蚂蚁走的步数。 输出格式 输出数据为两个空格分开的整数 p q, 分别表示蚂蚁在k步后所处格子的行号和列号。 样例输入 5 60 0 0 0 0 00 0 0 0 0 00 0 1 0 0 00 0 0 0 0 00 0 0 0 0 02 3 L 5 样例输出 1 3 样例输入 3 30 0 01 1 11 1 11 1 U 6 样例输出 0 0 分析 直接模拟路径和蚂蚁的坐标。 AC代码 1 #include stdio.h2 #include algorithm3 #include iostream4 #include string.h5 #include string6 #include math.h7 #include stdlib.h8 #include queue9 #include stack
10 #include set
11 #include map
12 #include list
13 #include iomanip
14 #include vector
15 #pragma comment(linker, /STACK:1024000000,1024000000)
16 #pragma warning(disable:4786)
17
18 using namespace std;
19
20 const int INF 0x3f3f3f3f;
21 const int Max 10000 10;
22 const double eps 1e-8;
23 const double PI acos(-1.0);
24 int a[110][110];
25
26 void run(int x , int y , char str , int k)
27 {
28 if(k 0)
29 printf(%d %d\n, x , y);
30 else
31 {
32 k --;
33 if(a[x][y] 0)
34 {
35 a[x][y] 1;
36 if(str U)
37 run(x , y - 1 , L , k);
38 else if(str D)
39 run(x , y 1 , R , k);
40 else if(str L)
41 run(x 1, y , D , k);
42 else
43 run(x - 1 , y , U , k);
44 }
45 else
46 {
47 a[x][y] 0;
48 if(str U)
49 run(x , y 1 , R , k);
50 else if(str D)
51 run(x , y - 1 , L , k);
52 else if(str L)
53 run(x - 1, y , U , k);
54 else
55 run(x 1 , y , D , k);
56 }
57 }
58 }
59
60 int main()
61 {
62 int i , j , n , m , x , y , k;
63 char s;
64 scanf(%d%d,n,m);
65 for(i 0;i n;i )
66 for(j 0;j m;j )
67 scanf(%d,a[i][j]);
68 scanf(%d %d %c %d, x , y , s , k);
69 run(x , y , s , k);
70 return 0;
71 } View Code 转载于:https://www.cnblogs.com/jeff-wgc/p/4450887.html