Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <cmath>
- #define DMAX 730
- using namespace std;
- vector <vector<bool> > a(DMAX);
- int n,p3lan;
- /// Functia care initializeaza "matricea":
- void init()
- {
- for (int i=1;i<DMAX;++i)
- a[i].resize(DMAX);
- }
- /// Functia recursiva:
- void mat3(int x,int y,int p3lan)
- {
- int pe3=p3lan/3; /// "Umplem" cu 1 patratul din mijloc:
- for(int i=x+pe3;i<=x+2*pe3-1;++i)
- for(int j=y+pe3;j<=y+2*pe3-1;++j)
- a[i][j]=true;
- /// Dupa ce am format patrate de lungime minima (1), ne oprim:
- if (pe3==1)
- return;
- /// Umplem cele 8 patrate:
- mat3(x , y , pe3);
- mat3(x , y + pe3, pe3);
- mat3(x , y + 2 * pe3, pe3);
- mat3(x + pe3, y , pe3);
- mat3(x + pe3, y + 2 * pe3, pe3);
- mat3(x + 2 * pe3, y , pe3);
- mat3(x + 2 * pe3, y + pe3, pe3);
- mat3(x + 2 * pe3, y + 2 * pe3, pe3);
- }
- int main()
- {
- ifstream f("sierpinski.in");
- f>>n;
- f.close();
- p3lan=pow(3, n);
- init();
- mat3(1,1,p3lan);
- ofstream g("sierpinski.out");
- for(int i=1;i<=p3lan;++i)
- {
- for(int j=1;j<=p3lan;++j)
- g<<a[i][j]<<' ';
- g<<'\n';
- }
- g.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment