zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    致我的2018 你好2019
    第十四分块(前体)(二次离线莫队)
    [Ynoi2019模拟赛]Yuno loves sqrt technology II(二次离线莫队)
    [Ynoi2015]此时此刻的光辉(莫队)
    python+selenium+Firefox+pycharm版本匹配
    IntelliJ IDEA 配置Maven
    Jmeter如何监控服务器性能
    fiddler工具
    关于Python安装官方whl包和tar.gz包的方法详解
    浅析Web Services
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10383770.html
Copyright © 2011-2022 走看看