蓝桥杯国赛 皮亚诺曲线距离
生活随笔
收集整理的這篇文章主要介紹了
蓝桥杯国赛 皮亚诺曲线距离
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
參考博客
題意:
題解:
這個很惡魔
本質(zhì)好說就是找規(guī)律,但是賊難寫。。
找了篇題解,做法就是大化小,將大階化為成小階,計算出離遠點的距離。。。我感覺我是寫不出來。。
挺秒的,要推公式估計要一陣子
代碼:
#include<iostream> #include<utility> #include<vector> #include<cmath>using namespace std;typedef pair < int , int > location; typedef long long ll; ll cacl(ll n,location loca){//n級皮亞諾,此時的坐標位置左下角為原點 ll pre_len=pow(3,n-1);ll total=0;location xy(loca.first/pre_len,loca.second/pre_len);ll x=loca.first,y=loca.second;ll num=0;if(xy.first==0){num=xy.second+1;}else if(xy.first==1){if(xy.second==2)num=4;else if(xy.second==1)num=5;else num=6;}else{num=7+xy.second;}total+=pre_len * pre_len * (num-1);if(n==1){return total;//結(jié)束標志 }location pre(loca);if(num==1);else if(num==2){pre=make_pair(-(x-pre_len+1),y-pre_len);}else if(num==3){pre=make_pair(x,y-2*pre_len);}else if(num==4){pre=make_pair(x-pre_len,-(y-3*pre_len+1));}else if(num==5){pre=make_pair(-(x-2*pre_len+1),-(y-2*pre_len+1));}else if(num==6){pre=make_pair(x-pre_len,-(y-pre_len+1));}else if(num==7){pre=make_pair(x-2*pre_len,y);}else if(num==8){pre=make_pair(-(x-3*pre_len+1),y-pre_len);}else{pre=make_pair(x-2*pre_len,y-2*pre_len);}return total+cacl(n-1,pre); }int main(){ll n,x1,y1,x2,y2;cin>>n>>x1>>y1>>x2>>y2;location first(x1,y1),second(x2,y2);//cout<<first.first<<endl;cout<<abs(cacl(n,first)-cacl(n,second));return 0; }總結(jié)
以上是生活随笔為你收集整理的蓝桥杯国赛 皮亚诺曲线距离的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么一根网线设置两个无线路由器两台无线路
- 下一篇: 苹果联手华为,把OPPO冲到了第六