【BZOJ 1020】 [SHOI2008]安全的航线flight
【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1020
【题意】
【题解】
二分+判断点是否在多边形区域内+计算点到直线的最短距离
对于每条线段,假设这条线段为(x,y)首先将线段的两段尝试更新距离陆地距离最近的距离中最远的距离ans,并求出其在陆地上对应的点u和v;(如果x和y都在陆地上那么u、v就都是陆地上的点)
然后在这条(x,y)中找一个点mid
使得pv=pu;
然后先用p点尝试更新一下答案ans(找离p点最近的陆地上的点)
然后如果pv< ans,那么这条直线就不用再找了;
因为如果是(x,y)上异于p的点;
它里陆地的距离只会比pv更近.
(画图就知道了);
这其实就只是用中点去剪枝而已.
但效果很好.
如果不满足pv< ans
则把xp和py两条直线再进行处理就好;
写个循环队列咯。
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define red(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 40;
const int M = 100e4 + 10;
const double eps = 1e-4;
struct point
{
double x, y;
};
point operator -(point u, point v) {
point t; t.x = u.x - v.x; t.y = u.y - v.y; return t;
}
struct abc
{
point p1, p2;
};
double crs(point u, point v) { return u.x*v.y - u.y*v.x; }
bool upon(point u, point v, point w) {
return !crs(v - u, w - u) && (u.x - v.x)*(u.x - w.x) <= 0 && (u.y - v.y)*(u.y - w.y) <= 0;
}
bool havitr(point u, point v, point s, point t) {
return crs(v - u, s - u)*crs(v - u, t - u) <= 0 && crs(t - s, u - s)*crs(t - s, v - s) <= 0;
}
struct disp { point p; double dis; };
double dot(point u, point v) { return u.x*v.x + u.y*v.y; }
double dist(point u, point v) { return sqrt(dot(u - v, u - v)); }
disp lss(disp u, disp v) { return (u.dis<v.dis) ? u : v; }
point getitr(point u, point s, point v, point t) {
double tmp = crs(t, u - v) / crs(s, t);
u.x += s.x*tmp; u.y += s.y*tmp; return u;
}
point s;
struct land
{
int tot;
point p[N];
void init()
{
rei(tot);
rep1(i, 1, tot)
red(p[i].x), red(p[i].y);
p[tot + 1] = p[1];
}
bool inside(point t)
{
int i, sum = 0;
for (i = 1; i <= tot; i++)
if (upon(t, p[i], p[i + 1])) return 1;
t.y += 0.1;
s.y = t.y; s.x = -10001;
for (i = 1; i <= tot; i++)
if (havitr(s, t, p[i], p[i + 1])) sum++;
t.y -= 0.1;
return sum & 1;
}
};
int c, n;
double ans = 0;
point a[N];
abc q[M];
land b[N];
disp nearst(point u, point v, point w) {
disp t;
if (v.x == w.x && v.y == w.y) t.p = v; else
if (dot(u - v, w - v) <= 0) t.p = v; else
if (dot(u - w, v - w) <= 0) t.p = w; else {
point s = v - w; swap(s.x, s.y); s.x = -s.x;
t.p = getitr(u, s, v, w - v);
}
t.dis = dist(t.p, u); return t;
}
point updata(point t)
{
rep1(i, 1, c)
if (b[i].inside(t))
return t;
disp temp;
temp.dis = 1e20;
rep1(i, 1, c)
rep1(j, 1, b[i].tot)
temp = lss(temp, nearst(t, b[i].p[j], b[i].p[j + 1]));
ans = max(ans, temp.dis);
return temp.p;
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(c), rei(n);
rep1(i, 1, n)
{
red(a[i].x), red(a[i].y);
}
rep1(i, 1, c)
b[i].init();
int head = 0, tail = 0;
rep1(i, 1, n - 1)
{
q[++tail].p1 = a[i], q[tail].p2 = a[i + 1];
updata(a[i]);
}
while (head != tail)
{
head = head%M + 1;
point x = q[head].p1, y = q[head].p2;
point u = updata(x), v = updata(y),mid;
while (dist(x, y) > eps)
{
mid.x = (x.x + y.x) / 2, mid.y = (x.y + y.y) / 2;
if (dist(u, mid) < dist(v, mid))
x = mid;
else
y = mid;
}
double temp = dist(u, x); updata(x);
if (temp > ans+eps)
{
tail = tail%M + 1, q[tail].p1 = q[head].p1, q[tail].p2 = mid;
tail = tail%M + 1, q[tail].p1 = mid, q[tail].p2 = q[head].p2;
}
}
printf("%.2f\n", ans);
return 0;
}
【BZOJ 1020】 [SHOI2008]安全的航线flight的更多相关文章
- BZOJ 1020 [SHOI2008]安全的航线flight
1020: [SHOI2008]安全的航线flight Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 847 Solved: 286[Submit][ ...
- 1020: [SHOI2008]安全的航线flight - BZOJ
Description在设计航线的时候,安全是一个很重要的问题.首先,最重要的是应采取一切措施确保飞行不会发生任何事故,但同时也需要做好最坏的打算,一旦事故发生,就要确保乘客有尽量高的生还几率.当飞机 ...
- 【BZOJ】【1020】【SHOI2008】安全的航线flight
计算几何/二分/迭代/搜索+剪枝 写三个tag可能是因为从哪个方向来理解都可以吧…… 我完全不会计算几何所以抄了ydc的代码 题解:http://ydcydcy1.blog.163.com/blog/ ...
- BZOJ 1020 安全的航线flight
Description 在设计航线的时候,安全是一个很重要的问题.首先,最重要的是应采取一切措施确保飞行不会发生任何事故,但同时也需要做好最坏的打算,一旦事故发生,就要确保乘客有尽量高的生还几率.当飞 ...
- bzoj 1023: [SHOI2008]cactus仙人掌图 tarjan缩环&&环上单调队列
1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1141 Solved: 435[Submit][ ...
- bzoj 1022: [SHOI2008]小约翰的游戏John anti_nim游戏
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1189 Solved: 734[Submit][ ...
- [BZOJ 1018] [SHOI2008] 堵塞的交通traffic 【线段树维护联通性】
题目链接:BZOJ - 1018 题目分析 这道题就说明了刷题少,比赛就容易跪..SDOI Round1 Day2 T3 就是与这道题类似的..然而我并没有做过这道题.. 这道题是线段树维护联通性的经 ...
- 数据结构(线段树):BZOJ 1018: [SHOI2008]堵塞的交通traffic
1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 2638 Solved: 864 Descri ...
- BZOJ 1021 [SHOI2008]Debt 循环的债务
1021: [SHOI2008]Debt 循环的债务 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 694 Solved: 356[Submit][S ...
随机推荐
- Python3的取余操作
https://blog.csdn.net/u014647208/article/details/53368244 取余代码: 输入以下代码: >>>10%2 >>> ...
- js取对象的属性值循环
var data = {name: "liuyang", job: "web", age: "27"} Object.keys(data). ...
- spring使用context:property-placeholder载不进属性问题 wangbiglei 发表于1年前 原 spring使用context:property-placeholder载不进属性问题
https://my.oschina.net/wangbiglei/blog/489583 http://www.cnblogs.com/leftthen/p/5615066.html
- synchronized和ReentrantLock区别
一.什么是sychronized sychronized是java中最基本同步互斥的手段,可以修饰代码块,方法,类. 在修饰代码块的时候需要一个reference对象作为锁的对象. 在修饰方法的时候默 ...
- UVA 488 - Triangle Wave 水~
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- (最新)使用爬虫刷CSDN博客访问量——亲测有效
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 1.概述 前言:前两天刚写了第一篇博客https://blog.csdn.net/qq_41782425/article/deta ...
- 【Codeforces Round #442 (Div. 2) C】Slava and tanks
[链接] 我是链接,点我呀:) [题意] 有n个位置,每个位置都可能有不定数量的tank; 你每次可以选择一个位置投掷炸弹. 并且,这个位置上的所有tank都会受到你的攻击. 并且失去一点体力. 然后 ...
- Linux 内核源代码分析 chap 2 存储管理 (5)
物理页面分配 linux 内核 2.4 中有 2 个版本号的物理页面分配函数 alloc_pages(). 一个在 mm/numa.c 中, 还有一个在 mm/page_alloc.c 中, 依据条件 ...
- IOS获取preferreces偏好设置plistname名称的方法
//获取preferreces偏好设置plistname名称的方法1 -(NSArray*)loadSpecifiersFromPlistName:(NSString*)plistName targe ...
- flink DataStream API使用及原理
传统的大数据处理方式一般是批处理式的,也就是说,今天所收集的数据,我们明天再把今天收集到的数据算出来,以供大家使用,但是在很多情况下,数据的时效性对于业务的成败是非常关键的. Spark 和 Flin ...