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

HRBUST - 2347 - 递归画图 - vj大一上寒假训练2.11

时间:2019-02-12 00:33:13      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:技术   坐标   pre   const   void   fine   printf   namespace   png   

技术图片

 

思路:利用坐标dfs搜索.

注意:1,初始化.2,坐标实时更新(x,y)

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define ll long long
 5 using namespace std;
 6 const int amn=1e3+10;
 7 int a,b,con=0;
 8 char mp[amn][amn];char ans[amn][amn];
 9 void solve(int x,int y,int tot)
10 {
11     if(tot==a)
12     {
13         //cout<<"!"<<endl<<x<<" "<<y<<endl<<"!!"<<endl;
14         for(int k=x;k<tot+x;k++)
15         {
16             for(int l=y;l<tot+y;l++)
17             {
18                 if(mp[k-x][l-y]==*)
19                     ans[k][l]=*;
20             }
21         }
22 
23          //con++;
24         return;
25     }
26     int tes=tot/a;
27     for(int i=x; i<tot+x; i+=tes)///注意这里i=x,j=y,找了好久才发现错误....
28     {
29         for(int j=y; j<tot+y; j+=tes)
30         {
31             if(mp[(i-x)/tes][(j-y)/tes]==*)
32             {
33                 //cout<<i<<" "<<j<<endl;
34                 solve(i,j,tes);
35             }
36 
37         }
38     }
39 }
40 int main()
41 {
42 
43     while(~scanf("%d%d",&a,&b))
44     {
45 
46         for(int i=0; i<a; i++)
47         {
48             getchar();
49             for(int j=0;j<a;j++)
50             scanf("%c",&mp[i][j]);
51         }
52         //cout<<"!\n";
53         int c=1;///注意初始化
54         for(int i=1;i<=b;i++)c*=a;
55         //cout<<c<<endl;
56         for(int i=0; i<c; i++)
57             for(int j=0; j<c; j++)
58             ans[i][j]= ;
59         //cout<<"!!\n";
60         solve(0,0,c);
61         //cout<<con<<endl;
62         //cout<<"!!!!\n";
63         for(int i=0; i<c; i++)
64         {
65             for(int j=0; j<c; j++)
66             {
67                 printf("%c",ans[i][j]);
68             }
69             
70             printf("\n");
71         }
72 
73         puts("");
74         //cout<<"!!!!!\n";
75     }
76 }

 

HRBUST - 2347 - 递归画图 - vj大一上寒假训练2.11

标签:技术   坐标   pre   const   void   fine   printf   namespace   png   

原文地址:https://www.cnblogs.com/brainm/p/10363596.html

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