设为首页 加入收藏

TOP

BZOJ1278: 向量vector(计算几何 随机化乱搞)
2019-02-15 16:08:26 】 浏览:93
Tags:BZOJ1278: 向量 vector 计算 几何 随机

题意

题目链接

Sol

讲一下我的乱搞做法。。。。

首先我们可以按极角排序。然后对\(y\)轴上方/下方的加起来分别求模长取个最大值。。

这样一次是\(O(n)\)的。

我们可以对所有向量每次随机化旋转一下,然后执行上面的过程。数据好像很水然后就艹过去了。。。

#include<bits/stdc++.h>
#define LL long long 
using namespace std;
const int MAXN = 1e5 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
template<typename A> inline A sqr(A x) {
    return x * x;
}
struct Point {
    double x, y;
    Point operator + (const Point &rhs) const {
        return {x + rhs.x, y + rhs.y};
    }
    Point operator - (const Point &rhs) const {
        return {x - rhs.x, y - rhs.y};
    }
    double operator ^ (const Point &rhs) const {
        return x * rhs.y - y * rhs.x;
    }
    bool operator < (const Point &rhs) const {
        return atan2(y, x) < atan2(rhs.y, rhs.x);
    }
    double len() {
        return sqr(x) + sqr(y);
    }
    void rotate(double ang) {
        double l = len(), px = x, py = y;
        x = px * cos(ang) - py * sin(ang);
        y = px * sin(ang) + py * cos(ang);
    }
}p[MAXN];
double check() {
    Point n1 = {0, 0}, n2 = {0, 0}; 
    for(int i = 1; i <= N; i++) 
        if(p[i].y >= 0) n1 = n1 + p[i];
        else n2 = n2 + p[i];
    return max(n1.len(), n2.len());
}
int main() {
    N = read();
    for(int i = 1; i <= N; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
    sort(p + 1, p + N + 1);
    double ans = 0;
    for(double i = 1; i <= 180; i ++) {
        ans = max(ans, check());
        for(int j = 1; j <= N; j++) p[j].rotate(1);
    }
    LL gg = ans;
    ans = gg;
    printf("%.3lf", ans);
    return 0;
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇37.QT-QTSingleApplication-程序.. 下一篇BZOJ2564: 集合的面积(闵可夫斯基..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目