poj3889 Fractal Streets

分形图,就是找规律。。。

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
P get_(int n,int pos){
    P ret;
    if(!n){ret.first=0;ret.second=0;return ret;}
    ll k=1<<(2*n-2),k2=1<<(n-1);
    P t=get_(n-1,pos%k);
    int opt=pos/k;
    if(opt==0)ret.first=t.second,ret.second=t.first;
    else if(opt==1)ret.first=t.first,ret.second=t.second+k2;
    else if(opt==2)ret.first=t.first+k2,ret.second=t.second+k2;
    else ret.first=2*k2-t.second-1,ret.second=k2-t.first-1;
    return ret;
}
double dis(ll x1,ll y1,ll x2,ll y2){return sqrt((double)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));} 
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        ll n,h,o;
        scanf("%lld%lld%lld",&n,&h,&o);
        h--;o--;
        P a1=get_(n,h),a2=get_(n,o);
        printf("%.0lf\n",dis(a1.first,a1.second,a2.first,a2.second)*10.0);
    }
    return 0;
}
View Code

 

posted @ 2018-12-17 10:10  lqsno1  阅读(91)  评论(0编辑  收藏  举报