Question Link
A piece of paper, which is folded from right to left each time. After the discount, it is opened, so that each crease is naturally 90 degrees. Output shape.
Idea: Simulate discount ...... Each fold is imagined as dividing a piece of paper into a front and a back. Maintain the left and direction, and then output. There are a lot of details.
Code:
# Include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> using namespace STD; # define N (1 <13) + 10 struct paper {int L, R; bool isface; paper () {} paper (INT _ L, int _ r, bool is): L (_ L ), R (_ r), isface (is) {}} paper [N]; int data [N]; int pp; void flod (Paper & now) {int mid = (now. L + now. r)/2; data [Mid] = now. isface? 1:-1; // printf ("% d % C % d \ n", now. l, "^ V" [DATA [Mid] = 1], now. r); If (now. isface) {paper [pp ++] = paper (MID, now. R ,! Now. isface); now. R = mid;} else {paper [pp ++] = paper (MID, now. r, now. isface); now. R = mid; now. isface =! Now. isface ;}} struct point {int X, Y; int way; point (INT x = 0, int y = 0, int way =-1): x (x ), Y (Y), way (way) {}} point [N]; Enum {R, U, L, d}; char mat [2000] [2000]; void showgraph (INT end) {point [0] = point (, R); // printf ("% d, % d, % C \ n, "rcould" [R]); int lmost = 0; int umost = 0; int rmost = 0; int dmost = 0; For (INT I = 1; I <end; I ++) {int way = (point [I-1]. way + data [I] + 4) % 4; int x = point [I-1]. x; int y = Po Int [I-1]. y; // details: Find the current location switch (point [I-1]. way) {Case R: Y + = 1; break; case l: Y-= 1; break; Case U: X-= 1; break; Case D: break ;} switch (way) {Case R: Y + = 1; break; case l: Y-= 1; break; Case U: break; Case D: x + = 1; break;} Point [I] = point (X, Y, way); // printf ("% d, % d, % C \ n", x, y, "rcould" [way]); umost = min (umost, x); dmost = max (dmost, x); lmost = min (lmost, y ); rmost = max (rmost, Y );} // Printf ("% d \ n", umost, lmost, rmost, dmost); memset (MAT ,'', sizeof (MAT); For (INT I = 0; I <end; I ++) {mat [point [I]. x-umost] [point [I]. y-lmost] = (point [I]. way = L | point [I]. way = r )? '_': '|';} Dmost = dmost-umost; rmost = rmost-lmost; For (INT I = 0; I <= dmost; I ++) {mat [I] [rmost + 1] = 0; int P = rmost; while (MAT [I] [p] = '') mat [I] [p --] = 0; printf ("% s \ n", mat [I]);} puts ("^ "); // printf ("% d \ n", umost, lmost, rmost, dmost);} int main () {int N; while (scanf ("% d", & N )! = EOF) {If (n = 0) break; pp = 0; paper [pp ++] = paper (0, 1 <n, true); memset (data, -1, sizeof (data); For (INT I = 0; I <n; I ++) {int nowpp = pp; For (Int J = 0; j <nowpp; j ++) {flod (paper [J]) ;}}// for (INT I = 1; I <(1 <n ); I ++) {// printf ("% C", "^ V" [DATA [I] = 1]); //} puts (""); showgraph (1 <n) ;}return 0 ;}
Va 177: Paper Folding (simulate Grade D)