poj 3130 How I Mathematician Wonder What You Are! 【半平面交】
求多边形的核,直接把所有边求半平面交判断有无即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=205;
const double eps=1e-6;
int n;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a)
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a)
{
return dian(x-a.x,y-a.y);
}
dian operator * (const double &a) const
{
return dian(x*a,y*a);
}
dian operator / (const double &a) const
{
return dian(x/a,y/a);
}
}p[N];
struct bian
{
dian s,v;
bian(dian S=dian(),dian V=dian())
{
s=S,v=V;
}
}l[N],s[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
double mj(dian a,dian b,dian c)
{
return cj(b-a,c-a)/2;
}
dian jd(bian x,bian y)
{
return x.s+x.v*(cj(x.s-y.s,y.v)/cj(y.v,x.v));
}
bool px(bian a,bian b)
{
return cj(a.v,b.v)==0;
}
bool bn(bian a,bian b)
{
int ar=cj(a.v,b.v);
return ar>0||(ar==0&&cj(a.v,b.s-a.s)>0);
}
bool dn(dian x,bian y)
{
return cj(y.v,x-y.s)<=0;
}
bool cmp(const bian &x,const bian &y)
{
if(x.v.y==0&&y.v.y==0)
return x.v.x<y.v.x;
if((x.v.y<=0)==(y.v.y<=0))
return bn(x,y);
return x.v.y<y.v.y;
}
double dis2(bian a)
{
return sqrt(a.v.x*a.v.x+a.v.y*a.v.y);
}
bian yi(bian a,double r)
{
return bian(dian(a.s.x-a.v.y*r/dis2(a),a.s.y+a.v.x*r/dis2(a)),a.v);
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=1;i<=n;i++)
p[i].x=read(),p[i].y=read();
p[n+1]=p[1];
for(int i=1;i<=n;i++)
l[i]=bian(p[i],p[i+1]-p[i]);sort(l+1,l+1+n,cmp);
int top=0;
for(int i=1;i<=n;i++)
if(i==1||!px(l[i],l[i-1]))
l[++top]=l[i];
n=top;
int ll=1,rr=2;
s[1]=l[1],s[2]=l[2];
for(int i=3;i<=n;i++)
{
while(ll<rr&&dn(jd(s[rr],s[rr-1]),l[i]))
rr--;
while(ll<rr&&dn(jd(s[ll],s[ll+1]),l[i]))
ll++;
s[++rr]=l[i];
}
while(ll<rr&&dn(jd(s[rr],s[rr-1]),s[ll]))
rr--;
printf("%d\n",(rr-ll>1));
}
return 0;
}
poj 3130 How I Mathematician Wonder What You Are! 【半平面交】的更多相关文章
- POJ 3130 How I Mathematician Wonder What You Are! (半平面交)
题目链接:POJ 3130 Problem Description After counting so many stars in the sky in his childhood, Isaac, n ...
- POJ 3130 How I Mathematician Wonder What You Are! (半平面相交)
Description After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a ...
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
/* poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 */ #include <stdio.h> #include ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- poj 3130 How I Mathematician Wonder What You Are!
http://poj.org/problem?id=3130 #include <cstdio> #include <cstring> #include <algorit ...
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...
- POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...
- POJ 3525 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
随机推荐
- Java的方法
以下内容引用自http://wiki.jikexueyuan.com/project/java/methods.html: 一个Java方法是为了执行某个操作的一些语句的组合.举个例子来说,当调用Sy ...
- Jmeter的几个关键配置文件
1.配置文件位于bin目录下: 2.配置文件可能存在优先级关系,好像user.properties会覆盖jmeter.properties,一般修改配置都是修改或者添加user.properties, ...
- 【Nginx】发送响应
请求处理完毕后,需要向用户发送http响应,告知客户端Nginx的执行结果.http响应主要包括响应行.响应头部.包体三部分.发送http响应时需要执行发送http头部(发送http头部时也会发送响应 ...
- apc smart UPS下使用apcupsd注意事项
公司的apc smart UPS安装有管理卡(似乎是AP-9631),server环境有FreeBSD.Windows Server.Linux(CentOS.Ubuntu) 实际使用中有例如以下问题 ...
- hdoj 3351 Seinfeld 【栈的简单应用】
Seinfeld Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- [RxJS] Create a Reusable Operator from Scratch in RxJS
With knowledge of extending Subscriber and using source.lift to connect a source to a subscriber, yo ...
- FFMpeg2.4.2 on Ubuntu14.04
FFmpeg 2.4 "Fresnel" – is the leading multimedia framework, cross-platform solution tha ...
- Tomcat9无法启动
闲来无事,重新学习一下Java, 去Tomcat官网下载Tomcat,各种版本,7-8-9,果断下载最新的9,解压后,无需安装,到bin文件夹下启动, 结果总是一闪而过,百度: 1.查看8080是否占 ...
- js权威指南
有很多js的细节基础不太了解,希望能通过阅读这本书查漏补缺!长期更新!
- jquery中一些容易忽略的方法
jquery.ajaxPrefilter:([dataTypes],handle(options,originalOptions,jqXHR)):在发送请求之前和执行$.ajax之前操作options ...