POJ 3348 Cows
来源:互联网 发布:pthread linux 编辑:程序博客网 时间:2024/05/16 04:41
题目大意:
给你n棵树,可以用这n棵树围一个圈,然后在圈里面可以养牛,每个牛需要50平方米的空间,问最多可以养多少牛?
其实就是求一个凸包,计算凸包面积,然后除以50,然后就得到答案,直接上模板了。
凸包这一类型的题目差不多,可以作为模板使用,时间复杂度是NlogN。
//Time 32ms; Memory 568K
#include<iostream>#include<algorithm>using namespace std;int n;typedef struct point {double x,y;point(double xx=0,double yy=0):x(xx),y(yy){}}vector;point p[10010],ch[10010];bool operator < (point a,point b){return a.x<b.x || (a.x==b.x && a.y<b.y);}vector operator - (point a,point 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;}int graph(){int k,m=0,i;for(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];}k=m;for(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;}int main(){int i,m,d;double s=0;cin>>n;for(i=0;i<n;i++) cin>>p[i].x>>p[i].y;sort(p,p+n);m=graph();for(i=1;i<m-1;i++) s+=0.5*cross(ch[i]-ch[0],ch[i+1]-ch[0]);d=s/50;cout<<d<<endl;return 0;}
- poj 3348 Cows
- POJ 3348 Cows
- poj 3348 Cows
- poj 3348 Cows
- POJ 3348 Cows
- poj 3348 Cows
- POJ 3348 Cows
- POJ 3348 Cows
- POJ 3348 Cows
- poj 3348 Cows
- POJ 3348 Cows
- POJ-3348:Cows
- poj 3348 Cows(求凸包面积)
- POJ 3348 Cows(凸包)
- POJ 3348 Cows(凸包求面积)
- POJ 3348 Cows 求凸包面积
- POJ 3348 || Cows(求凸包面积
- POJ 3348 Cows (凸包)
- 创业公司,人才的找和留
- POJ 2299 Ultra-QuickSort(树状数组入门) 求逆序数
- ajax对注册名进行验证是否数据库中存在
- 由两个实例看元数据管理
- 我所经历的ERP项目的失败
- POJ 3348 Cows
- 打造绿色互联网必须遵循“技术为王”的原则
- 第三章数程序设计初步--循环结构项目3拓展英尺到米的转换表
- POJ 1654 Area
- 20大IT科技公司的老巢啥样?你见过没!
- 飘逸的python - zlib压缩存到数据库
- 竞赛快速及常用(后续更新)
- 周哲_java软件工程师 简历
- Linux常用命令