您的位置:首页 > 其它

文章标题

2017-03-07 15:55 253 查看
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 2050

int 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
;
node p[N*4];
int n;
LL ans, val
;
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: