【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 ...
随机推荐
- JavaScript篇(一)二叉树的插入 (附:可视化)
一.二叉树概念 二叉树(binary tree)是一颗树,其中每个节点都不能有多于两个的儿子. 字节一面,第一道就是二叉树的插入,在这里其实是对于一个二叉查找树的插入. 使二叉树成为二叉查找树的性质是 ...
- 51Nod——N1082 与7无关的数
https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1082 题目来源: 有道难题 基准时间限制:1 秒 空间限制:13107 ...
- [Angular] Protect The Session Id with https and http only
For the whole signup process. we need to Hash the password to create a password digest Store the use ...
- Q13.cocoapod_卡在“analyzing_depengcies”问题解决
Q13.CocoaPod 卡在"analyzing depengcies"问题解决 问题描写叙述: 当进入到项目目录后,pod init一个Podfile,然后键入你要的库连接信息 ...
- javascript中的this指向问题总结
this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象 1.函数执行的时候,首先看函数名前边是否有点 ‘·’,有的话点’ ...
- Keepalived + Mysql 双主
VIP 192.168.1.41 Master 192.168.1.42 Slave 192.168.1.43 .配置 yum -y install mysql-server chkconfig -- ...
- Windows服务安装命令:
sc create YY.SmsPlatform.RemoteDataCenter binPath= "E:\YY.SmsPlatform\YY.SmsPlatform.RemoteData ...
- 利用Attribute实现Aop
Aop“面向切面编程”,与OOP“面向对象编程”一样是一种编程思路.个人理解:在不改变原有逻辑的基础上,注入其他行为. 基础代码(仿MVC拦截器实现) namespace HGL.Toolkit.Ao ...
- angular 引入material-ui
第一步:安装material和cdk和animations,一个也不能缺,否则会报错. npm install --save @angular/material @angular/cdk @angul ...
- EL表达式.md
操作符 描述 . 访问一个Bean属性或者一个映射条目 [] 访问一个数组或者链表的元素 ( ) 组织一个子表达式以改变优先级 + 加 - 减或负 * 乘 / or div 除 % or mod 取模 ...