POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内。
思路 : 与3335一样,不过要注意方向变化一下。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h> using namespace std ; struct node
{
double x;
double y ;
} p[],temp[],newp[];//p是最开始的多边形的每个点,temp是中间过程中临时存的多边形的每个点,newp是切割后的多边形的每个点
int n,newn ;//原来的点数,切割后的点数
double a,b,c ;//直线方程的三个系数 void getline(node x,node y)//求x与y两点确定的直线方程ax+by+c=0
{
a = y.y-x.y ;
b = x.x-y.x ;
c = y.x*x.y - y.y*x.x ;
}
node intersect(node x,node y)//求x与y点确定的直线与ax+by+c=0这条直线的交点
{
double u = fabs(a*x.x+b*x.y+c) ;
double v = fabs(a*y.x+b*y.y+c) ;
node t ;
t.x = (x.x*v+y.x*u)/(u+v) ;//y.y-x.y=u+v;y.y-t.y=v;y.y-x.y=u;
t.y = (x.y*v+y.y*u)/(u+v) ;
return t ;
}
void cut()
{
int cutn = ;
for(int i = ; i <= newn ; i++)
{
if(a*newp[i].x+b*newp[i].y+c >= )//所有的点都大于0,说明所有的点都在这条直线的另一边,所以不用切
temp[ ++cutn] = newp[i] ;
else
{
if(a*newp[i-].x+b*newp[i-].y+c > )
temp[++cutn ] = intersect(newp[i-],newp[i]) ;//把新交点加入
if(a*newp[i+].x+b*newp[i+].y+c > )
temp[ ++cutn] = intersect(newp[i+],newp[i]) ;
}
}
for(int i = ; i <= cutn ; i++)
newp[i] = temp[i] ;
newp[cutn+] = temp[] ;//能够找出所有点的前驱和后继
newp[] = temp[cutn] ;
newn = cutn ;
} void solve()
{
for(int i = ; i <= n ; i++)
{
newp[i] = p[i] ;
}
p[n+] = p[] ;
newp[n+] = newp[] ;
newp[] = newp[n] ;
newn = n ;
for(int i = ; i <= n ; i++)
{
getline(p[i],p[i+]) ;//从头开始顺序遍历两个相邻点。
cut() ;
}
}
void guizhenghua()
{
for(int i = ; i < (n+)/ ; i++)//规整化方向,顺时针变逆时针,逆时针变顺时针。
swap(p[i],p[n-i]) ;
}
int main()
{
while(scanf("%d",&n)!=EOF && n)
{
for(int i = ; i <= n ; i++)
scanf("%lf %lf",&p[i].x,&p[i].y) ;
guizhenghua() ;
p[n+] = p[] ;
solve() ;
if(newn == ) puts("") ;
else puts("") ;
}
return ;
}
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 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】
<题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- 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 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- poj 3130 How I Mathematician Wonder What You Are!
http://poj.org/problem?id=3130 #include <cstdio> #include <cstring> #include <algorit ...
- How I Mathematician Wonder What You Are! - POJ 3130(求多边形的核)
题目大意:判断多多边形是否存在内核. 代码如下: #include<iostream> #include<string.h> #include<stdio.h> # ...
- poj 3130 How I Mathematician Wonder What You Are! 【半平面交】
求多边形的核,直接把所有边求半平面交判断有无即可 #include<iostream> #include<cstdio> #include<algorithm> # ...
随机推荐
- 在Java如何保证方法是线程安全的
废话开篇 都说Java程序好些,但是我觉得Java编程这东西,没个十年八年的真不敢说自己精通Java编程,由于工作原因,开始转战Java多线程,以前没怎么接触过,所以想留点脚印在这两条路上. 切入正题 ...
- 读:HIS 与医保系统的接入方案及实现
HIS 与医保系统的接入方案及实现刘剑锋 李刚荣第三军医大学西南医院信息科(重庆 400038) 医院HIS和医保系统的接口设计方案涉及两个部分,分别由医院和医保中心分别完成相,应的程序设计,这两部分 ...
- C++异常机制知识点
在这里总结一下,C++中的异常机制,以及如何使用异常的知识点 C++中处理异常的过程是这样的:在执行程序发生异常,可以不在本函数中处理,而是抛出一个错误信息,把它传递给上一级的函数来解决,上一级解决 ...
- iOS9新系统下APP Store 应用上传新指南
一 iTunes Connect介绍 iTunes Connect是面向iOS应用开发人员的苹果门户网站,供开发人员管理其应用,跟踪下载情况.今年1月份闹得沸沸扬扬的iTunes Connect BU ...
- C++设计模式——享元模式
本文版权归果冻说所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利.如果这篇文章对你有帮助,你可以请我喝杯咖啡. » 本文链接:http:// ...
- Centering HTML elements larger than their parents
Centering HTML elements larger than their parents It's not a common problem, but I've run into it a ...
- Indigo Studio
http://www.infragistics.com/products/indigo-studio?gclid=CIXrnav4lcQCFdclvQoduVEAnA
- 分布式架构--第一篇--项目拆分(maven命令生成多模块项目)
预览生成的项目结构: ying-yue-parent // 顶级总编译控制模块 ying-yue-lib // jar模块 ying-yue-model // 模型对象模块 ying-yue-dao ...
- [转载]EF Code First 学习笔记:约定配置
要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一个就 ...
- 尝试用Uplodify
尝试用Uplodify Uplodify官方 前台index代码: @{ Layout = null; } <script src="~/Scripts/jquery-1.8. ...