/***************
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. 开源搜索技术—Lucene、Solr

    Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引 ...

  2. php mvc 框架演示

    <pre name="code" class="cpp"><pre name="code" class="pyt ...

  3. VC实现卡拉OK字幕叠加

    一. GDI编程基础 字幕叠加,应当是属于图形.图像处理的范畴.在Windows平台上,图形.图像处理的方法当然首选GDI(Graphics Device Interface,图形设备接口).GDI是 ...

  4. C# 保留小数点后两位(方法总结)

    最简单使用: float i=1.6667f; string show=i.ToString("0.00"); //结果1.67(四舍五入) 其他类似方法: string show ...

  5. java线程的使用(Runnable)

    在实际项目开发过程中,线程是经常要用到的,特别是为了不影响项目的运行效果. 以下就以实际项目中的简单例子来介绍: public class SystemRedisInfoController exte ...

  6. 浅谈Struts2(二)

    一.struts2的跳转 1.action跳转JSP a.默认为forward <action name="action1" class="com.liquidxu ...

  7. #ifndef 与 #program once 的区别(转)

    转自http://hi.baidu.com/hrx20091001/item/ee70f7cc6d036d4ea9ba94e0 #ifndef 与 #program once 的区别 为了避免同一个文 ...

  8. python初探-copy

    python中,数据的拷贝有以下三种形式:赋值.浅copy和深copy.根据类型的不同,可以把数据分成以下两类:字符串和数字为一类,其他(包括列表.元祖.字典...)为一类. 在python中有池的概 ...

  9. C++获取当前机器内网IP地址

    /*头文件*/ #include "winsock2.h" #pragma comment(lib,"ws2_32.lib") /*Hui 获取当前服务器IP* ...

  10. 斯坦福 IOS讲义 课件总结 二

    1,OC里面传参数个数不同,可以是两个完全不同的方法.如 - (void)addCard:(Card *)card atTop:(BOOL)atTop; - (void)addCard:(Card * ...