Zoj--3839(模拟)
2014-11-30 20:10:06
思路:zoj11月月赛签到题,一开始脑抽写了200+行WA,精简到100行左右A掉了。其实就是构造,算好第i幅图再去算i+1幅图,计算好几个关键点很重要。
1 /************************************************************************* 2 > File Name: J.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Sun 30 Nov 2014 01:41:11 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <vector> 13 #include <map> 14 #include <set> 15 #include <stack> 16 #include <queue> 17 #include <iostream> 18 #include <algorithm> 19 using namespace std; 20 #define lp (p << 1) 21 #define rp (p << 1|1) 22 #define getmid(l,r) (l + (r - l) / 2) 23 #define MP(a,b) make_pair(a,b) 24 typedef long long ll; 25 const int INF = 1 << 30; 26 27 char g3[20][20] = {"********","*** ***","*** ***","*** ***","* **** *", 28 "* * * *","* * * *","********"}; 29 char g[7][1030][1030]; 30 int n; 31 int m,A,B,C,a,b,c,d,e,f; 32 33 void Mod(int k){ 34 int mm = 1; 35 while(k--) mm *= 2; 36 A = a = mm / 8; 37 B = A + mm / 4; 38 C = mm / 2; 39 b = B - 1; 40 c = mm - B; 41 d = mm - 1 - a; 42 e = mm / 4; 43 f = mm - 1 - e; 44 } 45 46 int main(){ 47 for(int tt = 4; tt <= 10; ++tt){ 48 Mod(tt); 49 m = 1 << tt; 50 int t = tt - 4; 51 for(int i = 0; i < m; ++i) g[t][0][i] = g[t][m - 1][i] = '*'; 52 for(int i = 1; i < m - 1; ++i){ 53 g[t][i][0] = g[t][i][m - 1] = '*'; 54 for(int j = 1; j < m - 1; ++j) g[t][i][j] = ' '; 55 } 56 for(int i = a; i <= b; ++i) g[t][A][i] = g[t][B][i] = '*'; 57 for(int i = c; i <= d; ++i) g[t][A][i] = g[t][B][i] = '*'; 58 for(int i = A; i <= B; ++i) g[t][i][a] = g[t][i][b] = g[t][i][c] = g[t][i][d] = '*'; 59 if(t == 0){ 60 for(int i = C; i < m; ++i){ 61 for(int j = e; j <= f; ++j){ 62 g[t][i][j] = g3[m / 2 - 1 - (i - C)][j - e]; 63 } 64 } 65 } 66 else{ 67 for(int i = C; i < m; ++i){ 68 for(int j = e; j <= f; ++j){ 69 g[t][i][j] = g[t - 1][m / 2 - 1 - (i - C)][j - e]; 70 } 71 } 72 } 73 } 74 while(scanf("%d",&n) != EOF){ 75 if(n < 8) break; 76 if(n == 8) 77 for(int i = 0; i < n; ++i){ 78 for(int j = 0; j < n; ++j){ 79 printf("%c",g3[i][j]); 80 } 81 puts(""); 82 } 83 else{ 84 int cnt = 0,tmp = n; 85 while(tmp != 1){ 86 cnt++; 87 tmp /= 2; 88 } 89 cnt -= 4; 90 for(int i = 0; i < n; ++i){ 91 for(int j = 0; j < n; ++j){ 92 printf("%c",g[cnt][i][j]); 93 } 94 puts(""); 95 } 96 } 97 puts(""); 98 } 99 return 0; 100 }