POJ 3335
/*半平面交求核心的增量法:
假设前N-1个半平面交,对于第N个半平面,只需用它来交前N-1个平面交出的多边形。
算法开始时,调整点的方向为顺时针方向,对于是否为顺时针,只需求出其面积,若为正,必为逆时针的。
对于每相邻两点求出一条直线,用该直线去交其半平面,并求出交点及判断原多边形点的方位。
*/ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN=110;
const double eps=1e-8; struct point {
double x,y;
};
point pts[MAXN],p[MAXN],q[MAXN];
int n,cCnt,curCnt; int DB(double d){
if(d>eps) return 1;
if(d<-eps) return -1;
return 0;
} double getArea(point *tmp, int n){
double ans=0;
for(int i=1;i<=n;i++)
ans+=(tmp[i].x*tmp[i+1].y-tmp[i].y*tmp[i+1].x);
return ans/2;
} void Adjust(point *ps,int n){
for(int i = 1; i < (n+1)/2; i ++)
swap(ps[i], ps[n-i]);
} void initial(){
double area=getArea(pts,n);
if(DB(area)==1) Adjust(pts,n);
for(int i=1;i<=n;i++)
p[i]=pts[i];
p[n+1]=p[1];
p[0]=p[n];
cCnt=n;
} void getline(point x,point y,double &a,double &b,double &c){
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,double a,double b,double c){
double u = fabs(a * x.x + b * x.y + c);
double v = fabs(a * y.x + b * y.y + c);
point pt;
pt.x=(x.x * v + y.x * u) / (u + v);
pt.y=(x.y * v + y.y * u) / (u + v);
return pt;
} void cut(double a,double b,double c){
curCnt=0;
for(int i=1;i<=cCnt;i++){
if(DB(a*p[i].x+b*p[i].y+c)>=0) q[++curCnt] = p[i];
else {
if(DB(a*p[i-1].x + b*p[i-1].y + c )>0){
q[++curCnt] = intersect(p[i],p[i-1],a,b,c);
}
if(DB(a*p[i+1].x + b*p[i+1].y + c )> 0){
q[++curCnt] = intersect(p[i],p[i+1],a,b,c);
}
}
}
for(int i = 1; i <= curCnt; ++i)p[i] = q[i];
p[curCnt+1] = q[1];p[0] = p[curCnt];
cCnt = curCnt;
} void slove(){
initial();
for(int i=1;i<=n;i++){
double a,b,c;
getline(pts[i],pts[i+1],a,b,c);
cut(a,b,c);
}
} int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&pts[i].x,&pts[i].y);
pts[n+1]=pts[1];
slove();
if(cCnt>=1) printf("YES\n");
else printf("NO\n");
}
return 0;
}
POJ 3335的更多相关文章
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
/*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130
求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...
- poj 3335(半平面交)
链接:http://poj.org/problem?id=3335 //大牛们常说的测模板题 ------------------------------------------------- ...
- poj 3335 Rotating Scoreboard
http://poj.org/problem?id=3335 #include <cstdio> #include <cstring> #include <algorit ...
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...
随机推荐
- Java 发送短信
这是一个调用sms接口发短信的程序,支持同时发送的短信量并不是很大,只作为学习使用(当然如果你想内部使用也行) 源码:package com; import org.apache.commons.ht ...
- PCB LDI 实现周期自动更新 实现思路
一.基本思路整理如下: 二.封周期启动程序C#代码(部份代码) /// <summary> /// 单个生产型号 更新周期 /// </summary> /// <par ...
- Power Network(最大流(EK算法))
http://poj.org/problem?id=1459 题意:有一个电路网络,每个节点可以产生.传递.消耗若干电量,有点线连接结点,每个电线有最大传输量,求这个网络的最大消费量. 思路:从源点到 ...
- go之map
一.概念 简述 1.map 是一种无序的键值对的集合.(类似于python的字典dict) 2.map 的key 与 value 都是有类型的,且定义阶段时就已经统一 定义方式 # 方式一 var m ...
- WebService的概念
一.序言 大家或多或少都听过 WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成 分.但是不得不承认的是W ...
- git add -A (用该命令添加文件时报错)
前言 最近在学着不使用github客户端,而直接用git命令上传代码至github,当使用命令 git add -A 添加所有项目文件时报错 老实说我是蒙蔽的,因为从来没有遇到过这个错,确认输入 ...
- D - Vanya and Fence
Problem description Vanya and his friends are walking along the fence of height h and they do not wa ...
- spring事务回滚问题
刚刚接到一个上家公司同事的一个电话,问我为什么service方法事务不会滚了,日志打印了,调用webservice报错. 我让他把这个调用执行webservice的方法截图发给我,如下: publ ...
- 《java数据结构与算法》系列之“数组"
int arrayName = new int[10] ;2 int arrayLength = arrayName.length; 解释:java有两种数据类型,一种是基本类型,如int等,一种是引 ...
- 【PostgreSQL-9.6.3】extract函数
extract函数格式: extract (field from source) extract函数是从日期或者时间数值里面抽取子域,比如年.月.日等.source必须是timestamp.time. ...