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 //大牛们常说的测模板题 ------------------------------------------------- ...
随机推荐
- jQuery Lint: enables you to automatically inject jQuery Lint into the page as it is loaded (great for ad-hoc code validation)
FireQuery is a Firebug extension for jQuery development jQuery Lint: enables you to automatically in ...
- hdu 4497 GCD and LCM(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)
质分解 + 简单计数.当时去比赛的时候太年轻了...这道题都没敢想.现在回过头来做了一下,发现挺简单的,当时没做这道题真是挺遗憾的.这道题就是把lcm / gcd 质分解,统计每个质因子的个数,然后 ...
- oracle中clob字段的使用
oracle中定义了一个字段是clob的,由于用的是ssh的框架,结果在面向对象存取的时候出现clob类型字段和String类型字段的转换问题.开始查阅了clob字段和String字段的相互转换的方法 ...
- HTML本地存储,localstorg的应用实例
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- Android学习路线(二十)运用Fragment构建动态UI
要在Android系统上创建一个动态或者多面板的用户界面,你须要将UI组件以及activity行为封装成模块.让它可以在你的activity中灵活地切换显示与隐藏. 你可以使用Fragment类来创建 ...
- android UI进阶之用ViewPager实现欢迎引导页面[转]
ViewPager需要android-support-v4.jar这个包的支持,来自google提供的一个附加包.大家搜下即可. ViewPager主要用来组织一组数据,并且通过左右滑动的方式来展示. ...
- Problem A: Artificial Intelligence?
Description Physics teachers in high school often think that problems given as text are more demandi ...
- A Byte of Python 笔记(9) 面向对象编程
第11章 面向对象编程 面向过程:根据操作数据的函数或语句块来设计程序. 面向对象(OOP, object-oriented programming):把数据和功能结合起来,用对象包裹组织程序. 类 ...
- Bootstrap Alert 使用
参考 http://www.bootcss.com/javascript.html#alerts 不过这里没有动态alert的例子 于是再参考http://stackoverflow.com/ques ...
- Oracle中sign函数和decode函数的使用
Oracle中sign函数和decode函数的使用 1.比较大小函数SIGN sign(x)或者Sign(x)叫做 符号函数,其功能是取某个数的符号(正或负): 当x>0,sign(x)=1; ...