• 叉积判断 POJ1696


     1 // 叉积判断 POJ1696
     2 
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <cstring>
     6 #include <cstdio>
     7 #include <vector>
     8 #include <cmath>
     9 #include <map>
    10 using namespace std;
    11 #define LL long long
    12 typedef pair<int,int> pii;
    13 const double inf = 123456789012345.0;
    14 const int MOD = 998244353;
    15 const int N = 2e5+10;
    16 const int maxx = 200010; 
    17 #define clc(a,b) memset(a,b,sizeof(a))
    18 const double eps = 1e-8;
    19 void fre() {freopen("in.txt","r",stdin);}
    20 void freout() {freopen("out.txt","w",stdout);}
    21 inline int read() {int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch=getchar();}while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}return x*f;}
    22 
    23 int sgn(double x){
    24     if(fabs(x) < eps)return 0;
    25     if(x < 0)return -1;
    26     else return 1;
    27 }
    28 
    29 struct Point{
    30     double x,y;
    31     int index;
    32     Point(){}
    33     Point(double _x,double _y){
    34         x = _x;y = _y;
    35     }
    36     Point operator -(const Point &b)const{
    37         return Point(x - b.x,y - b.y);
    38     }
    39     double operator ^(const Point &b)const{
    40         return x*b.y - y*b.x;
    41     }
    42     double operator *(const Point &b)const{
    43         return x*b.x + y*b.y;
    44     }
    45 };
    46 
    47 double dist(Point a,Point b){
    48     return sqrt((a-b)*(a-b));
    49 }
    50 
    51 int pos;
    52 Point p[110];
    53 bool cmp(Point a,Point b){
    54     double tmp=(a-p[pos])^(b-p[pos]);
    55     if(sgn(tmp)==0){
    56         return dist(a,p[pos])<dist(b,p[pos]);
    57     }
    58     else if(sgn(tmp)<0) return false;
    59     else return true;
    60 }
    61 
    62 int main(){
    63     int T,n;
    64     scanf("%d",&T);
    65     while(T--){
    66         scanf("%d",&n);
    67         for(int i=0;i<n;i++){
    68             scanf("%d%lf%lf",&p[i].index,&p[i].x,&p[i].y);
    69             if(p[i].y<p[0].y||(p[i].y==p[0].y&&p[i].x<p[0].x)){
    70                 swap(p[i],p[0]);
    71             }
    72         }
    73         pos=0;
    74         for(int i=0;i<n;i++){
    75             sort(p+i,p+n,cmp);
    76             pos++;
    77         }
    78         printf("%d",n);
    79         for(int i=0;i<n;i++)
    80             printf(" %d",p[i].index);
    81         printf("
    ");
    82     }
    83     return 0;
    84 }
  • 相关阅读:
    Sql Server 2005中的架构(Schema)、用户(User)、角色(Role)和登录(Login)(三)
    安装Eclipse的Tomcat插件
    Datedif函数
    web.xml 中的listener、 filter、servlet 加载顺序及其详解(1)
    Sql Server 2005中的架构(Schema)、用户(User)、角色(Role)和登录(Login)一
    关于IIS6.0 发布Web服务的问题 Pete
    什么是Winsock
    RTTI
    Cstring转char、string、int等数据类型的方法
    C++静态成员函数小结
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5865733.html
Copyright © 2020-2023  润新知