文章标题
来源:互联网 发布:kafka java获取offset 编辑:程序博客网 时间:2024/05/22 06:07
2016 wf G oil
题意,从suface挖一个井,穿过一些油田,油田是平行于surface的一些线段,获得一些value,问value最大多少。
做法:最优的挖井方法肯定经过油田的端点,枚举端点,其他点极角排序,扫描线扫一遍,更新答案。trick:因为要从地面开始挖井,所以y轴一样的油田不用算,eps要1e-12。
这里
#include <bits/stdc++.h>using namespace std;#define LL long long#define pii pair<int, int>#define MP make_pair#define inf 0x3f3f3f3f#define mod 1000000007#define eps 1e-12#define Pi acos(-1.0)#define N 2050int dcmp(double x){ if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1;}struct point{ double x, y; point(double x = 0, double y = 0) : x(x), y(y) {} point operator - (const point &b) const { return point(x - b.x, y - b.y); } point operator + (const point &b) const { return point(x + b.x, y + b.y); }};struct seg{ point u, v; seg() {} seg(point _u, point _v){ u = _u, v = _v; }};struct node{ point u; LL val; int in; double ang; node(){} node(point _u, LL _val){ u = _u, val = _val; ang = atan2(u.y, u.x); } bool operator < (const node &b) const { if(dcmp(ang - b.ang) == 0) return in > b.in; return dcmp(ang - b.ang) < 0; }};seg a[N];node p[N*4];int n;LL ans, val[N];void gao(point u, int id, int sta){ int tot = 0; LL cur = sta; for(int i = 1; i <= n; ++i){ if(i == id) continue; if(a[i].u.y == u.y) continue; p[tot++] = node(a[i].u - u, val[i]); p[tot++] = node(a[i].v - u, val[i]); if(dcmp(p[tot-2].ang - p[tot-1].ang) <= 0) p[tot-2].in = 1, p[tot-1].in = -1; else p[tot-2].in = -1, p[tot-1].in = 1; } sort(p, p + tot); for(int i = tot; i < 2 * tot; ++i) p[i] = p[i-tot], p[i].ang += 2 * Pi; LL add = 0; for(int i = 0, ps = 0; i < tot; ++i){ double nxt = p[i].ang + Pi; while(dcmp(p[ps].ang - nxt) <= 0){ add += p[ps].val * p[ps].in; ps++; } cur += p[i].val * p[i].in; ans = max(ans, cur + add); }}int main(){ ans = 0; scanf("%d", &n); for(int i = 1; i <= n; ++i){ int x0, x1, y; scanf("%d%d%d", &x0, &x1, &y); a[i].u = point(x0, y); a[i].v = point(x1, y); val[i] = (LL)abs(x0 - x1); ans = max(ans, val[i]); } for(int i = 1; i <= n; ++i){ gao(a[i].u, i, val[i]); gao(a[i].v, i, val[i]); } cout << ans << endl; return 0;}
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 常用的字符转换类
- 学习理解实现Servlet的三种方式
- 【caffe学习笔记】caffe训练日志输出
- 如何从esclipe中快速找到web项目的所需文件
- java web 面试一般 问题总结
- 文章标题
- 定位IO瓶颈的一些方法(iotop工具具体查看IO负载主要是落在哪个进程上)
- red5流媒体服务器
- java排序算法(4)—冒泡排序
- iOS简单验证中文名的有效性
- InfluxDB学习之InfluxDB的安装和简介
- spring注解事务及事务回滚失败的原因
- Java Exception之多个catch
- SEAndroid 浅谈