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


  半平面交的学习戳这里: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. poj1847 Tram(Dijkstra || Floyd || SPFA)

    题目链接 http://poj.org/problem?id=1847 题意 有n个车站,编号1~n,每个车站有k个出口,车站的出口默认是k个出口中的第一个,如果不想从默认出口出站,则需要手动选择出站 ...

  2. CentOS 使用命令设置代理

    全局的代理设置, vim /etc/profile 添加下面内容 http_proxy = http://username:password@yourproxy:8080/ ftp_proxy = h ...

  3. MySQL性能优化(七·下)-- 锁机制 之 行锁

    一.行锁概念及特点 1.概念:给单独的一行记录加锁,主要应用于innodb表存储引擎 2.特点:在innodb存储引擎中应用比较多,支持事务.开销大.加锁慢:会出现死锁:锁的粒度小,并发情况下,产生锁 ...

  4. 有关FPGA

         在FPGA发展历史上,前后共有过超过50家厂商,在国外目前剩下不到10家,除赛灵思和ALTERA两家持续不断地军备竞赛,其它的都有着各自固守的市场定位.即使是有新进入者,例如受英特尔新工艺支 ...

  5. 【基础知识】ASP.NET[基础二(aspx)]

    1.cs可以调用aspx中的runat=server控件,aspx中也可以访问测试中定义的字段.函数,还可以编写复杂的C#代码,for等所有C#代码都可以写在aspx中(不推荐这样写): 2.把代码写 ...

  6. Django框架(一)-Django初识

    Django初识 一.Web框架本质—自己实现Web框架 1.所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端 import socket sk = sock ...

  7. 鸟哥的私房菜:Bash shell(一)-Bash shell功能简介

    Bash shell系列里,由变量谈起,先讲到环境变量的功能与修改的问题, 然后会继续提到历史指令的运用.接下来,就会谈一下『数据流重导向』这个重要概念, 最后就是管线命令的利用! 一  Bash s ...

  8. Eclipse 工具下Maven 项目的快速搭建

    Eclipse 工具下Maven 项目的搭建 参考博文:https://www.cnblogs.com/iflytek/p/7096481.html 什么是Maven项目 简单来说,传统的Web项目: ...

  9. 批量导入--EasyPOIPOI

    easypoi功能如同名字easy,主打的功能就是容易,让一个没见接触过poi的人员 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 语言( ...

  10. eclipse转idea, 快捷键设置

    设置快捷键的途径: 打开idea的配置,找到Keymap,设置为eclipse 另外还要手动设置某些快捷键 上下移动 点击类打开 代码提示 查询 重命名 快速实现接口 回到上一次光标处