/***************
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 半平面交 求核的面积的更多相关文章

  1. 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130

    求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...

  2. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  3. POJ 3335 Rotating Scoreboard 半平面交求核

    LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...

  4. POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交

    题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...

  5. POJ 1279 Art Gallery 半平面交/多边形求核

    http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...

  6. poj 3335 Rotating Scoreboard - 半平面交

    /* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...

  7. POJ 3304 Segments 基础线段交判断

    LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断 ...

  8. POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)

    POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...

  9. poj 3335(半平面交)

    链接:http://poj.org/problem?id=3335     //大牛们常说的测模板题 ------------------------------------------------- ...

随机推荐

  1. crtmpserver初探

    前言       Adobe的FMS(Flash Media Server)是很好用.但对应着分级授权的是money和有限功能开放.商业的东西既然用不起,也阻碍了我们的技术进步,那就只能求助于开源社区 ...

  2. Microsoft Azure 负载平衡服务

     Microsoft Azure 为在其中托管的虚拟机(IaaS) 和云服务(PaaS) 提供负载平衡服务.负载平衡支持应用程序伸缩,并且提供应用程序故障恢复以及其他优势. 可以通过以下方式访问负 ...

  3. 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题

    最近因为项目里需求是选择或者拍摄多张照片后,提供滑动预览和上传,很多照片是好几MB一张,因为目前的Android系统对运行的程序都有一定的内存限制,一般是16MB或24MB(视平台而定),不做处理直接 ...

  4. HTTP学习笔记——URL与资源

    什么是URL? 所有的东西都有一个标准化的东西,公交有线路号,飞机有航班号,个人有身份证号,你坐出租车,告诉司机师傅我要到石牌华师,他就能明白你的意思了.URL就是因特网资源的标准化名称.URL指向一 ...

  5. SQL Server2012新特性概述

    公司最近要升级数据库,SQL Server 2008R2-->2012.再开始升级之前先找了点资料分析一下2012的新特性和功能,提前预热一下. 2012中主要关注一下三个领域: 性能:改进的核 ...

  6. Jsp指令有那些?

    <%@page language="java" contentType="text/html;charset=gb2312" session=" ...

  7. Hibernate - cascade-and -session_state

    cascade属性: 默认为none,代表不级联. 级联是指操作主对象时,对关联的对象也做相同的操作. 可设为:delete, save-update, all, none ...-- 一般是对象只归 ...

  8. C++ const 限定符

    C++ const 限定符 作用:把一个对象转换成一个常量 用法:const type name = value; 性质:1. 定义时必须初始化,定义后不能被修改.2. 类中的const成员变量必须通 ...

  9. Apache与Nginx网络模型

    Nginx的高并发得益于其采用了epoll模型,与传统的服务器程序架构不同,epoll是linux内核2.6以后才出现的.下面通过比较Apache和Nginx工作原理来比较. 传统Apache都是多进 ...

  10. C#中小函数的应用

    今天看到的一段函数 StringBuilder sb = new StringBuilder("sselect * from table where 1=1"); if(TextB ...