A - Engines Atcoder 4900

Title effect: n points, the resulting combination of any of several points of maximum distance from the origin point.

Solution: polar angle Sort: https://blog.csdn.net/qq_39942341/article/details/79840394

Sorting using polar angle, these vectors as the origin points of phase separation, then the smaller the angle difference between the parallelogram law, two vectors, the longer the length of the vector obtained composite thereof.

#include<bits/stdc++.h>
using namespace std;
const int N=1E5+7;
struct stu{
    double a,b;
    bool friend operator <(const stu &x,const stu &y){
        return atan2(x.b,x.a)<atan2(y.b,y.a);
    }
}arr[N];
int nxt[N];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)    cin>>arr[i].a>>ARR [I] .B;    
     for ( int I = . 1 ; I <= n-; I ++) NXT [I] = I + . 1 ; 
    NXT [n-] = . 1 ; 
    Sort (ARR + . 1 , ARR + . 1 + n-);
     Double ANS = 0 ;
     for ( int I = . 1 ; I <= n-; I ++) { // each of points as a starting point, traverse the circle back to the starting point, while the size of the recording 
        Double DX = ARR [I] II.A;
         Double Dy = ARR [I] .B; 
        ANS = max (ANS, ARR [I] * II.A ARR [I] + II.A ARR [I] .B * ARR [I] .B); 
        
        for ( int j=nxt[i];j!=i;j=nxt[j]){
            dx+=arr[j].a;
            dy+=arr[j].b;
            ans=max(ans,dx*dx+dy*dy);
        }
    }
    printf("%.15lf\n",sqrt(ans));
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Accepting/p/11900458.html
Recommended