二分+计算几何/半平面交


  半平面交的学习戳这里: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 ;
}
Most Distant Point from the Sea
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 ≤ in − 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的更多相关文章

  1. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  2. 【POJ 1459 power network】

    不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...

  3. 【POJ 2728 Desert King】

    Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...

  4. 【POJ 2976 Dropping tests】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...

  5. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  6. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  7. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  8. 【POJ 2823 Sliding Window】 单调队列

    题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...

  9. 【POJ 2406 Power Strings】

    Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...

随机推荐

  1. spring boot get和post请求,以及requestbody为json串时候的处理

    GET.POST方式提时, 根据request header Content-Type的值来判断: application/x-www-form-urlencoded, 可选(即非必须,因为这种情况的 ...

  2. Xcode的快捷键及代码格式化

    1. 文件CMD + N: 新文件 CMD + SHIFT + N: 新项目CMD + O: 打开 CMD + S: 保存 CMD+OPt+S:保存所有文件 CMD + SHIFT + S: 另存为 ...

  3. (一)预定义宏、__func__、_Pragma、变长参数宏定义以及__VA_ARGS__

    作为第一篇,首先要说一下C++11与C99的兼容性. C++11将 对以下这些C99特性的支持 都纳入新标准中: 1) C99中的预定义宏 2) __func__预定义标识符 3) _Pragma操作 ...

  4. Codeforces Round #494 (Div 3) (A~E)

    目录 Codeforces 1003 A.Polycarp's Pockets B.Binary String Constructing C.Intense Heat D.Coins and Quer ...

  5. 最新OFFICE 0day漏洞分析

    漏洞概述 fireeye最近公布了一个OFFICE 0day,在无需用户交互的情况下,打开word文档就可以通过hta脚本执行任意代码.经过研究发现,此漏洞的成因主要是word在处理内嵌OLE2LIN ...

  6. 20162325 金立清 S2 W11 C20

    20162325 2017-2018-2 <程序设计与数据结构>第11周学习总结 教材关键概念摘要 在哈希方法中,元素保存在哈希表中,其在表中的位置由哈希函数确定. 两个元素或关键字映射到 ...

  7. win7 64位安装pywin32

    先安装pywin32-218.win-amd64-py3.4.exe文件: 安装完成后,用CMD管理员模式进入\Python34\Scripts\目录 输入pywin32_postinstall.py ...

  8. BZOJ 1588: [HNOI2002]营业额统计 双向链表

    BZOJ 1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 512 MBSubmit: 9619  Solved: 3287 题目连接 ht ...

  9. BZOJ 1208: [HNOI2004]宠物收养所 SET的妙用

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4902  Solved: 1879 题目连接 http:/ ...

  10. mysql-5.7.10产生的日志时间与系统时间不一致

    问题描述: 使用安装的mysql workbench登录mysql后,选择server log 进行日志查看的时候,发现产生日志的时间和当期的系统时间不一致:如下图: 查看mysql系统的当期时间显示 ...