POJ 2187 Beauty Contest G++
来源:互联网 发布:数据新闻手册百度云 编辑:程序博客网 时间:2024/05/16 17:31
//#include <iostream>#include <vector> #include <algorithm>#include <cstdio>//挑战程序设计竞赛 例题 没理解 using namespace std;struct P{double x,y;P(){}P(double x,double y):x(x),y(y){}P operator+ (P p){return P(x+p.x,y+p.y);}P operator- (P p){return P(x-p.x,y-p.y);}P operator* (double d){return P(x*d,y*d);}double dot(P p){return x*p.x+y*p.y;}double det(P p){return x*p.y-y*p.x;}};//字典序比较 bool cmp_x(const P&p,const P& q){if(p.x!=q.x){return p.x<q.x;}return p.y<q.y;}//距离的平方double dist(P p,P q){return (p-q).dot(p-q);} //求凸包vector<P> convex_hull(P*ps,int n){sort(ps,ps+n,cmp_x);int k=0;//凸包的顶点数vector<P> qs(n*2);//构造中的凸包//构造凸包的下侧for(int i=0;i<n;i++){while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;qs[k++]=ps[i];}//构造凸包的上侧 for(int i=n-2,t=k;i>=0;i--){while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0){k--;}qs[k++]=ps[i];}qs.resize(k-1);return qs;} int main(){int N;//cin>>N;scanf("%d",&N);P ps[N];for(int i=0;i<N;i++){//cin>>ps[i].x>>ps[i].y;double x,y;scanf("%lf%lf",&x,&y);ps[i].x=x;ps[i].y=y;}vector<P> qs=convex_hull(ps,N);double res=0;for(int i=0;i<qs.size();i++){for(int j=0;j<i;j++){res=max(res,dist(qs[i],qs[j]));}}printf("%d\n",(int)res);//cout<<(int)res;return 0;}
N个牧场,已知每个牧场的坐标。求两个牧场最远距离的平方。
阅读全文
0 0
- POJ 2187 Beauty Contest G++
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- poj 2187 Beauty Contest
- Poj 2187 Beauty Contest
- poj 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187 Beauty Contest
- POJ 2187--Beauty Contest
- poj 2187 Beauty Contest
- 数据库的增删改查(mysql)
- js特点以及和Java的区别
- 弹性动画
- Web安全之token
- 实验二 线性表综合实验(静态链表)
- POJ 2187 Beauty Contest G++
- 嵌入式相关
- 【转】微信公众号支付开发全过程 --JAVA
- JAVA提高篇(21)--FileReader和FileWriter
- 6.4OpenCV形态学图像处理:开运算、闭运算、形态学梯度、顶帽、黑帽
- ORA-01033:ORACLE initialization or shutdown 错误解决方法
- Automatic Brain Tumor Detection and Segmentation Using U-Net Based Fully Convolutional Networks_2017
- 欧拉函数有关式ϕ(n)/(n-1)值递减序列性质
- UVa10635 Prince ans Princess(LCS)