2017-04-04 在校训练T3 选美比赛 contest
2017-04-05 15:53
162 查看
选美比赛 contest
Description
约翰农夫的母牛贝西,刚刚在牛选美比赛赢得第一名,赢得了“世界牛小姐”称号。为了传播善意,贝西将参观世界各地的农场N(2 < = N < = 50000)。为简单起见,世界将被表示成一个二维平面,其中每个农场位于一对整数坐标(x,y),其值在-2000000~2000000范围内。没有两个农场共享相同的坐标。
尽管贝西旅行中走农场之间的直线,但一些农场之间的距离可能很大,所以她想带着一个手提箱,足够她装食物,即使最远的距离。她想确定旅行中最大可能的距离,这样她才能决定箱子的大小。帮助贝西计算所有成对的农场间最大距离。(最远点对)
Input
第一行一个整数N
以下N行,每行两个整数,表示一个农场的坐标。
Output
一行,一个整数表示最远一对农场距离的平方。
Sample Input
4
0 0
0 1
1 1
1 0
Sample Output
2
本题是先叉乘,然后旋(xuán)转(zhuǎn)卡(qiǎ)壳(ké)。
没了。
Description
约翰农夫的母牛贝西,刚刚在牛选美比赛赢得第一名,赢得了“世界牛小姐”称号。为了传播善意,贝西将参观世界各地的农场N(2 < = N < = 50000)。为简单起见,世界将被表示成一个二维平面,其中每个农场位于一对整数坐标(x,y),其值在-2000000~2000000范围内。没有两个农场共享相同的坐标。
尽管贝西旅行中走农场之间的直线,但一些农场之间的距离可能很大,所以她想带着一个手提箱,足够她装食物,即使最远的距离。她想确定旅行中最大可能的距离,这样她才能决定箱子的大小。帮助贝西计算所有成对的农场间最大距离。(最远点对)
Input
第一行一个整数N
以下N行,每行两个整数,表示一个农场的坐标。
Output
一行,一个整数表示最远一对农场距离的平方。
Sample Input
4
0 0
0 1
1 1
1 0
Sample Output
2
本题是先叉乘,然后旋(xuán)转(zhuǎn)卡(qiǎ)壳(ké)。
没了。
#include <cstdio> #include <iostream> #include <cstdlib> #include <algorithm> #include <cmath> #include <cstring> using namespace std ; const int maxn=50010; int n,top; long long ans; typedef struct NODE{ long long x,y; NODE (){} NODE (long long a,long long b){ x=a,y=b; } }N; N p[maxn],stack[maxn]; N operator -(N a,N b){ return N (a.x-b.x,a.y-b.y); } long long operator * (N a,N b){ return a.x*b.y-a.y*b.x; } long long sqr (long long x) {return x*x;} long long dist (N x,N y){ return sqr (x.x-y.x)+sqr(x.y-y.y); } bool operator <(N a,N b){ long long cnt=((a-p[1])*(b-p[1])); return cnt>0 || (cnt==0&&dist(p[1],a)<dist (p[1],b)); } void init (){ scanf ("%d",&n); int i,k=1; for (i=1;i<=n;i++){ scanf ("%lld %lld",&p[i].x,&p[i].y); if (p[i].x < p[k].x || (p[i].x==p[k].x&&p[i].y<p[k].y)) k=i; } swap (p[1],p[k]); sort (p+2,p+n+1); } void graham(){//构建凸包 stack[++top]=p[1]; stack[++top]=p[2]; int i; for(i=3;i<=n;i++){ while(top>1&&(stack[top]-stack[top-1])*(p[i]-stack[top-1])<=0) top--; stack[++top]=p[i]; } } void xzkk(){ stack[top+1]=stack[1]; int now=2,i; for(i=1;i<=top;i++){ while((stack[i+1]-stack[i])*(stack[now]-stack[i])<(stack[i+1]-stack[i])*(stack[now+1]-stack[i])){ now++; if(now==top+1) now=1; } ans=max(ans,dist(stack[now],stack[i])); } } int main (){ init (); graham (); xzkk (); cout <<ans; return 0; }
相关文章推荐
- 网路通信中的选美比赛,看看国外的电话费为什么那么便宜"Beauty Contest"
- 2017-04-04 水题信心 03选美比赛
- 2015-2016 ACM-ICPC Southwestern Europe Regional Contest (SWERC 15)训练总结【7/10】
- 2016 Multi-University Training Contest 1 T3
- 2016 Multi-University Training Contest 2(2016多校训练第二场)1009
- 「2017 Multi-University Training Contest 7」2017多校训练7
- 2015-2016 Northwestern European Regional Contest 训练总结 【5+2】【待补】
- [HDU5727] Necklace [2016 Multi-University Training Contest 1(2016多校联合训练1) E]
- [HDU5764] After a Sleepless Night [2016 Multi-University Training Contest 4(2016多校联合训练4) B]
- HDOJ 5775 (2016多校联合训练 Training Contest 4) Bubble Sort
- 小总结——以The 9th Zhejiang Provincial Collegiate Programming Contest做训练赛后
- 2017多校训练Contest3: 1004 Kanade's sum hdu6059
- HDOJ 5738 (2016多校联合训练 Training Contest 2) Eureka
- LA4329 乒乓比赛(树状数组)(训练指南)
- 2018.1.28 训练日记--图论做题+牛客比赛
- 2017多校训练Contest3: 1005 RXD and dividing hdu6060
- 2016专题训练II-黄华 比赛排名
- 洛谷“测试”(这是一场比赛)T3 隔离(最小割)
- ACM训练日记—3月25日(13届景驰—埃森哲杯比赛(牛客)题目整理)
- 2018.1.21 训练日记--解比赛题