HDU4216 Computational Geometry?

The meaning of the question: Knowing the coordinates of the bomb, n vectors (n<100), starting from the origin, each vector can go forward or reverse, find a way, so that the distance from the farthest point to the bomb on the road is the largest, ask maximum distance

Solution: The farthest distance is required, that is, the vector must be in the same direction as far as possible to be farther, you can enumerate the directions, and the largest one is the answer

#include <bits/stdc++.h>
#define maxn 100
#define PI 3.14159265358979323846
#define Vector Point
using namespace std;
typedef long long ll;
struct Point {
    double x, y;
}a[maxn], c, e, b;
int main(){
    int T, ca = 1, n;
    double ma;
    scanf("%d", &T);
    while(T--){
        scanf("%d%lf%lf", &n, &c.x, &c.y);
        for(int i=0;i<n;i++) scanf("%lf%lf", &a[i].x, &a[i].y);
        ma = 0;
        for(int j=0;j<360;j+=2){
            bx =by= 0 ;
            ey = sin( 2 *PI/ 360 * j);
            e.x = cos(2*PI/360*j);
            for(int i=0;i<n;i++){
                if(e.x*a[i].x+e.y*a[i].y >= 0) b.x-=a[i].x,b.y-=a[i].y;
                else b.x+=a[i].x,b.y+=a[i].y;
                ma = max(ma, (b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));
            }
        }
        printf("Case %d: %.3f\n", ca++, sqrt(ma));
    }
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325191817&siteId=291194637