poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
/***************
poj 3335 点序顺时针
***************/
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-;
const double maxn = 0x7f7f7f7f;
int dcmp(double x){
if(fabs(x)<eps)
return ;
else
return x<?-:;
}
struct point {
double x,y;
point (double x=,double y =):x(x),y(y){}
};
point p[];
typedef point Vector; struct polygon{
point p[];
int Size;
}; struct line{
point fir,sec;
line(point a = point(),point b = point()){
fir = a;
sec = b;
}
}; Vector operator -(point a,point b){
return Vector(a.x-b.x,a.y-b.y);
} Vector operator *(Vector a,double p){
return Vector (a.x*p,a.y*p);
}
Vector operator + (Vector a,Vector b){
return Vector (a.x+b.x,a.y+b.y);
} double cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
} double dot(Vector a,Vector b){
return a.x*b.x+a.y*b.y;
} point getLineIntersection(point p,Vector v,point q,Vector w){
Vector u = p-q;
double t = cross(w,u)/cross(v,w);
return p+v*t;
} bool onsegment(point p,point a1,point a2){
return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
} polygon cutploygon(polygon poly,line ln){
polygon newploy;
int m=;
int n = poly.Size;
point a = ln.fir,b = ln.sec;
for(int i=;i<n;i++){
point c = poly.p[i];
point d = poly.p[(i+)%n];
double cc = cross(b-a,c-a);
double dd = cross(b-a,d-a);
if(cc>=)
newploy.p[m++] = c;
if(cc*dd<)
newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
}
newploy.Size = m;
return newploy;
} int main()
{
int t;
cin>>t;
int n;
while(t--){
cin>>n;
for(int i=;i<n;i++)
cin>>p[i].x>>p[i].y;
polygon poly;
poly.Size = ;
poly.p[].x = -maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = maxn;
poly.p[].x = -maxn;
poly.p[].y = maxn;
bool flag = true;
for(int i=;i<=n;i++){
line ln;
ln.fir = p[i%n];
ln.sec = p[i-];
poly = cutploygon(poly,ln);
if(poly.Size==){
flag = false;
break;
}
}
if(!flag)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return ;
} /****************************************/
poj 点序逆时针
/****************************************/ #include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-;
const double maxn = 0x7f7f7f7f;
int dcmp(double x){
if(fabs(x)<eps)
return ;
else
return x<?-:;
}
struct point {
double x,y;
point (double x=,double y =):x(x),y(y){}
};
point p[];
typedef point Vector; struct polygon{
point p[];
int Size;
}; struct line{
point fir,sec;
line(point a = point(),point b = point()){
fir = a;
sec = b;
}
}; Vector operator -(point a,point b){
return Vector(a.x-b.x,a.y-b.y);
} Vector operator *(Vector a,double p){
return Vector (a.x*p,a.y*p);
}
Vector operator + (Vector a,Vector b){
return Vector (a.x+b.x,a.y+b.y);
} double cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
} double dot(Vector a,Vector b){
return a.x*b.x+a.y*b.y;
} point getLineIntersection(point p,Vector v,point q,Vector w){
Vector u = p-q;
double t = cross(w,u)/cross(v,w);
return p+v*t;
} bool onsegment(point p,point a1,point a2){
return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
} polygon cutploygon(polygon poly,line ln){
polygon newploy;
int m=;
int n = poly.Size;
point a = ln.fir,b = ln.sec;
for(int i=;i<n;i++){
point c = poly.p[i];
point d = poly.p[(i+)%n];
double cc = cross(b-a,c-a);
double dd = cross(b-a,d-a);
if(cc>=)
newploy.p[m++] = c;
if(cc*dd<)
newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
}
newploy.Size = m;
return newploy;
} int main()
{
int n;
while(cin>>n&&n){
for(int i=;i<n;i++)
cin>>p[i].x>>p[i].y;
polygon poly;
poly.Size = ;
poly.p[].x = -maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = maxn;
poly.p[].x = -maxn;
poly.p[].y = maxn;
bool flag = true;
for(int i=;i<n;i++){
line ln;
ln.fir = p[i%n];
ln.sec = p[(i+)%n];
poly = cutploygon(poly,ln);
if(poly.Size==){
flag = false;
break;
}
}
if(!flag)
cout<<""<<endl;
else
cout<<""<<endl;
}
return ;
} /*************************************/
poj 点序顺时针
/*************************************/
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-;
const double maxn = 0x7f7f7f7f;
int dcmp(double x){
if(fabs(x)<eps)
return ;
else
return x<?-:;
}
struct point {
double x,y;
point (double x=,double y =):x(x),y(y){}
};
point p[];
typedef point Vector; struct polygon{
point p[];
int Size;
}; struct line{
point fir,sec;
line(point a = point(),point b = point()){
fir = a;
sec = b;
}
}; Vector operator -(point a,point b){
return Vector(a.x-b.x,a.y-b.y);
} Vector operator *(Vector a,double p){
return Vector (a.x*p,a.y*p);
}
Vector operator + (Vector a,Vector b){
return Vector (a.x+b.x,a.y+b.y);
} double cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
} double dot(Vector a,Vector b){
return a.x*b.x+a.y*b.y;
} point getLineIntersection(point p,Vector v,point q,Vector w){
Vector u = p-q;
double t = cross(w,u)/cross(v,w);
return p+v*t;
} bool onsegment(point p,point a1,point a2){
return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
} polygon cutploygon(polygon poly,line ln){
polygon newploy;
int m=;
int n = poly.Size;
point a = ln.fir,b = ln.sec;
for(int i=;i<n;i++){
point c = poly.p[i];
point d = poly.p[(i+)%n];
double cc = cross(b-a,c-a);
double dd = cross(b-a,d-a);
if(cc>=)
newploy.p[m++] = c;
if(cc*dd<)
newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
}
newploy.Size = m;
return newploy;
} int main()
{
int n;
int cnt =;
while(cin>>n&&n){
for(int i=;i<n;i++)
cin>>p[i].x>>p[i].y;
polygon poly;
poly.Size = ;
poly.p[].x = -maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = maxn;
poly.p[].x = -maxn;
poly.p[].y = maxn;
bool flag = true;
for(int i=;i<=n;i++){
line ln;
ln.fir = p[i%n];
ln.sec = p[i-];
poly = cutploygon(poly,ln);
if(poly.Size==){
flag = false;
break;
}
}
//cout<<poly.Size<<endl;
cout<<"Floor #"<<cnt++<<endl;
if(!flag)
cout<<"Surveillance is impossible."<<endl;
else
cout<<"Surveillance is possible."<<endl;
cout<<endl;
}
return ;
} /**********************************
poj 1279 点序顺时针
**********************************/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
const double eps = 1e-;
const double maxn = 0x7f7f7f7f;
int dcmp(double x){
if(fabs(x)<eps)
return ;
else
return x<?-:;
}
struct point {
double x,y;
point (double x=,double y =):x(x),y(y){}
};
point p[];
typedef point Vector; struct polygon{
point p[];
int Size;
}; struct line{
point fir,sec;
line(point a = point(),point b = point()){
fir = a;
sec = b;
}
}; Vector operator -(point a,point b){
return Vector(a.x-b.x,a.y-b.y);
} Vector operator *(Vector a,double p){
return Vector (a.x*p,a.y*p);
}
Vector operator + (Vector a,Vector b){
return Vector (a.x+b.x,a.y+b.y);
} double cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
} double dot(Vector a,Vector b){
return a.x*b.x+a.y*b.y;
} point getLineIntersection(point p,Vector v,point q,Vector w){
Vector u = p-q;
double t = cross(w,u)/cross(v,w);
return p+v*t;
} bool onsegment(point p,point a1,point a2){
return dcmp(cross(a1-p,a2-p))==&&dcmp(dot(a1-p,a2-p))<;
} polygon cutploygon(polygon poly,line ln){
polygon newploy;
int m=;
int n = poly.Size;
point a = ln.fir,b = ln.sec;
for(int i=;i<n;i++){
point c = poly.p[i];
point d = poly.p[(i+)%n];
double cc = cross(b-a,c-a);
double dd = cross(b-a,d-a);
if(cc>=)
newploy.p[m++] = c;
if(cc*dd<)
newploy.p[m++] = getLineIntersection(a,b-a,c,d-c);
}
newploy.Size = m;
return newploy;
} double polyArea(point *p,int n){
double area =;
for(int i=;i<n-;i++){
area += cross(p[i]-p[],p[i+]-p[]);
}
return area/;
} int main()
{
int t;
cin>>t;
int n;
while(t--){
cin>>n;
for(int i=;i<n;i++)
cin>>p[i].x>>p[i].y;
polygon poly;
poly.Size = ;
poly.p[].x = -maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = -maxn;
poly.p[].x = maxn;
poly.p[].y = maxn;
poly.p[].x = -maxn;
poly.p[].y = maxn;
bool flag = true;
for(int i=;i<=n;i++){
line ln;
ln.fir = p[i%n];
ln.sec = p[i-];
poly = cutploygon(poly,ln);
if(poly.Size==){
flag = false;
break;
}
}
double res;
if(!flag)
res =;
else{
res = polyArea(poly.p,poly.Size);
}
printf("%.2lf\n",res);
}
return ;
}
poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积的更多相关文章
- 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130
求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...
- 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: ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- POJ 1279 Art Gallery 半平面交/多边形求核
http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- POJ 3304 Segments 基础线段交判断
LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- poj 3335(半平面交)
链接:http://poj.org/problem?id=3335 //大牛们常说的测模板题 ------------------------------------------------- ...
随机推荐
- Centos系统mysql 忘记root用户的密码:
第一步:(停掉正在运行的mysql) [root@maomao ~]# service mysqld stop Stopping MySQL: ...
- wordpress在window下完美实现301重定向的方法
问题: 首先,简单说一下关于301重定向的问题,最简单的理解就是,假设你的主机上绑定有 www.uilike.cn, uilike.cn, www.uiseo.cn三个域名,当你想输入 uilike. ...
- swith 语句详解
switch 语句的格式: switch ( 整型或字符型变量 ) { case 变量可能值1 : 分支一; break; case 变量可能值2 : 分支二; break; case 变量可 ...
- Android 匿名共享内存C接口分析
在Android 匿名共享内存驱动源码分析中详细分析了匿名共享内存在Linux内核空间的实现,虽然内核空间实现了匿名共享内存,但仍然需要在用户空间为用户使用匿名共享内存提供访问接口.Android系统 ...
- TCP状态转换机说明
建立一个 TCP 连接TCP 是一个面向连接的协议,无论哪一方向另一方发送数据之前,都必须先在双方之间建立一条连接.本节将详细讨论一个TCP 连接是如何建立的以及通信结束后是如何终止的. TCP使用三 ...
- xcode 不值钱的动画UIButton
#import "ViewController.h" @interface ViewController () /** 按钮 */ @property(nonatomic,weak ...
- 日常之学习CSS3变形和js函数指针
1,transform变形属性,包括rotate(xxdeg)旋转,translate(x轴px,y轴px)移动,scale(0.5,2)变形(x轴缩小0.5倍,y轴放大2倍),skew(x轴deg, ...
- tomcat 部署web项目异常
项目部署到Tomcat报这样的异常:validateJarFile jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending cla ...
- Android应用开发提高篇(6)-----FaceDetector(人脸检测)
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/10/2388776.html 一.概述 初次看到FaceDetector这个类时,心里想:And ...
- Java web 开发环境配置。
一.配置 win8 64位 环境java 开发环境 1. 下载JDK,地址 http://www.oracle.com/technetwork/java/javase/downloads/index ...