[GYM 100492A] Average Convex Hull 凸包好题
大致题意:
给出一个点集,其中有一个点有相同的几率会被删除,求删除之后的点集够成的凸包上的点的平均数。
首先看到题目,可以考虑枚举删除的点,将其凸包上前后两点以及两点间凸包内所有点构建凸包,因为凸包内每个点
最多被访问一次,所以是O(N)的复杂度。理论上可行,但是实际上实现起来相当困难,又兴趣的可以去尝试。
这题的正解是先将所有的点求个凸包,若凸包顶点为偶数,则只需先删除凸包上的所有奇数点,然后求得一个凸包,然
后再删除凸包上偶数点,在求一次凸包,最后答案为
ans=两个凸包的顶点数+(m-1)*m-构建前两个凸包时经过的凸包的点数+删除的点在凸包内部的情况
奇数点同理,但要多计算一次。
附图 偶数点时
奇数点时
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 #include<set> 7 #include<map> 8 #include<stack> 9 #include<time.h> 10 #include<cstdlib> 11 #include<cmath> 12 #include<list> 13 using namespace std; 14 #define MAXN 200100 15 #define eps 1e-5 16 #define For(i,a,b) for(int i=a;i<=b;i++) 17 #define Fore(i,a,b) for(int i=a;i>=b;i--) 18 #define lson l,mid,rt<<1 19 #define rson mid+1,r,rt<<1|1 20 #define mkp make_pair 21 #define pb push_back 22 #define cr clear() 23 #define sz size() 24 #define met(a,b) memset(a,b,sizeof(a)) 25 #define iossy ios::sync_with_stdio(false) 26 #define fre freopen 27 #define pi acos(-1.0) 28 #define inf 1e9+9 29 #define Vector Point 30 const int Mod=1e9+7; 31 typedef unsigned long long ull; 32 typedef long long ll; 33 typedef pair<int,int> pii; 34 typedef pair<ll,ll> pll; 35 int dcmp(double x){ 36 if(fabs(x)<=eps) return 0; 37 return x<0?-1:1; 38 } 39 struct Point { 40 double x,y; 41 int id; 42 int pre,nxt; 43 Point(double x=0,double y=0) : x(x),y(y) {} 44 Point operator - (const Point &a)const{ return Point(x-a.x,y-a.y); } 45 Point operator + (const Point &a)const{ return Point(x+a.x,y+a.y); } 46 Point operator * (const double &a)const{ return Point(x*a,y*a); } 47 Point operator / (const double &a)const{ return Point(x/a,y/a); } 48 bool operator < (const Point &a)const{ if(x==a.x) return y<a.y;return x<a.x; } 49 bool operator == (const Point &a)const{ return dcmp(x-a.x)==0 && dcmp(y-a.y)==0; } 50 void read(int iid=0) { scanf("%lf%lf",&x,&y);id=iid; } 51 void out(){cout<<"Bug: "<<x<<" "<<y<<endl;} 52 }; 53 inline double Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; } 54 inline double Dot(Vector a,Vector b) { return a.x*b.x+a.y*b.y; } 55 inline double dis(Vector a) { return sqrt(Dot(a,a)); } 56 int ConvexHull(Point *p,int n,Point *ch){ 57 int m=0; 58 sort(p,p+n); 59 For(i,0,n-1){ 60 p[i].id=i; 61 while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; 62 ch[m++]=p[i]; 63 } 64 int k=m; 65 Fore(i,n-2,0){ 66 while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; 67 ch[m++]=p[i]; 68 } 69 if(n>1) m--; 70 return m; 71 } 72 inline bool Onsegment(Point a,Point b1,Point b2){ 73 return dcmp(Cross(b1-a,b2-a))==0 && dcmp(Dot(b1-a,b2-a))<0; 74 } 75 bool Intersect_Segm_Segm(Point a1,Point a2,Point b1,Point b2){ 76 if(a1==b1 || a1==b2 || a2==b1 || a2==b2) return 1; 77 if(Onsegment(a1,b1,b2) || Onsegment(a2,b1,b2)) return 1; 78 double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1); 79 double c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1); 80 return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0; 81 } 82 Point Intersect_Line_Point(Point p,Vector u,Point q,Vector v){ 83 Vector w=p-q; 84 double t=Cross(v,w)/Cross(u,v); 85 return p+u*t; 86 } 87 int vis[MAXN],vvis[MAXN]; 88 int tcnt; 89 int tConvexHull(Point *p,int n,Point *ch){ 90 int m=0; 91 sort(p,p+n); 92 For(i,0,n-1){ 93 if(vis[p[i].id]) continue; 94 while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; 95 ch[m++]=p[i]; 96 } 97 int k=m; 98 Fore(i,n-2,0){ 99 if(vis[p[i].id]) continue; 100 while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; 101 ch[m++]=p[i]; 102 } 103 if(ch[0]==ch[m-1]) m--; 104 For(i,0,m-1){ 105 if(vvis[ch[i].id]) tcnt++; 106 } 107 return m; 108 } 109 ll n; 110 Point ch[MAXN],p[MAXN],stk[MAXN]; 111 int solve(){ 112 scanf("%lld",&n); 113 tcnt=0; 114 met(vis,0); 115 met(vvis,0); 116 For(i,0,n-1) p[i].read(i); 117 int m=ConvexHull(p,n,ch); 118 For(i,0,m-1) vvis[ch[i].id]=1; 119 if(n==1) return puts("0/1"); 120 ll ans=m*1LL*(n-m); 121 if(m%2==0){ 122 For(i,0,m-1){ 123 vis[ch[i].id]=1; 124 i++; 125 } 126 ans+=tConvexHull(p,n,stk); 127 met(vis,0); 128 For(i,1,m-1){ 129 vis[ch[i].id]=1; 130 i++; 131 } 132 ans+=tConvexHull(p,n,stk); 133 }else{ 134 For(i,2,m-1){ 135 vis[ch[i].id]=1; 136 i++; 137 } 138 ans+=tConvexHull(p,n,stk); 139 met(vis,0); 140 For(i,1,m-1){ 141 vis[ch[i].id]=1; 142 i++; 143 } 144 ans+=tConvexHull(p,n,stk); 145 met(vis,0); 146 vis[ch[0].id]=1; 147 ans+=tConvexHull(p,n,stk); 148 } 149 ans+=m*1LL*(m-1)-tcnt; 150 ll cnt=__gcd(ans,n); 151 ans/=cnt; 152 n/=cnt; 153 printf("%lld/%lld\n",ans,n); 154 } 155 int main(){ 156 // fre("in.txt","r",stdin); 157 fre("average.in","r",stdin); 158 fre("average.out","w",stdout); 159 int t=1; 160 solve(); 161 return 0; 162 }
View Code
转载于:https://www.cnblogs.com/cjbiantai/p/9369367.html
[GYM 100492A] Average Convex Hull 凸包好题相关推荐
- P6810 「MCOI-02」Convex Hull 凸包
P6810 「MCOI-02」Convex Hull 凸包 思路 ∑i=1n∑j=1mτ(i)τ(j)τ(gcd(i,j))∑d=1nτ(d)∑i=1nd∑j=1mdτ(id)τ(id)[gcd(i, ...
- JavaScript:实现Convex hull凸包问题算法(附完整源码)
JavaScript:实现Convex hull凸包问题算法 function compare (a, b) {// Compare Function to Sort the points, a an ...
- 清华计算几何大作业(一):CG2017 PA1-1 Convex Hull (凸包)
CG2017 PA1-1 Convex Hull (凸包) 1. 前置知识 2. 思路分析 3. 伪代码 4. 可视化结果示例 5. 项目代码(待更新完整) 1.1.1 Numerical Tests ...
- OpenCV 凸包Convex Hull
OpenCV 凸包Convex Hull 凸包Convex Hull 目标 代码 结果 凸包Convex Hull 目标 在本教程中,您将学习如何: 使用OpenCV函数cv :: convexHul ...
- R语言为散点图添加凸包(convex hull):数据预处理(创建一个包含每组数据凸包边界的数据集)、ggplot2使用geom_polygon函数为可视化图像添加凸包(convex hull)
R语言为散点图添加凸包(convex hull):数据预处理(创建一个包含每组数据凸包边界的数据集).ggplot2使用geom_polygon函数为可视化图像添加凸包(convex hull) 目录
- 寻找凸包 (Convex Hull)
凸包问题是算法中经典的题目了,最近算法课讲分治问题时提到了Convex Hull,算法导论的书上也花了篇幅讨论了Convex Hull的求解,主要是Graham方法. 为了能更好地理解分治和Graha ...
- MATLAB凸包Convex hull运算
凸包Convex hull运算(求离散点的边界) [k,a] = convhull(x,y); K = convulln(X, options); [K AV] = convexHull(DT); t ...
- Monotone Chain Convex Hull(单调链凸包)
1 Monotone Chain Convex Hull(单调链凸包)算法伪代码: 2 //输入:一个在平面上的点集P 3 //点集 P 按 先x后y 的递增排序 4 //m 表示共a[i=0...m ...
- matlab 凸包质心算法,求多边形凸包(线性算法)--陈氏凸包算法--Computing the convex hull of a simple polygon(源码)...
陈氏凸包算法-算法参考:Computing the convex hull of a simple polygon 作者:Chern-Lin Chen 陈氏算法提供了一个线性效率求凸包的算法,本文使用 ...
最新文章
- 解题报告:CF1307D Cow and Fields(最短路、最优解不等式化简)
- 洛谷P1006 传纸条 (棋盘dp)
- fwrite,fread and fprintf,fscanf的一些使用体会
- x86异常处理与中断机制(1)概述中断的来源和处理方式
- mysql列连接_连接来自MySQL中不同表的列
- BZOJ5336 TJOI2018 party 【状压DP】*
- 网页百度云盘服务器有点忙,百度网盘使用提示网络异常,建议使用三种解决方法...
- bim 水利枢纽 运维_BIM——运维专篇
- Redis 内存碎片
- [异能程序员]第二章 上头条(第二更)
- 小红书七夕营销攻略,玩出新花样(内附小红书推广方案干货)
- 录屏怎么录?你知道多少录屏软件?
- android sdk 固态硬盘,使用TVM在android中进行Mobilenet SSD部署
- C语言:递归实现N的阶乘
- hadoop暂时永久关闭安全模式
- 中文括号和英文括号转换
- 走出软件作坊:三五个人十来条枪 如何成为开发正规军 链接[收藏]
- android 银联插件,Android版添加phonegap-银联支付插件教程
- 利用OpenCV计算图像二维熵
- 三维pcd地图转二维栅格地图
热门文章
- C++ leetCode 1. 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个
- stm32命名规则,型号说明
- blkdiag--生成以输入元素为对角线元素的矩阵
- php orm url,PHP ORM使用之
- pytorch基础操作学习笔记(autograd,Tensor)
- 1.2.3 使用向量化进行加速计算
- Dimple.js基础
- 计算机考试一年有肌肉,阅卷老师最想看到什么样的字体?电脑阅卷时代,这种字体很吃香...
- spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获
- C++ STL究竟有多慢?