[ACM_几何] Pipe
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/B
#include<iostream> #include<cmath> #include<string.h> #include<string> #include<cstdio> #include<algorithm> #include<iomanip>using namespace std; #define eps 1e-8 #define PI acos(-1.0)//点和向量 struct Point{double x,y;Point(double x=0,double y=0):x(x),y(y){}void out(){cout<<"("<<x<<','<<y<<") ";} }; typedef Point Vector; Vector operator+(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);} Vector operator-(Vector a,Vector 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,double p){return Vector(a.x/p,a.y/p);} bool operator<(const Vector& a,const Vector& b){return a.x<b.x||(a.x==b.x && a.y<b.y);} int dcmp(double x){if(fabs(x)<eps)return 0;else return x<0 ? -1:1; } bool operator==(const Point& a,const Point& b){return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0; } double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//向量点积 double Length(Vector A){return sqrt(Dot(A,A));}//向量模长 double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}//向量夹角 double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;} double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);}//三角形面积的2倍 //绕起点逆时针旋转rad度 Vector Rotate(Vector A,double rad){ return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); } double torad(double jiao){return jiao/180*PI;}//角度转弧度 double tojiao(double ang){return ang/PI*180;}//弧度转角度 //单位法向量 Vector Normal(Vector A){double L=Length(A);return Vector(-A.y/L,A.x/L); } //点和直线 struct Line{Point P;//直线上任意一点Vector v;//方向向量,他的左边对应的就是半平面double ang;//极角,即从x正半轴旋转到向量v所需的角(弧度) Line(){}Line(Point p,Vector v):P(p),v(v){ang=atan2(v.y,v.x);}bool operator<(const Line& L)const {return ang<L.ang;} }; //计算直线P+tv和Q+tw的交点(计算前必须确保有唯一交点)即:Cross(v,w)非0 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; } double getx(Point p1,Point p2,Point p3,Point p4)//找到直线和线段相交的横坐标(求两直线交点) {double k1=(p2.y-p1.y)/(p2.x-p1.x);double k2=(p4.y-p3.y)/(p4.x-p3.x);double b1=p2.y-k1*p2.x;double b2=p3.y-k2*p3.x;return (b2-b1)/(k1-k2);} //点到直线距离(dis between point P and line AB) double DistanceToLine(Point P,Point A,Point B){Vector v1=B-A , v2=P-A;return fabs(Cross(v1,v2))/Length(v1); } //dis between point P and segment AB double DistancetoSegment(Point P,Point A,Point B){if(A==B)return Length(P-A);Vector v1=B-A,v2=P-A,v3=P-B;if(dcmp(Dot(v1,v2))<0)return Length(v2);else if(dcmp(Dot(v1,v3))>0)return Length(v3);else return fabs(Cross(v1,v2))/Length(v1); } //point P on line AB 投影点 Point GetLineProjection(Point P,Point A,Point B){Vector v=B-A;return A+v*(Dot(v,P-A)/Dot(v,v)); } //线段规范相交(只有一个且不在端点)每条线段两端都在另一条两侧,(叉积符号不同) bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2){a2=(a2-a1)*10000000000+a1;//射线A1A2相交线短B1B2double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0; } //判断点P是否在线段AB上 bool OnSegment(Point p,Point a1,Point a2){return dcmp(Cross(a1-p,a2-p))==0 && dcmp(Dot(a1-p,a2-p))<0; } //多边形的面积(可以是非凸多边形) double PolygonArea(Point* p,int n){double area=0;for(int i=1;i<n-1;i++)area+=Cross(p[i]-p[0],p[i+1]-p[0]);return area/2; }//点p在有向直线左边,上面不算 bool OnLeft(Line L,Point p){return Cross(L.v,p-L.P)>0; }double ok(double x,double y,double d,double z){double f=fabs(d*(1/tan(acos(z/y))+1/tan(acos(z/x))))-z;if(fabs(f)<1e-4)return 0;else return f; } //计算凸包输入点数组p,个数n,输出点数组ch,返回凸包定点数 //输入不能有重复,完成后输入点顺序被破坏 //如果不希望凸包的边上有输入点,把两个<=改成< //精度要求高时,建议用dcmp比较 //基于水平的Andrew算法-->1、点排序2、删除重复的然后把前两个放进凸包 //3、从第三个往后当新点在凸包前进左边时继续,否则一次删除最近加入的点,直到新点在左边 int ConVexHull(Point* p,int n,Point*ch){sort(p,p+n);int m=0;for(int i=0;i<n;i++){//下凸包while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;ch[m++]=p[i];}int k=m;for(int i=n-2;i>=0;i--){//上凸包while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;ch[m++]=p[i];}if(n>1)m--;return m; }//****************************************************************************** #define N 21 #define left -10e8 Point up[N],down[N]; int n;double getans()//最值一定过两个顶点一上一下,所以枚举所有点对 {int i,j,k;double ans=left,right;//二分法double tx,ty;Point ql,qr;for(i=0;i<n;i++)for(j=0;j<n;j++){if(i==j)continue;ql=up[i];qr=down[j];right=left;//left是左边界,非常小的一个值,right就是枚举的过两点的直线最远能达的x的大小for(k=0;k<n;k++)//验证枚举直线是否满足所有点 {tx=up[k].x;ty=(tx-ql.x)*(qr.y-ql.y)/(qr.x-ql.x)+ql.y;//求出对应x点在枚举的直线上的y值 if(ty>down[k].y&&ty<up[k].y||fabs(ty-down[k].y)<eps||fabs(ty-up[k].y)<eps)//该y值应在上下之间或与上或下重合right=tx;//更新有边界值else//如果该点时不满足 {if(k)//细节!!! {if(ty<down[k].y)right=getx(ql,qr,down[k-1],down[k]);elseright=getx(ql,qr,up[k-1],up[k]);}break;}}if(right>ans)ans=right;}return ans;}int main(){cout.precision(2);for(;cin>>n&&n;){for(int i=0;i<n;i++){cin>>up[i].x>>up[i].y;down[i].x=up[i].x;down[i].y=up[i].y-1;}double ans=getans();if(ans>up[n-1].x||fabs(ans-up[n-1].x)<eps)cout<<"Through all the pipe.\n";else cout<<fixed<<ans<<'\n';}return 0; }
View Code
转载于:https://www.cnblogs.com/zjutlitao/p/3244038.html
[ACM_几何] Pipe相关推荐
- [ACM_几何] Wall
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/E 题目大意:依次给n个点围成的一个城堡,在周围建围墙,要求围墙 ...
- [ACM_几何] F. 3D Triangles (三维三角行相交)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28235#problem/A 题目大意:给出三维空间两个三角形三个顶点,判断二者是否有公共 ...
- 几何深度学习(Geometric Deep Learning)技术
几何深度学习(Geometric Deep Learning)技术 几何深度学习综述 从论文Geometric Deep Learning: Grids, Groups, Graphs, Geodes ...
- Pipe Utilization管道利用率
Pipe Utilization管道利用率 概述 CUDA设备的每个流式多处理器(SM)都具有许多专门用于执行特定任务的硬件单元.在芯片级,这些单元提供执行管道,翘曲调度程序将指令发送到这些管道.例如 ...
- 虚拟纹理与几何图像技术
虚拟纹理与几何图像技术 一. 基本图形学概念 图1. 几何与纹理. 曲面一般表示成三角网格和纹理图像,三角网格表示曲面的几何拓扑信息,纹理图像给出曲面的颜色材质等信息.将三角网格映射到平面区域的过程被 ...
- Angualr设置自定义管道Pipe(类似Vue的过滤器filters)货币格式化(实现内置管道CurrencyPipe的功能)
新建管道: ng g pipe pipes/money或ng g p pipes/money pipes/money.pipe.ts,同时在父级module.ts加入 im ...
- 使用Blender中的几何节点创建程序对象
大小解压后:2.4G 持续时间3h 30m 1280X720 MP4 语言:英语+中英文字幕(根据原英文字幕机译更准确) 使用Blender中的几何节点按程序创建对象 信息: 使用Blender中的几 ...
- linux进程通信:pipe实现进程同步
文章目录 通过管道同步进程 实现代码 管道缓冲区 设置缓冲区大小 总结 :pipe的特点 通过管道同步进程 管道自带同步互斥机制: 管道的内核实现:fs/pipe.c ,主要通过内核的锁以及等待队列等 ...
- linux进程间通信:无名管道 pipe
文章目录 内核层实现 结构 通信原理 特点 使用 函数声明 使用实例 单向通信 双向通信 编程注意事项 管道中无数据时读操作会阻塞 将管道的写端句柄关闭,不会影响读端数据读取 管道中没有数据,写操作关 ...
最新文章
- python全局变量定义_Python 3 实现定义跨模块的全局变量和使用
- 2020 China Collegiate Programming Contest Qinhuangdao Site 补题部分
- 【渝粤题库】陕西师范大学151210 成本会计作业 (专升本)
- 流行趋势-立体感和艺术剪纸风海报美妆设计
- 网络不稳定的原因_关键词排名波动原因,如何解决网站排名不稳定!
- 求和(1,2,3.....n使其和为m的所有情况)
- jdbc编程遇到文件上传
- 在WebBrowser控件使用js调用C#方法
- ip 纯真数据库查找
- 电视下载我的android应用未安装不了,安卓系统下载了微信为什么安装不上?总是显示未安装程序,这是怎么回事?...
- wps for linux字体缺失,wps for linux 字体库缺失问题的解决办法
- accuracy(准确率), precision(精密度), recall(召回率), specificity(特异性), and F1-score(F1分数):分别是什么意思?
- windows server 2008 R2 怎么集成USB3.0驱动
- 第十五节 使用NETCONN 接口编程
- OpenCV(3.4.1)错误 Assertion failed (chunk.m_size 0xFFFF)
- 将腾讯视频QLV格式转换为MP4格式
- Cesium 视频融合,边缘模糊
- crmeb多商户2.0正式版 新增DIY、PC端客服、同城配送平台等完整包下载更新包下载
- 最新的CC2642R与CC2640、CC2640R2F有什么改进?
- 如何在SM30维护表时自动写入表字段的默认值-事件(EVENT)
热门文章
- 今年最新整理的《高频Java面试题集合》,聪明人已经收藏了!
- 【PAT (Advanced Level) Practice】1005 Spell It Right (20 分)
- 【深度学习】利用一些API进行图像数据增广
- 【响应式Web前端设计】设置图片间隙为0
- python【力扣LeetCode算法题库】1111- 有效括号的嵌套深度
- python【蓝桥杯vip练习题库】ALGO-120 学做菜
- js中new实例化对象内部过程
- 网络广告推广浅析网站的外链究竟要如何优化效果才会更好呢?
- 网站内容优化时需注意哪些事项?
- 计算机辅助园林设计ps,计算机辅助园林设计III