poj3525(二分答案+半平面交)

应该说是到好题。。可惜不小心看到二分这个字眼然后浪费了qaq

直接二分答案后平移线段,按倾斜角+90度的方向偏移即可,然后剩下的就是判断有没有核了。。。

其实有点怕超时的,毕竟是nlog10^9,所以特意把排序写在前面,这样nlognlog10^9可以降成nlog10^9。。事实上log后面太大不会怎么样。。所以就算用nlognlog10^9甚至n^2log10^9都没问题的。。。实测nlog10^9算法跑起来只有0ms...然而还是差点进入了首页qaq




#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define eps 1e-8
#define inf 1e9
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define ls T[i<<1]
#define rs T[i<<1|1]
#define op T[i]
#define mid (x+y>>1)
#define NM 105
#define nm 100498
#define pi 3.1415926535897931
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}






struct P{
	double x,y;
	P(double x=0,double y=0):x(x),y(y){}
	P operator-(const P&o){return P(x-o.x,y-o.y);}
	double operator*(const P&o){return x*o.y-y*o.x;}
}p[NM];
struct L{P a,b;double k;}l[NM];
int n,m,tmp[NM],q[NM],qh,qt;

bool cmp(int x,int y){
	if(fabs(l[x].k-l[y].k)<eps)return (l[y].b-l[x].a)*(l[x].b-l[x].a)>eps;
	return l[x].k<l[y].k;
}
P intersect(L x,L y){
	double t1=(x.b-y.a)*(x.a-y.a),t2=(y.b-x.b)*(x.a-x.b);
	return P((y.a.x*t2+y.b.x*t1)/(t1+t2),(y.a.y*t2+y.b.y*t1)/(t1+t2));
}
bool judge(L a,L b,L c){return (a.b-a.a)*(intersect(b,c)-a.a)+eps<0;}

void cut(){
	mem(q);qh=1;qt=0;
	inc(k,1,m){
		int i=tmp[k];
		while(qh<qt&&judge(l[i],l[q[qt-1]],l[q[qt]]))qt--;
		while(qh<qt&&judge(l[i],l[q[qh+1]],l[q[qh]]))qh++;
		q[++qt]=i;
	}
	while(qh<qh&&judge(l[q[qt]],l[q[qh+1]],l[q[qh]]))qh++;
	while(qh<qt&&judge(l[q[qh]],l[q[qt-1]],l[q[qt]]))qt--;
}

bool check(double t){
	inc(i,1,n){
		l[i].a.x=p[i].x+cos(l[i].k+pi/2)*t;
		l[i].a.y=p[i].y+sin(l[i].k+pi/2)*t;
		l[i].b.x=p[i+1].x+cos(l[i].k+pi/2)*t;
		l[i].b.y=p[i+1].y+sin(l[i].k+pi/2)*t;
	}
	cut();
	return qt>qh+1;
}

int main(){
	//freopen("data.in","r",stdin);
	while(n=read()){
		inc(i,1,n)p[i].x=read(),p[i].y=read();
		p[n+1]=p[1];
		inc(i,1,n){
			l[i].a=p[i];l[i].b=p[i+1];
			l[i].k=atan2(p[i+1].y-p[i].y,p[i+1].x-p[i].x);
			tmp[i]=i;
		}
		sort(tmp+1,tmp+1+n,cmp);m=1;
		inc(i,2,n)if(fabs(l[tmp[i]].k-l[tmp[m]].k)>eps)tmp[++m]=tmp[i];
		double l=0,r=10000*sqrt(2.0),ans=0;
		while(l+1e-6<=r){
			double t=(l+r)/2;
			if(check(t)){l=t;ans=t;}
			else r=t;
		}
		printf("%.6lf\n",ans);
	}
	return 0;
}





Most Distant Point from the Sea
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 5724 Accepted: 2545 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 then 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]


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值