POJ3889 Fractal Streets

Source: Internet
Author: User

My understanding of Divide and conquer: https://www.cnblogs.com/AKMer/p/9728574.html

Topic Portal: http://poj.org/problem?id=3889

It is said that this kind of graph is called Fractal chart ... Generally find the law is good, like I this dish chicken will only make a small change in the fractal map.

Time complexity:\ (O (can over) \)

Space complexity:\ (O (1) \)

The code is as follows:

#include <cmath> #include <cstdio>using namespace std;    int read () {int X=0,f=1;char ch=getchar (); for (;ch< ' 0 ' | |    Ch> ' 9 '; Ch=getchar ()) if (ch== '-') f=-1;    for (; ch>= ' 0 ' &&ch<= ' 9 '; Ch=getchar ()) x= (x<<1) + (x<<3) +ch-' 0 '; return x*f;}    struct Fuckpps {int x, y;    Fuckpps () {} fuckpps (int _x,int _y) {x=_x,y=_y; }};            Fuckpps Find (int n,int angle,int ID) {if (n==1) {if (angle==0) {if (id==1) return Fuckpps (n);            if (id==2) return Fuckpps ();            if (id==3) return Fuckpps (2,2);        if (id==4) return Fuckpps (2,1);            } if (angle==1) {if (id==1) return Fuckpps (n);            if (id==2) return Fuckpps (2,1);            if (id==3) return Fuckpps (2,2);        if (id==4) return Fuckpps ();            } if (angle==2) {if (id==1) return Fuckpps (2,2);            if (id==2) return Fuckpps (2,1);            if (id==3) return Fuckpps (); if (id==4) return Fuckpps ();            } if (angle==3) {if (id==1) return Fuckpps (2,2);            if (id==2) return Fuckpps ();            if (id==3) return Fuckpps ();        if (id==4) return Fuckpps (2,1);    }} Fuckpps Res;    int a=1<< (n-1), b=a*2,c=a*3;        if (angle==0) {if (id<=a) res=find (N-1,1,id);            if (id>a&&id<=b) {res=find (n-1,0,id-a);        res.y+=1<< (n-1);            } if (id>b&&id<=c) {res=find (n-1,0,id-b);            res.x+=1<< (n-1);        res.y+=1<< (n-1);            } if (id>c) {res=find (n-1,3,id-c);        res.x+=1<< (n-1);        }} if (Angle==1) {if (id<=a) res=find (N-1,0,id);            if (id>a&&id<=b) {res=find (n-1,1,id-a);        res.x+=1<< (n-1);            } if (id>b&&id<=c) {res=find (n-1,1,id-b);            res.x+=1<< (n-1); res.y+=1<< (n1);            } if (id>c) {res=find (n-1,2,id-c);        res.y+=1<< (n-1);            }} if (angle==2) {if (id<=a) {res=find (n-1,3,id);            res.x+=1<< (n-1);        res.y+=1<< (n-1);            } if (id>a&&id<=b) {res=find (n-1,2,id-a);        res.x+=1<< (n-1);        } if (Id>b&&id<=c) res=find (n-1,2,id-b);            if (id>c) {res=find (n-1,1,id-c);        res.y+=1<< (n-1);            }} if (angle==3) {if (id<=a) {res=find (n-1,2,id);            res.x+=1<< (n-1);        res.y+=1<< (n-1);            } if (id>a&&id<=b) {res=find (n-1,3,id-a);        res.y+=1<< (n-1);        } if (Id>b&&id<=c) res=find (n-1,3,id-b);            if (id>c) {res=find (n-1,0,id-c);        res.x+=1<< (n-1); }} return res;} Big disgusting sub-situation discussion divide the treatment int ABS (inT A,int b) {if (a>b) return a-A; return b-a;} int sqr (int a) {return a*a;}    int main () {int t=read ();        while (t--) {int n=read (), A=read (), B=read ();        Fuckpps A1=find (N,0,a), A2=find (N,0,B);        Double gey=sqrt (SQR (ABS (a1.x,a2.x)) +SQR (ABS (A1.Y,A2.Y)));        int Ans=trunc (10*gey+0.5);    printf ("%d\n", ans); } return 0;}

POJ3889 Fractal Streets

Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.