P1452 Beauty Contes

题目背景

此处省略1W字^ ^

题目描述

贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”。因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意。世界将被表示成一个二维平面,每个农场位于一对整数坐标(x,y),各有一个值范围在-10000…10000。没有两个农场共享相同的一对坐标。

尽管贝西沿直线前往下一个农场,但牧场之间的距离可能很大,所以她需要一个手提箱保证在每一段旅程中她有足够吃的食物。她想确定她可能需要旅行的最大可能距离,她要知道她必须带的手提箱的大小。帮助贝西计算农场的最大距离。

输入输出格式

输入格式:

第一行:一个整数n

第2~n+1行:xi yi 表示n个农场中第i个的坐标

输出格式:

一行:最远距离的[b]平方[/b]

输入输出样例

输入样例#1:

4
0 0
0 1
1 1
1 0

输出样例#1:

2

说明

NONE

本来想练习一下旋转卡壳,

但是n^2的暴力居然A了。,,。。

既然A了,。。。

那就不写旋转卡壳23333333

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #define vec point
 7 using namespace std;
 8 const double eps=1e-8;
 9 const int MAXN=50001;
10 int n;
11 void read(int &n)
12 {
13     char c=‘+‘;int x=0;bool flag=0;
14     while(c<‘0‘||c>‘9‘){c=getchar();if(c==‘-‘)flag=1;}
15     while(c>=‘0‘&&c<=‘9‘){x=x*10+(c-48);c=getchar();}
16     flag==1?n=-x:n=x;
17 }
18 inline int dcmp(double x)
19 {
20     if(fabs(x)<eps)    return 0;
21     else return x>0?1:-1;
22 }
23 struct point
24 {
25     double x,y;
26     inline point(double x=0,double y=0):x(x),y(y){};
27 }p[MAXN],ch[MAXN];
28 vec operator - (vec a,vec b) {return vec(a.x-b.x,a.y-b.y);}
29 vec operator + (vec a,vec b) {return vec(a.x+b.x,a.y+b.y);}
30 vec operator == (vec a,vec b){return (dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0);}
31 int comp(const point &a,const point &b)
32 {
33     if(a.x==b.x)    return a.y<b.y;
34     else    return a.x<b.x;
35 }
36 int stack[MAXN];
37 double cross(vec a,vec b){return a.x*b.y-a.y*b.x;}
38 int convex_hull()
39 {
40     sort(p+1,p+n+1,comp);
41     int top=1;
42     for(int i=1;i<=n;i++)
43     {
44         while(top>2&& dcmp(cross(ch[top-1]-ch[top-2], p[i]-ch[top-2]))<=0)    top--;
45         ch[top++]=p[i];
46     }
47     int tmp=top+1;
48     for(int i=n-1;i>=1;i--)
49     {
50         while(top+1>tmp&& dcmp(cross(ch[top-1]-ch[top-2], p[i]-ch[top-2]))<=0)    top--;
51         ch[top++]=p[i];
52     }
53     if(n>2) top--;
54     return top;
55 }
56 int dis(point a,point b)
57 {
58     return    ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
59 }
60 int main()
61 {
62     //freopen("fc.in","r",stdin);
63     //freopen("fc.out","w",stdout);
64     read(n);
65     //ios::sync_with_stdio(0);
66     for(int i=1;i<=n;i++)
67     {
68         double a,b;
69         cin>>a>>b;
70         p[i]=point(a,b);
71     }
72     int num=convex_hull();
73     int ans=0;
74     for(int i=1;i<=num;i++)
75         for(int j=1;j<=num;j++)
76         ans=max(ans,(int) dis(ch[i],ch[j]));
77
78     printf("%d",ans);
79     return 0;
80 }
时间: 2024-11-25 10:56:20

P1452 Beauty Contes的相关文章

P1452 Beauty Contes(旋转卡壳版)

题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面,每个农场位于一对整数坐标(x,y),各有一个值范围在-10000…10000.没有两个农场共享相同的一对坐标. 尽管贝西沿直线前往下一个农场,但牧场之间的距离可能很大,所以她需要一个手提箱保证在每一段旅程中她有足够吃的食物.她想确定她可能需要旅行的最大可能距离,她要知道她必须带的手提箱的大小.帮助贝西计算农

ZOJ 3872 Beauty of Array(数学啊)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5520 Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty

【The beauty of math】无限循环小数转分数

0.333333... = 1/3 推导过程: 设x=0.333333 10x=3.333333(循环体的数字个数为1) 10x-x=3 x=1/3 所以计算的核心在于确定无限循环的循环体的数字个数. [The beauty of math]无限循环小数转分数,布布扣,bubuko.com

Beauty of Array

Description Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A. Input There a

ZOJ 3872 Beauty of Array 连续子序列求和

Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A. Input There are multiple

HDU 5496 Beauty of Sequence

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5496 Beauty of Sequence Problem Description Sequence is beautiful and the beauty of an integer sequence is defined as follows: removes all but the first element from every consecutive group of equivalen

Beauty World OpenCart 主题模板 ABC-0046

Beauty World OpenCart 主题模板 ABC-0046 BEAUTY WORLD OPENCART 主题模板 ABC-0046 模板特性 OpenCart版本 1.5.6, 1.5.6.1, 1.5.6.2, 1.5.6.3, 1.5.6.4, 2.0.1.1 包含文件 PHP Files, CSS Files, JS Files Introduction------------------Beauty World is a very advanced OpenCart them

AndyQsmart ACM学习历程——ZOJ3872 Beauty of Array(递推)

Description Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A. Input There a

12th浙江省省赛 B题 Beauty of Array

Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of