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

Paper Folding UVA - 177 模拟+思路+找规律

时间:2018-11-03 02:21:21      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:cout   一半   ble   找规律   pac   vector   href   tar   txt   

题目:题目链接

思路:1到4是很容易写出来的,我们先考虑这四种情况的绘制顺序

  1:ru

  2:rulu

  3:rululdlu

  4:rululdluldrdldlu

  不难发现,相较于前一行,每一次增加一倍数量,并且增加的这部分前一半和原来正好相反,后一半相同,根据这一性质,预处理出极端情况13的解答字符串,然后绘制即可,注意控制行尾空格

AC代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <string>
 6 #include <vector>
 7 #include <map>
 8 #include <set>
 9 #include <queue>
10 #include <deque>
11 
12 #define FRER() freopen("in.txt", "r", stdin)
13 #define FREW() freopen("out.txt", "w", stdout)
14 
15 #define INF 0x3f3f3f3f
16 
17 using namespace std;
18 
19 char ans[10000], _map[20000][20000];
20 int _max[20000];
21 
22 char cal(char ch) {
23     if(ch == l)
24         return r;
25     if(ch == r)
26         return l;
27     if(ch == u)
28         return d;
29     if(ch == d)
30         return u;
31 }
32 
33 int main()
34 {
35     //FRER();
36     //FREW();
37     ios::sync_with_stdio(0);
38     cin.tie(0);
39     
40     ans[0] = r;
41     ans[1] = u;
42     for(int i = 2; i < 14; ++i) {
43         int n = 1 << (i - 2), m = 1 << (i - 1);        
44         for(int j = 0; j < n; ++j) {
45             ans[j + m] = cal(ans[j]);
46         }
47         for(int j = 0; j < 1 << (i - 2); ++j) {
48             ans[j + m + n] = ans[j + n];
49         }
50     }
51     ans[1 << 13] = \0;
52     cout << ans << endl;
53     int n;
54     while(cin >> n, n) {
55         memset(_map, 0, sizeof(_map));
56         memset(_max, 0, sizeof(_max));
57         int minl = 10000, maxl = 10000, minc = 10000, maxc = 10000;
58         int l = 10000, c = 10000;
59         int m = 1 << n;
60         _max[10000] = 10000;
61         _map[l][c] = _;
62         for(int i = 1; i < m; ++i) {
63             if(ans[i - 1] == l) 
64                 --c;
65             else if(ans[i - 1] == r)
66                 ++c;
67             else if(ans[i - 1] == u)
68                 --l;
69             
70             if(ans[i] == u) {
71                 
72                 _map[l][c] = |;
73             }
74             else if(ans[i] == d) {
75                 ++l;
76                 _map[l][c] = |;
77             }
78             else if(ans[i] == l) {
79                 --c;
80                 _map[l][c] = _;
81             }
82             else {
83                 ++c;
84                 _map[l][c] = _;
85             }
86             minl = min(minl, l);
87             minc = min(minc, c);
88             maxl = max(maxl, l);
89             _max[l] = max(_max[l], c);
90         }
91         for(int i = minl; i <= maxl; ++i) {
92             for(int j = minc; j <= _max[i]; ++j) 
93                 cout << (_map[i][j] == 0 ?   : _map[i][j]);
94             cout << endl;
95         }
96         cout << ^ << endl;
97     }
98     return 0;
99 }

 

Paper Folding UVA - 177 模拟+思路+找规律

标签:cout   一半   ble   找规律   pac   vector   href   tar   txt   

原文地址:https://www.cnblogs.com/fan-jiaming/p/9899115.html

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