题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3839
题目大意:画脸。。每张脸是上一个脸倒过来加上眼睛。。
注意n<8时停止,被这个坑惨了- -以为是0停止。。
递归,然后去推坐标公式。。
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #include <vector> 5 using namespace std; 6 typedef long long LL; 7 typedef pair<int,int> PII; 8 typedef vector<int> vec; 9 typedef vector<vec> mat; 10 #define AA first 11 #define BB second 12 13 char s[2000][2000]; 14 15 void solve(int x,int y,int si,bool seq){ 16 // printf("[solve]:x=%d,y=%d,si=%d\n",x,y,si); 17 if( si==8 ){ 18 // return; 19 if( seq ){ 20 for(int i=x;i<x+si;i++){ 21 if( i==x||i==x+si-1){ 22 for(int j=y;j<y+si;j++){ 23 s[i][j] = ‘*‘; 24 } 25 } else { 26 for(int j=y;j<y+si;j++){ 27 if( (i>=x+1&&i<=x+3)&&(j<=y+2||(j>=y+5&&j<=y+7)) ) s[i][j] = ‘*‘; 28 else if( i==x+4&&(j==y||(j>=y+2&&j<=y+5)||j==y+7) ) s[i][j] = ‘*‘; 29 else if( (i==x+5||i==x+6)&&(j==y||j==y+7||j==y+2||j==y+5) ) s[i][j] = ‘*‘; 30 else s[i][j] = ‘ ‘; 31 } 32 } 33 } 34 } else { 35 for(int i=x;i>x-si;i--){ 36 if( i==x||i==x-si+1 ){ 37 for(int j=y;j>y-si;j--){ 38 s[i][j] = ‘*‘; 39 } 40 } else { 41 for(int j=y;j>y-si;j--){ 42 if( (i<=x-1&&i>=x-3)&&(j>=y-2||(j<=y-5&&j>=y-7)) ) s[i][j] = ‘*‘; 43 else if( i==x-4&&(j==y||(j<=y-2&&j>=y-5)||j==y-7) ) s[i][j] = ‘*‘; 44 else if( (i==x-5||i==x-6)&&(j==y||j==y-7||j==y-2||j==y-5) ) s[i][j] = ‘*‘; 45 else s[i][j] = ‘ ‘; 46 } 47 } 48 } 49 } 50 return; 51 } 52 if( seq ){ 53 for(int i=x;i<x+si;i++ ){ 54 if( i==x||i==x+si-1 ){ 55 for(int j=y;j<y+si;j++){ 56 s[i][j] = ‘*‘; 57 } 58 } else { 59 for(int j=y;j<y+si;j++){ 60 if( j==y||j==y+si-1 ) s[i][j] = ‘*‘; 61 else if( (i==x+si/8||i==x+si/8+si/4)&&((j>=y+si/8&&j<=y+si/8+si/4-1)||(j<=y+si-si/8-1&&j>=y+si-si/8-si/4)) ) { 62 s[i][j] = ‘*‘; 63 } 64 else if( (i>x+si/8&&i<x+si/8+si/4)&&(j==y+si/8||j==y+si/8+si/4-1||j==y+si-si/8-1||j==y+si-si/8-si/4) ) s[i][j] = ‘*‘; 65 else s[i][j] = ‘ ‘; 66 } 67 } 68 } 69 solve(x+si-1,y+si-si/4-1,si/2,!seq); 70 } else { 71 for(int i=x;i>x-si;i-- ){ 72 if( i==x||i==x-si+1 ){ 73 for(int j=y;j>y-si;j--){ 74 s[i][j] = ‘*‘; 75 } 76 } else { 77 for(int j=y;j>y-si;j--){ 78 if( j==y||j==y-si+1 ) s[i][j] = ‘*‘; 79 else if( (i==x-si/8||i==x-si/8-si/4)&&((j<=y-si/8&&j>=y-si/8-si/4+1)||(j>=y-si+si/8+1&&j<=y-si+si/8+si/4)) ) { 80 s[i][j] = ‘*‘; 81 } 82 else if( (i<x-si/8&&i>x-si/8-si/4)&&(j==y-si/8||j==y-si/8-si/4+1||j==y-si+si/8+1||j==y-si+si/8+si/4) ) s[i][j] = ‘*‘; 83 else s[i][j] = ‘ ‘; 84 } 85 } 86 } 87 solve(x-si+1,y-si+si/4+1,si/2,!seq); 88 } 89 } 90 91 int n; 92 93 int main(){ 94 while( ~scanf("%d",&n) ){ 95 if(n < 8)break; 96 solve(0,0,n,true); 97 for(int i=0;i<n;i++){ 98 s[i][n] = ‘\0‘; 99 //for(int j=0;j<n;j++){ 100 printf("%s\n",s[i]); 101 // } 102 // puts(""); 103 } 104 puts(""); 105 } 106 // solve(31,31,32,false); 107 108 return 0; 109 }
时间: 2024-10-05 05:01:56