poj3384(半平面交)

这个。。圆心的范围就直接将边向内平移R距离,求半平面交就行。。

然后求出范围之后就要求最远距离了。。一开始想到旋转卡壳然而唯一写的一次旋转卡壳都没写完啊。。

看到n的范围发现直接暴力枚举就行了233333

还好不求面积。。太麻烦了。。_(:зゝ∠)_



#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 300005
#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];
double dis(P o){return sqrt(sqr(o.x)+sqr(o.y));}
struct L{P a,b;double k;}l[NM];
int n,m,R,cnt,q[NM],qh,qt,_x,_y,tmp[NM];
double ans;

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(){
	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];
	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<qt&&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--;
}

int main(){
	//freopen("data.in","r",stdin);
	n=read();R=read();
	dec(i,n,1)p[i].x=read(),p[i].y=read();
	p[n+1]=p[1];
	inc(i,1,n){
		l[i].k=atan2(p[i+1].y-p[i].y,p[i+1].x-p[i].x);
		l[i].a.x=p[i].x+cos(l[i].k+pi/2)*R;
		l[i].a.y=p[i].y+sin(l[i].k+pi/2)*R;
		l[i].b.x=p[i+1].x+cos(l[i].k+pi/2)*R;
		l[i].b.y=p[i+1].y+sin(l[i].k+pi/2)*R;
		tmp[i]=i;
	}
	cut();
	//printf("%d %d %d\n",qh,qt,m);
	inc(i,qh,qt-1)p[++cnt]=intersect(l[q[i]],l[q[i+1]]);
	p[++cnt]=intersect(l[q[qh]],l[q[qt]]);
	inc(i,1,cnt)inc(j,i+1,cnt)if(dis(p[_x]-p[_y])<dis(p[i]-p[j])){_x=i;_y=j;}
	return 0*printf("%.4lf %.4lf %.4lf %.4lf\n",p[_x].x,p[_x].y,p[_y].x,p[_y].y);
}




Feng Shui
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6063 Accepted: 1824 Special Judge

Description

Feng shui is the ancient Chinese practice of placement and arrangement of space to achieve harmony with the environment. George has recently got interested in it, and now wants to apply it to his home and bring harmony to it.

There is a practice which says that bare floor is bad for living area since spiritual energy drains through it, so George purchased two similar round-shaped carpets (feng shui says that straight lines and sharp corners must be avoided). Unfortunately, he is unable to cover the floor entirely since the room has shape of a convex polygon. But he still wants to minimize the uncovered area by selecting the best placing for his carpets, and asks you to help.

You need to place two carpets in the room so that the total area covered by both carpets is maximal possible. The carpets may overlap, but they may not be cut or folded (including cutting or folding along the floor border) — feng shui tells to avoid straight lines.

Input

The first line of the input file contains two integer numbers n and r — the number of corners in George’s room (3 ≤ n ≤ 100) and the radius of the carpets (1 ≤ r ≤ 1000, both carpets have the same radius). The following n lines contain two integers xi and yi each — coordinates of the i-th corner (−1000 ≤ xi, yi ≤ 1000). Coordinates of all corners are different, and adjacent walls of the room are not collinear. The corners are listed in clockwise order.

Output

Write four numbers x1, y1, x2, y2 to the output file, where (x1, y1) and (x2, y2) denote the spots where carpet centers should be placed. Coordinates must be precise up to 4 digits after the decimal point.

If there are multiple optimal placements available, return any of them. The input data guarantees that at least one solution exists.

Sample Input

 
 
#15 2 -2 0 -5 3 0 8 7 3 5 0
#24 3 0 0 0 8 10 8 10 0

Sample Output

 
 
#1-2 3 3 2.5
#23 5 7 3

Hint

Source

Northeastern Europe 2006, Northern Subregion

[Submit]   [Go Back]   [Status]   [Discuss]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值