【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和jquery事件--键盘事件KeyboardEvent
Js和jq事件—键盘事件KeyboardEvent 键盘事件keydown,keypress和keyup,还需要涉及到一个文本事件textInput. keydown,keypress和keyup事件 ...
- 00089_字节输出流OutputStream
1.字节输出流OutputStream (1)OutputStream此抽象类,是表示输出字节流的所有类的超类.操作的数据都是字节,定义了输出字节流的基本共性功能方法: (2)输出流中定义都是写wri ...
- crm2013 查看下拉框的选项
在CRM2011中,我们非常easy查看下拉框的选择.打开页面,按F12.把光标对准目标,就会显示出详细的选项,如图:' watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi ...
- vue的使用(一)
之前找了一个学前端的同学,给我免费做几个页面,但是后来也就杳无音信了,今天脑子发热自己学一下vue算了. 本节目标: 安装以及数据绑定 1.安装和运行 ·必须要安装nodejs,这个到网上写 ...
- trunc与round
TRUNC(number[,num_digits]) number 需要截尾取整的数字. num_digits 用于指定取整精度的数字.Num_digits 的默认值为 0. 作用:截断数字和时间 ...
- 在 Windows 10 x64 上安装及使用 ab 工具的流程
本文转自:www.shuijingwanwq.com/2017/04/18/1568/ 1.基于AB测试工具进行高并发情形下的模拟测试,打开:http://httpd.apache.org/docs/ ...
- change_names
DC在储存网表时,有时会采用特殊的字符 比如表示总线BUS[7]-BUS[0] 会表示成\BUS[7] \BUS[6]...... 在compile命令之后,write命令之前 加上:chan ...
- [D3] Build a Scatter Plot with D3 v4
Scatter plots, sometimes also known as bubble charts, are another common type of visualization. They ...
- wepy小程序实现列表分页上拉加载(2)
第一篇:wepy小程序实现列表分页上拉加载(1) 本文接着上一篇内容: 4.优化-添加加载动画 (1)首先写加载动画的结构和样式 打开list.wpy文件 template结构代码: <temp ...
- 云服务器搭建 Nginx 静态网站
第一步:安装 Nginx 在 CentOS 上,可直接使用 yum 来安装 Nginx(当然也可以通过下载压缩包.解压.编译的方式安装,不过太麻烦了) yum install nginx -y 第二步 ...