日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ - 1696 Space Ant(极角排序)

發布時間:2024/4/11 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ - 1696 Space Ant(极角排序) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:點擊查看

題目大意:現在有一只特殊的螞蟻,它會按照以下規則盡可能長的尋找路徑:

  • 不能回頭
  • 不能右轉
  • 只能逆時針行走
  • 現在給出n個點,輸出最長的路徑

    題目分析:既然是逆時針旋轉,那么每次只能走極角最小的一個,每次都排序找就可以了,時間復雜度是n*n*logn,極角排序的cmp函數還是用這張圖

    代碼:

    #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<queue> #include<map> #include<set> #include<sstream> using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=110;const double eps = 1e-8;int sgn(double x){if(fabs(x) < eps)return 0;if(x < 0)return -1;else return 1; }struct Point{double x,y;int id;Point(){}Point(double _x,double _y){x = _x;y = _y;}void input(){scanf("%d%lf%lf",&id,&x,&y);}bool operator < (Point b)const{return sgn(y-b.y)== 0?sgn(x-b.x)<0:y<b.y;}Point operator -(const Point &b)const{return Point(x-b.x,y-b.y);}//叉積double operator ^(const Point &b)const{return x*b.y - y*b.x;}//點積double operator *(const Point &b)const{return x*b.x + y*b.y;}//返回兩點的距離double distance(Point p){return hypot(x-p.x,y-p.y);} }point[N];double xmult(Point p0,Point p1,Point p2) {return (p1-p0)^(p2-p0); }int pos;bool cmp(Point a,Point b) {double temp=xmult(point[pos],a,b);if(sgn(temp)==0)return a.distance(point[pos])<b.distance(point[pos]);return sgn(temp)>0; }int main() { // freopen("input.txt","r",stdin); // ios::sync_with_stdio(false);int w;cin>>w;while(w--){int n;scanf("%d",&n);for(int i=0;i<n;i++){point[i].input();if(point[i]<point[0])swap(point[i],point[0]);}pos=0;for(int i=1;i<n;i++){sort(point+i,point+n,cmp);pos++;}printf("%d",n);for(int i=0;i<n;i++)printf(" %d",point[i].id);putchar('\n');}return 0; }

    ?

    總結

    以上是生活随笔為你收集整理的POJ - 1696 Space Ant(极角排序)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。