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


  半平面交的学习戳这里: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. mysql 新增时,唯一索引冲突时更新

    INSERT INTO table_name(f1 ,f2 ,f3) VALUES(? ,?) on duplicate key update f2 = ? ,f3 = ?

  2. poj2524 Ubiquitous Religions(并查集)

    题目链接 http://poj.org/problem?id=2524 题意 有n个学生,编号1~n,每个学生最多有1个宗教信仰,输入m组数据,每组数据包含a.b,表示同学a和同学b有相同的信仰,求在 ...

  3. linux 下rocketmq安装

    一.解压mq(/data下)tar -zxvf Rocketmq-3.5.8.tar.gz 二.修改配置文件vi /etc/profileexport rocketmq=/data/alibaba-r ...

  4. 【运维理论】RAID级别简介

    独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(RAID, Redundant Array of Inexpensive ...

  5. CF1060E Sergey and Subway 思维

    分两种情况讨论 一种为奇数长为$L$的路径,在经过变化后,我们需要走$\frac{L}{2} + 1$步 一种为偶数长为$L$的路径,在变化后,我们需要走$\frac{L}{2}$步 那么,我们只需要 ...

  6. 拆分Cocos2dx渲染部分代码

    纹理实现 思想 这个是Cocos2dx的渲染部分的最基本的实现,被我拆分到mac上,但是并不是用的EGLContext,而是搭配glfw,还有soil第三方图形库. 实现 // // main.cpp ...

  7. poj3268 Silver Cow Party(农场派对)

    题目描述 原题来自:USACO 2007 Feb. Silver N(1≤N≤1000)N (1 \le N \le 1000)N(1≤N≤1000) 头牛要去参加一场在编号为 x(1≤x≤N)x(1 ...

  8. HDU 1698 just a hook 线段树,区间定值,求和

    Just a Hook Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1 ...

  9. Python— isinstance用法说明

    在学习自动化测试的脚本中发现了这个函数,所以在网上查了一下资料进行如下整理: 通过帮助查看如下: 作用:来判断一个对象是否是一个已知的类型: 其第一个参数(object)为对象,第二个参数为类型名(i ...

  10. OPENCV----在APP性能测试中的应用(一)

    应用项目:  APP的性能测试 应用场景:  APP启动速度  视频开播速度 加载速度  等~~ 缘来:  基于APP日志和UiAutomator的测试方案,测试结果不能直白且精确的反应,用户的体验 ...