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 //大牛们常说的测模板题 ------------------------------------------------- ...
随机推荐
- android之获取应用中的图片资源_获取找你妹中的图片资源
一直不知道原来获取一个应用中的图片资源这么简单,刚才直接把apk解压,就得到了里面的一下文件,搜索一下就全部把图片资源找出来了,想要模仿应用或者自己不会ui的话,用现成的资源方便多了. 也没多少说的, ...
- kbengine Unity3d demo 代码执行流程(4)
当服务端成功启动,客户端链接服务端后进入demo中的游戏界面,demo中的功能包括注册.登录.角色管理.战斗.场景等等. 对于新接触kbengine的人,看见客户端的代码后会觉得很迷茫,有些无从下手. ...
- xmu1125 越野车大赛(三分)
1125: 越野车大赛 Time Limit: 500 MS Memory Limit: 64 MB Special JudgeSubmit: 4 Solved: 3[Submit][Statu ...
- 二分查找(Java)
二分查找的前提的要查找的数组必须有序. 代码如下: 程序1 public class source { public int binary_sort(int[] array, int item) { ...
- PHP发送短信如何实现?
最近要用php发送和接收短信,用户订单要用短信通知一类的功能,网上看了好多短信平台感觉都不靠谱. 也测试了很多代码,下面把几款PHP发送短信好用的分享给大家: PHP发送短信方法一(比较好,推荐) / ...
- Android 开发笔记“context和getApplicationContext”
在android中常常会遇到与context有关的内容 浅论一下context : 在语句 AlertDialog.Builder builder = new AlertDialog.Builder( ...
- 10-C语言函数
目录: 一.函数 二.return与exit关键字 三.递归与递推 回到顶部 一.函数 1 函数由函数名.返回值.形参.函数体组成. 函数的使用分三个步骤:声明.定义.调用 2 语法格式: 返回值类型 ...
- ios 学习笔记(8) 控件 按钮(UIButton)的使用方法
在实际开发中,对于开发者来说,更多的还是使用“自定义”按钮.将“按钮”对象的类型设置成UIButtonTypeCustom.这样一来,按钮的所有元素都将由开发者来配置和自定义. 对于一个自定义按钮来说 ...
- MVC-04 视图(2)
三.View如何从Aciton取得数据 从Action取得数据,在ASP.NET MVC可区分成两种方式,一种是“使用弱类型取得数据”,另一种则是“使用强类型取得数据”,两者的差别在于View页面最上 ...
- DC游戏《斑鸠》原创赏析[转载]
游戏背景: 凤来之国本来只是边远地区的一个小国.但现在他们却自称为得到“神之力”的“神通者”,在“选民思想”“和平统一”之类的名义下开始了对各地的武力侵略. 事情的起因是因为凤来之 ...