极角排序
作者:互联网
#include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<stack> #include<queue> #include<string> #include<stdio.h> #include<map> #define IOS ios::sync_with_stdio(false) using namespace std; const int maxn=1e6+10; typedef long long ll; typedef unsigned long long ull; struct Node{ double x,y; double val; double dis; Node(){} Node(int x_,int y_){ x=x_;y=y_; } Node operator - (const Node &p){ return Node(x-p.x,y-p.y); } double operator ^ (const Node &p){ return x*p.y-y*p.x; } }node[1010]; double cross(double x1,double y1,double x2,double y2){ return x1*y2-x2*y1; } double cmp(Node a,Node b){ Node c;c.x=0,c.y=0; double ans = (a-c)^(b-c); return ans>0; } int cmp1 (Node a,Node b){ if(a.val==b.val){ return a.dis>b.dis; } return a.val<b.val; } double PI = acos(-1.0); int main(){ int t; int cas=0; scanf("%d",&t); while(t--){ int n;scanf("%d",&n); for(int i=0;i<n;++i){ cin>>node[i].x>>node[i].y; double v = atan2(node[i].y,node[i].x); if(v<0){ v = v+2*PI; } node[i].val=v; node[i].dis=sqrt(node[i].x*node[i].x+node[i].y*node[i].y); } sort(node,node+n,cmp1); printf("case #%d:\n",cas++); for(int i=0;i<n;++i){ printf("(%.4lf,%.4lf)\n",node[i].dis,node[i].val); } } return 0; }
B. 极坐标排序 - 编程思维与实践课程模拟练习 - ECNU Online Judge
标签:Node,node,排序,return,int,double,极角,include 来源: https://www.cnblogs.com/kayiko/p/14833637.html