【POJ】【3525】Most Distant Point from the Sea
二分+计算几何/半平面交
半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621
然而这题是要二分长度r……用每条直线的距离为r的平行线来截“凸包”
做平行线的方法是:对于向量(x,y),与它垂直的向量有:(y,-x)和(-y,x),然后再转化成单位向量,再乘以 r ,就得到了转移向量tmp,设直线上两点为A(x1,y1),B(x2,y2),用这个方法就找到了直线AB的平行线CD,其中C=A+tmp,D=b+tmp;
然而我傻逼的搞错了方向……结果平行线做成了远离凸包的那一条……导致答案一直增大QAQ
剩下的就没啥了,看是否存在这么一块半平面的交即可。
Source Code
Problem: User: sdfzyhy
Memory: 672K Time: 16MS
Language: G++ Result: Accepted Source Code //POJ 3525
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
typedef long long LL;
inline int getint(){
int r=,v=; char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-')r=-;
for(; isdigit(ch);ch=getchar()) v=v*+ch-'';
return r*v;
}
const int N=;
const double eps=1e-,INF=1e8;
/*******************template********************/ int n;
struct Poi{
double x,y;
Poi(){}
Poi(double x,double y):x(x),y(y){}
void read(){scanf("%lf%lf",&x,&y);}
void out(){printf("%f %f\n",x,y);}
}p[N],tp[N],s[N],o;
typedef Poi Vec;
Vec operator - (const Poi &a,const Poi &b){return Vec(a.x-b.x,a.y-b.y);}
Vec operator + (const Poi &a,const Vec &b){return Poi(a.x+b.x,a.y+b.y);}
Vec operator * (const double &k,const Vec a){return Vec(a.x*k,a.y*k);}
inline double Cross(const Vec &a,const Vec &b){return a.x*b.y-a.y*b.x;}
inline double Dot(const Vec &a,const Vec &b){return a.x*b.x+a.y*b.y;}
inline double Len(const Vec &a){return sqrt(Dot(a,a));}
inline int dcmp(double x){return x > eps ? : x < eps ? - : ;}
double getarea(Poi *a,int n){
double ans=0.0;
F(i,,n) ans+=Cross(a[i]-o,a[i+]-o);
return ans*0.5;
}
Poi getpoint (const Poi &a,const Poi &b,const Poi &c,const Poi &d){
Poi ans,tmp=b-a;
double k1=Cross(d-a,c-a),k2=Cross(c-b,d-b);
ans=a+(k1/(k1+k2))*tmp;
return ans;
}
inline void get_parallel(Poi &a,Poi &b,double r,Poi &c,Poi &d){
// Poi tmp(b.y-a.y,a.x-b.x);
Poi tmp(a.y-b.y,b.x-a.x);
tmp=(r/Len(tmp))*tmp;
c=a+tmp; d=b+tmp;
// a.out(); b.out(); c.out(); d.out();
// puts("");
}
void init(){
F(i,,n) p[i].read();
p[n+]=p[];
}
bool check(double r){
tp[]=tp[]=Poi(-INF,-INF);
tp[]=Poi(INF,-INF);
tp[]=Poi(INF,INF);
tp[]=Poi(-INF,INF);
int num=,size=;
F(i,,n){
size=;
F(j,,num){
Poi t1(,),t2(,);
get_parallel(p[i],p[i+],r,t1,t2);
if (dcmp(Cross(t2-t1,tp[j]-t1))>=)
s[++size]=tp[j];
if (dcmp(Cross(t2-t1,tp[j]-t1)*Cross(t2-t1,tp[j+]-t1))<)
s[++size]=getpoint(t1,t2,tp[j],tp[j+]);
}
s[size+]=s[];
F(j,,size+) tp[j]=s[j];
num=size;
// printf("num=%d\n",num);
// F(j,1,num) tp[j].out();
}
// printf("n=%d num=%d size=%d\n",n,num,size);
if (num>) return ;
else return ;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("3525.in","r",stdin);
freopen("3525.out","w",stdout);
#endif
while(scanf("%d",&n)!=EOF && n){
init();
double l=0.0,r=1e7,mid;
while(r-l>eps){
mid=(l+r)/;
// printf("mid=%f\n",mid);
if (check(mid)) l=mid;
else r=mid;
}
printf("%f\n",l);
}
return ;
}
Time Limit: 5000MS | Memory Limit: 65536K | |||
Total Submissions: 4183 | Accepted: 1956 | Special Judge |
Description
The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: “Where is the most distant point from the sea?” The answer to this question for Honshu was found in 1996. The most distant point is located in former Usuda Town, Nagano Prefecture, whose distance from the sea is 114.86 km.
In this problem, you are asked to write a program which, given a map of an island, finds the most distant point from the sea in the island, and reports its distance from the sea. In order to simplify the problem, we only consider maps representable by convex polygons.
Input
The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows.
n | ||
x1 | y1 | |
⋮ | ||
xn | yn |
Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space.
n in the first line is the number of vertices of the polygon, satisfying 3 ≤ n ≤ 100. Subsequent n lines are the x- and y-coordinates of the n vertices. Line segments (xi, yi)–(xi+1, yi+1) (1 ≤ i ≤ n − 1) and the line segment (xn, yn)–(x1, y1) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive.
You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.
The last dataset is followed by a line containing a single zero.
Output
For each dataset in the input, one line containing the distance of the most distant point from the sea should be output. An output line should not contain extra characters such as spaces. The answer should not have an error greater than 0.00001 (10−5). You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.
Sample Input
4
0 0
10000 0
10000 10000
0 10000
3
0 0
10000 0
7000 1000
6
0 40
100 20
250 40
250 70
100 90
0 70
3
0 0
10000 10000
5000 5001
0
Sample Output
5000.000000
494.233641
34.542948
0.353553
Source
[Submit] [Go Back] [Status] [Discuss]
【POJ】【3525】Most Distant Point from the Sea的更多相关文章
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- 【POJ 1459 power network】
不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...
- 【POJ 2728 Desert King】
Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...
- 【POJ 2976 Dropping tests】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...
- 【POJ 3080 Blue Jeans】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...
- 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)
1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- 【POJ 2823 Sliding Window】 单调队列
题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...
- 【POJ 2406 Power Strings】
Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...
随机推荐
- 机械加工行业计划排程:中车实施应用易普优APS
一.机械加工行业现状 机械制造业在生产管理上的主要特点是:离散为主.流程为辅.装配为重点.机械制造业的基本加工过程是把原材料分割,大部分属于多种原材料平行加工,逐一经过车.铣.刨.磨或钣金成型等加工工 ...
- Django实战(16):Django+jquery
现在我们有了一个使用json格式的RESTful API,可以实现这样的功能了:为了避免在产品列表和购物车之间来回切换,需要在产品列表界面显示购物车,并且通过ajax的方式不刷新界面就更新购物车的显示 ...
- Gitlab服务器维护
一. 内容 Gitlab服务器的更新 Gitlab服务器备份与恢复 导入Git仓库 二. Gitlab服务器的更新 1. 使用SSH登陆Gitlab服务器 2. 停止后端的unicorn服务器 [ro ...
- Ionic Js十七:侧栏菜单
一个容器元素包含侧边菜单和主要内容.通过把主要内容区域从一边拖动到另一边,来让左侧或右侧的侧栏菜单进行切换. 效果图如下所示:   用法 要使用侧栏菜单,添加一个父元素,一个中间内容 ,和一个或更 ...
- IP、TCP和DNS与HTTP的密切关系
看了上一篇博文的发表时间,是7月22日,现在是10月22日,已经有三个月没写博客了.这三个月里各种忙各种瞎折腾,发生了很多事情,也思考了很多问题.现在这段时间开始闲下来了,同时该思考的事情也思考清楚了 ...
- React Native之数据存储技术AsyncStorage
1. 如何将数据存储到本地? 数据存储是开发APP必不可少的一部分,比如页面缓存,从网络上获取数据的本地持久化等,那么在RN中如何进行数据存储呢? RN官方推荐我们在RN中使用AsyncStorage ...
- luoguP4336 [SHOI2016]黑暗前的幻想乡 容斥原理 + 矩阵树定理
自然地想到容斥原理 然后套个矩阵树就行了 求行列式的时候只有换行要改变符号啊QAQ 复杂度为\(O(2^n * n^3)\) #include <cstdio> #include < ...
- 【线段树】【扫描线】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem A. Donut
题意:平面上n个点,每个点带有一个或正或负的权值,让你在平面上放一个内边长为2l,外边长为2r的正方形框,问你最大能圈出来的权值和是多少? 容易推出,能框到每个点的 框中心 的范围也是一个以该点为中心 ...
- 最小生成树 Prim(普里姆)算法和Kruskal(克鲁斯特尔)算法
Prim算法 1.概览 普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树.意即由此算法搜索到的边子集所构成的树中,不但包括了连通图里的所有顶点(英语:Vertex (gra ...
- 在WAMPSERVER下增加多版本的PHP(PHP5.3,PHP5.4,PHP5.5)完美支持。
WAMPServer可以让开发者在Windows系统下快速搭建WAMP环境,它支持多版本的Apache.MySQL.PHP之间的相互切换,互不影响,对于PHPer开发者来讲极为方便快速. 以下是在WA ...