【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 ...
随机推荐
- oracle中vsize和length
其实LENGTH与VSIZE这两个函数联系不大,区别很大.虽然都是“取长度”,但是LENGTH函数结果是“有多少个字符”,VSIZE结果是“需要多少bytes”.简单看一下这两个函数. 1.创建表T并 ...
- MVC设计模式一
一:基础知识 1.mvc model view control 2.模型 是应用程序的主体部分,模型表示业务数据与业务逻辑. 一个模型可以为多个视图提供数据 提高了代码的可重用性 3.视图 用户看到的 ...
- CODEVS 4655 序列终结者-splay(区间更新、区间翻转、区间最值)
4655 序列终结者 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 题目描述 Description 网上有许多题,就是给定一个序列,要 ...
- redis修改密码
## 无需添加密码参数 redis-cli.exe -h 127.0.0.1 -p 6379 ## 获取当前密码 config get requirepass ## 设置当前密码,服务重新启动后又会置 ...
- 【MPI】并行奇偶交换排序
typedef long long __int64; #include "mpi.h" #include <cstdio> #include <algorithm ...
- wxFormBuilder初体验
第一步 打开wxFormBuilder 修改工程信息并保存工程 Name: 工程名 File: 生成代码(.py)文件名 Code_generation: 生成代码类型 第二步 创建窗体 切换至for ...
- Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 暴力并查集
D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time a ...
- CF 277.5 C.Given Length and Sum of Digits.. 构造
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- centos7搭建.netcore运行环境
开发环境介绍 1.操作系统:Windows Server 2008 R2 Enterprise 2.IDE:VisualStudio2017 3..Net Core 2.0 SDK 本文假设你已经满足 ...
- Window 下安装
Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases Redis 支持 32 位和 64 位.这个需要根据你系统平台的实际情况选择, ...