POJ 2187.Beauty Contest
来源:互联网 发布:xfun吃货俱乐部淘宝 编辑:程序博客网 时间:2024/06/07 21:43
题目:http://poj.org/problem?id=2187
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0x7fffffff#define LFINF 1e10#define eps 1e-7#define MAXN 100105#define PI 3.14159265358979323846using namespace std;struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y) {}};typedef Point Vector;Vector operator - (Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); }int dcmp(double x){ if(fabs(x)<eps) return 0; else return x<0?-1:1; }int n;Point node[50005];Point convex[50005];int top;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; } double Length(Vector A) { return sqrt(Dot(A,A)); } bool cmp(Point a, Point b){ return dcmp(a.y-b.y)==-1 || (dcmp(a.y-b.y)==0 && dcmp(a.x-b.x)==-1);}void grahamScan(){sort(node,node+n,cmp); int tmp; top = 1; convex[0]=node[0], convex[1]=node[1]; for(int i=2; i<n; i++){ while(top>0 && dcmp(Cross(convex[top]-convex[top-1], node[i]-convex[top-1])) <= 0)top--; convex[++top] = node[i]; } tmp = top; for(int i=n-2; i>=0; i--){ while(top>tmp && dcmp(Cross(convex[top]-convex[top-1], node[i]-convex[top-1])) <= 0)top--; convex[++top] = node[i]; }}double rotating_calipers(){ int q = 1; double ans = 0; convex[top] = convex[0]; for(int p = 0; p < top; p++) { while(dcmp(Cross(convex[p+1]-convex[p],convex[q+1]-convex[p])-Cross(convex[p+1]-convex[p],convex[q]-convex[p]))==1) q=(q+1)%top; ans=max(ans,max(Length(convex[p]-convex[q]),Length(convex[p+1]-convex[q+1]))); } return ans; }int main(){cin>>n;for(int i = 0; i < n; i++)cin>>node[i].x>>node[i].y;grahamScan();double ans = rotating_calipers();ans *= ans;printf("%.0lf",ans);}总结: 凸包. 先计算凸包, 然后用旋转卡壳法计算凸包直径.
阅读全文
0 0
- 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
- poj 2187 Beauty Contest
- 脚踏实地云 mysql-proxy做客户端连接转发【外网访问内网mysql】
- weblogic12c 安装
- EAGLE电路板编辑器制做电路板的流程
- [Android Studio] 解决Module里面调用aar出现Failed to resolve的问题
- Echarts
- POJ 2187.Beauty Contest
- 归并排序实现求逆序数
- 数据超出本行 换到下一行展示的方法
- mysql怎样配置ODBC数据源
- 如何在 Hadoop 2.2.0 环境下使用 Spark 2.2.x
- 软件调试笔记70
- jq设置checkbox默认选中状态
- [Leetcode] Binary Index Tree
- TortoiseGIT(GUI工具)安装教程