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> # ...
随机推荐
- <转载>编程珠玑-位排序(bitsort)
转载:http://www.cnblogs.com/shuaiwhu/archive/2011/05/29/2065039.html 维护版权 在<编程珠玑>一书上,有一题是将一堆不 ...
- Helloworld模块之内核makefile详解
Hello World 模块以及对应的内核makefile详解 hello.c: #include <linux/module.h> //所有模块都需要的头文件 #include < ...
- golang的函数
在golang中, 函数是第一类值(first-class object), 即函数可以赋值与被赋值. 换言之, 函数也可以作为ReceiverType, 定义自己的method. 实例: http. ...
- Objective - C中属性和点语法的使用
一.属性 属性是Objective—C 2.0定义的语法,为实例变量提供了setter.getter方法的默认实现能在一定程度上简化程序代码,并且增强实例变量的访问安全性 ...
- RSA和DES------加密和解密类
public class CryptogramUtil { //******************************************************************** ...
- angular2 国际化实现
angular2国际化通过管道(pipe)的形式实现下载ng2-translate 如何使用可以参照https://github.com/ocombe/ng2-translate 自己写了一个小DEM ...
- java提供了native2ascii工具
可以使用这个工具,把中文编码称为ascii码 在命令行输入native2ascii 输入中文 得到数据
- java类中定义接口
今天看到一个java类中定义了接口,写个备忘录,记录一下 package com.gxf.test; public class Test_interface { public interface sh ...
- 11.6Daily Scrum
人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.817 数据库测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.818 实现视频浏览的功能 王 ...
- 向Array中添加快速排序
快速排序思路 1) 假设第一个元素为基准元素 2) 把所有比基准元素小的记录放置在前一部分,把所有比基准元素大的记录放置在后一部分,并把基准元素放在这两部分的中间(i=j的位置) 快速排序实现 Fun ...