• 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;
    }
    
  • 相关阅读:
    软件测试
    数据库中查询json 样式的值的sql语句
    xml转json的方法
    将数据保存本地文件
    Spring 配置 web.xml (防止spring 内存溢出)
    解决maven工程 子工程中的一些配置读取进来的问题
    quartz 的简单使用
    mock 测试 MVC
    sun 证书问题解决
    将文本转换为json的工具类
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10383770.html
Copyright © 2020-2023  润新知