前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >BZOJ1278: 向量vector(计算几何 随机化乱搞)

BZOJ1278: 向量vector(计算几何 随机化乱搞)

作者头像
attack
发布2019-03-04 16:17:56
3010
发布2019-03-04 16:17:56
举报

题意

题目链接

Sol

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

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

这样一次是O(n)的。

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

代码语言:javascript
复制
#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;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-02-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档