POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核。
思路:半平面交求多边形是否有核。模板题。
定义:
多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 )。核内的点与多边形所有顶点的连线均在多边形内部。
半平面交:对于平面,任何直线都能将平面划分成两部分,即两个半平面。半平面交既是多个半平面的交集。定义如其名。
半平面交求多边形的核。
设多边形点集为 *p,核的点集为*cp。
开始时将p的所有点放到cp内,然后枚举多边形的所有边去切割cp,cp中在边内侧的点保留,外侧的点删除,注意添加交点。
在边的内侧或外侧可以用叉乘来判断,还有注意多边形点集的顺序是逆时针还是顺时针。
将3130的代码中的1改成 YES,0 改成 NO ,大于-EPS 改成 小于 EPS 就是 3335的代码。。。。。。无耻的暗爽中
POJ 3130
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string> #define LL long long
#define EPS (1e-9)
#define Right 1;
#define Left -1; using namespace std; struct P
{
double x,y;
} p[55],tp[2510],cp[2510]; double X_Mul(P a1,P a2,P b1,P b2)
{
P v1 = {a2.x-a1.x,a2.y-a1.y},v2 = {b2.x-b1.x,b2.y-b1.y};
return v1.x*v2.y - v1.y*v2.x;
} P Cal_Cross_Position(P a1,P a2,P b1,P b2)
{
double t = fabs(X_Mul(a1,a2,a1,b1))/fabs(X_Mul(a1,a2,b2,b1));
P p = {b1.x + (b2.x-b1.x)*t,b1.y + (b2.y-b1.y)*t};
return p;
} int Cut_Polygon(P a1,P a2,P *tp,int n,P *cp)
{
double xm1,xm2;
int i ,top = 0;
for(i = 0;i < n; ++i)
{
xm1 = X_Mul(a1,a2,a1,tp[i]),xm2 = X_Mul(a1,a2,a1,tp[i+1]);
if(xm1 > -EPS && xm2 > -EPS)
{
cp[top++] = tp[i];
}
else if(xm1 > -EPS || xm2 > -EPS)
{
if(xm1 > -EPS)
{
cp[top++] = tp[i];
}
cp[top++] = Cal_Cross_Position(a1,a2,tp[i],tp[i+1]);
}
}
cp[top] = cp[0];
return top;
} void Is_Star(P *tp,P *cp,P *p,int n)
{
int i,j,top; for(i = 0;i <= n; ++i)
{
tp[i] = p[i];
} for(top = n,i = 0;i < n; ++i)
{
top = Cut_Polygon(p[i],p[i+1],tp,top,cp);
//cout<<"top = "<<top<<endl;
if(top == 0)
{
cout<<"0"<<endl;
return ;
} for(j = 0;j <= top; ++j)
{
tp[j] = cp[j];
} }
cout<<"1"<<endl;
} int main()
{
int i,n;
while(scanf("%d",&n) && n)
{
for(i = 0; i < n; ++i)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
} p[n] = p[0]; Is_Star(tp,cp,p,n);
}
return 0;
}
POJ 3335
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string> #define LL long long
#define EPS (1e-9)
#define Right 1;
#define Left -1; using namespace std; struct P
{
double x,y;
} p[55],tp[2510],cp[2510]; double X_Mul(P a1,P a2,P b1,P b2)
{
P v1 = {a2.x-a1.x,a2.y-a1.y},v2 = {b2.x-b1.x,b2.y-b1.y};
return v1.x*v2.y - v1.y*v2.x;
} P Cal_Cross_Position(P a1,P a2,P b1,P b2)
{
double t = fabs(X_Mul(a1,a2,a1,b1))/fabs(X_Mul(a1,a2,b2,b1));
P p = {b1.x + (b2.x-b1.x)*t,b1.y + (b2.y-b1.y)*t};
return p;
} int Cut_Polygon(P a1,P a2,P *tp,int n,P *cp)
{
double xm1,xm2;
int i ,top = 0;
for(i = 0;i < n; ++i)
{
xm1 = X_Mul(a1,a2,a1,tp[i]),xm2 = X_Mul(a1,a2,a1,tp[i+1]);
if(xm1 < EPS && xm2 < EPS)
{
cp[top++] = tp[i];
}
else if(xm1 < EPS || xm2 < EPS)
{
if(xm1 < EPS)
{
cp[top++] = tp[i];
}
cp[top++] = Cal_Cross_Position(a1,a2,tp[i],tp[i+1]);
}
}
cp[top] = cp[0];
return top;
} void Is_Star(P *tp,P *cp,P *p,int n)
{
int i,j,top; for(i = 0;i <= n; ++i)
{
tp[i] = p[i];
} for(top = n,i = 0;i < n; ++i)
{
top = Cut_Polygon(p[i],p[i+1],tp,top,cp);
//cout<<"top = "<<top<<endl;
if(top == 0)
{
cout<<"NO"<<endl;
return ;
} for(j = 0;j <= top; ++j)
{
tp[j] = cp[j];
} }
cout<<"YES"<<endl;
} int main()
{
int i,n;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i = 0; i < n; ++i)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
} p[n] = p[0]; Is_Star(tp,cp,p,n);
}
return 0;
}
POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交的更多相关文章
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
/* poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 */ #include <stdio.h> #include ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- 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 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- 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! (半平面相交)
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!(半平面交求多边形的核)
题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...
- poj 3130 How I Mathematician Wonder What You Are! 【半平面交】
求多边形的核,直接把所有边求半平面交判断有无即可 #include<iostream> #include<cstdio> #include<algorithm> # ...
随机推荐
- SSH应该使用密钥还是密码?
关于SSH,几乎每个人都同意密钥要优于密码,更安全,并且更先进,但我并不同意这个观点. 虽然密钥的确可以更好,但它有着还没被意识到的严重风险,并且我认为比得到妥善管理的密码更不安全. 通常密钥更好的理 ...
- 【HDOJ】4328 Cut the cake
将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. /* 4328 */ #include <iostream> #include <sstream&g ...
- 大四实习准备3_java多线程
4.25.27无耻地懒散了.....26号陪女朋友去了.今天28号,继续加油! 2015-4-28 Java 多线程 (java中类不能多继承,可以多层继承:接口则都可以) 定义和创建: 方法一:继承 ...
- bzoj2456
有趣的题目 空间1mb,所以开数组的算法就不要想了(我一开始没看到……) 仔细读题,然后发现这里他限定众数为出现超过n div 2次 也就是说,这个数可以对应每一个不相同的数消掉,最终还剩下这个数 也 ...
- [原]Unity3D深入浅出 - 光源组件(Light)
Unity中提供了四种光源: Directional light: 方向光,类似太阳的日照效果. Point light: 点光源,类似蜡烛. Spotlight: 聚光灯,类似手电筒. Area L ...
- FormsAuthentication实现单点登录
原文地址:http://www.wlm.so/Article/Detail/lmb48bk9f690n00000 单点登录,这种在网络非常常见,在这里讨论的是实现同一主域下的子站间的单点登录,同样也适 ...
- 【转】使用NDK生成native C/C++的可执行程序
原文网址:http://www.linuxidc.com/Linux/2011-08/40901.htm 众所周知, NDK可以生成lib,让java程序通过jni来调用,其实,NDK也可以生成C/C ...
- [开发工具] 史上最全系列之开发环境搭建之DDMS
原文链接:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=275774 一.简介 DDMS 的全称是DalvikDebug Mon ...
- Js获取Cookie值的方法
function getCookie(name) { var prefix = name + "=" var start = document.cookie.indexOf(pre ...
- JS组件Bootstrap实现弹出框和提示框效果代码
这篇文章主要介绍了JS组件Bootstrap实现弹出框和提示框效果代码,对弹出框和提示框感兴趣的小伙伴们可以参考一下 前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编 ...