POJ 3335 Rotating Scoreboard(多边形的核)
我看的这里:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html
然后整理一下当做模版。0换成eps,会wa,应该要写成精度特判把。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define N 110
struct point
{
double x,y;
}p[N],temp[N],pre[N];
int n,m;
double a,b,c;
void getline(point x,point y)
{
a = y.y - x.y;
b = x.x - y.x;
c = y.x * x.y - x.x * y.y;
}
point intersect(point x,point y) //获取直线ax+by+c==0 和点x和y所连直线的交点
{
double u = fabs(a*x.x+b*x.y+c);
double v = fabs(a*y.x+b*y.y+c);
point ans;
ans.x = (x.x*v+y.x*u)/(u+v);
ans.y = (x.y*v+y.y*u)/(u+v);
return ans;
}
void cut()
{
int num = ,i;
for(i = ;i <= m;i ++)
{
if(a*p[i].x + b*p[i].y + c >= )
{
temp[++num] = p[i];
}
else
{
if(a*p[i-].x + b*p[i-].y + c > )
temp[++num] = intersect(p[i],p[i-]);
if(a*p[i+].x + b*p[i+].y + c > )
temp[++num] = intersect(p[i],p[i+]);
}
}
for(i = ;i <= num;i ++)
p[i] = temp[i];
p[] = p[num];
p[num+] = p[];
m = num;
}
void fun()
{
int i;
m = n;
for(i = ;i <= n;i ++)
{
getline(pre[i],pre[i+]);
cut();
}
}
int main()
{
int i,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i = ;i <= n;i ++)
{
scanf("%lf%lf",&pre[i].x,&pre[i].y);
p[i] = pre[i];
}
pre[n+] = pre[];
p[n+] = p[];
p[] = p[n];
fun();
if(m)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
POJ 3335 Rotating Scoreboard(多边形的核)的更多相关文章
- 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 3335 Rotating Scoreboard (Half Plane Intersection)
3335 -- Rotating Scoreboard 给出一个多边形,要求判断它的内核是否存在. 还是半平面交的题,在这道题中,公告板允许其所在位置与直线共线也算是可见,于是我们就可以将每一条直线微 ...
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- POJ 3335 Rotating Scoreboard(半平面交求多边形核)
题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...
- poj 3335 Rotating Scoreboard
http://poj.org/problem?id=3335 #include <cstdio> #include <cstring> #include <algorit ...
- How I Mathematician Wonder What You Are! - POJ 3130(求多边形的核)
题目大意:判断多多边形是否存在内核. 代码如下: #include<iostream> #include<string.h> #include<stdio.h> # ...
随机推荐
- Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...
- 【leetcode】Combination Sum
Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...
- Java,Calendar 获得明天凌晨的时间time
/** * 获得明天凌晨的时间time * * @return */ private long getNextDayZeroTime() { Calendar calendar = Calendar. ...
- Java for LeetCode 023 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解 ...
- UVA 10325 The Lottery( 容斥原理)
The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. ...
- register
register:这个关键字请求编译器尽可能的将变量存在CPU内部寄存器中,而不是通过内存寻址访问,以提高效率.注意是尽可能,不是绝对.你想想,一个CPU 的寄存器也就那么几个或几十个,你要是定义了很 ...
- telnet 测试端口是否打开
[root@mysqld ~]# yum list |grep telnet telnet.x86_64 1:0.17-48.el6 @base telnet-server.x86_64 1:0.17 ...
- 【Linux工具】GIT+Gollum在Ubuntu下搭建本地WIKI编辑系统
1 设置淘宝的gem镜像 1.1 不用镜像的痛苦 如果直接用官网的话,会有如下的错误信息,添加源.安装gem都是一样的错误,就算能连上也会很慢: $ gem sources -a https://ru ...
- 让Entity Framework支持MySql数据库(转载)
转载地址:http://www.cnblogs.com/wintersun/archive/2010/12/12/1903861.html Entity Framework 4.0 也可以支持大名鼎鼎 ...
- 继承ActionSupport,返回INPUT的原因
http://developer.51cto.com/art/200907/134757.htm 表面现象: 在WebWork中,当一个Action中既没有重写ActionSupport中的valid ...