【POJ】【2187】Beauty Contest
计算几何/旋转卡壳
学习旋转卡壳请戳这里~感觉讲的最好的就是这个了……
其实就是找面积最大的三角形?。。。并且满足单调……
嗯反正就是这样……
这是一道模板题
好像必须写成循环访问?我在原数组后面复制了一遍点,结果挂了……改成cur=cur%n+1就过了QAQ
//其实是不是数组没开够所以复制的方法就爆了?
UPD:(2015年5月13日 20:40:45)
其实是我点保存在1~n里面,所以复制的时候不能写p[i+n-1]=p[i]; 而应该是p[i+n]=p[i];……QAQ我是傻逼
Source Code
Problem: User: sdfzyhy
Memory: 1044K Time: 32MS
Language: G++ Result: Accepted Source Code //POJ 2187
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
typedef long long LL;
inline int getint(){
int r=,v=; char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-;
for(; isdigit(ch);ch=getchar()) v=v*-''+ch;
return r*v;
}
const int N=;
/*******************template********************/
struct Poi{
int x,y;
Poi(){}
Poi(int x,int y):x(x),y(y){}
void read(){x=getint();y=getint();}
}p[N],ch[N];
typedef Poi Vec;
Vec operator - (const Poi &a,const Poi &b){return Vec(a.x-b.x,a.y-b.y);}
bool operator < (const Poi &a,const Poi &b){return a.x<b.x || (a.x==b.x && a.y<b.y);}
inline int Cross(const Poi &a,const Poi &b){return a.x*b.y-a.y*b.x;}
inline int Dot(const Poi &a,const Poi &b){return a.x*b.x+a.y*b.y;}
int n,m,ans; void graham(Poi *p,int n){
int size=;
sort(p+,p+n+);
ch[++m]=p[];
F(i,,n){
while(m> && Cross(ch[m]-ch[m-],p[i]-ch[m-])<=) m--;
ch[++m]=p[i];
}
int k=m;
D(i,n-,){
while(m>k && Cross(ch[m]-ch[m-],p[i]-ch[m-])<=) m--;
ch[++m]=p[i];
}
if (n>) m--;
} void rot(Poi *p,int n){
ans=;
// F(i,1,n-1) p[n+i-1]=p[i];
// n=n*2-1;
int cur=;
F(i,,n){
Vec v = p[i]-p[i+];
while(Cross(p[i+]-p[i],p[cur+]-p[i]) > Cross(p[i+]-p[i],p[cur]-p[i]))
cur=(cur%n)+;
ans=max(ans,Dot(p[cur]-p[i],p[cur]-p[i]));
ans=max(ans,Dot(p[cur+]-p[i+],p[cur+]-p[i+]));
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("2187.in","r",stdin);
// freopen("2187.out","w",stdout);
#endif
n=getint();
F(i,,n) p[i].read();
graham(p,n);
rot(ch,m);
printf("%d\n",ans);
return ;
}
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 29879 | Accepted: 9260 |
Description
Even though Bessie travels directly in a straight line between pairs
of farms, the distance between some farms can be quite large, so she
wants to bring a suitcase full of hay with her so she has enough food to
eat on each leg of her journey. Since Bessie refills her suitcase at
every farm she visits, she wants to determine the maximum possible
distance she might need to travel so she knows the size of suitcase she
must bring.Help Bessie by computing the maximum distance among all pairs
of farms.
Input
* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm
Output
Sample Input
4
0 0
0 1
1 1
1 0
Sample Output
2
Hint
Source
[Submit] [Go Back] [Status] [Discuss]
【POJ】【2187】Beauty Contest的更多相关文章
- POJ 2187: Beauty Contest(旋转卡)
id=2187">Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27218 ...
- POJ - 2187:Beauty Contest (最简单的旋转卡壳,求最远距离)
Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ti ...
- POJ 2187:Beauty Contest 求给定一些点集里最远的两个点距离
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 31414 Accepted: 9749 D ...
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- 【POJ 1459 power network】
不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...
- 【POJ 2728 Desert King】
Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...
- 【POJ 2976 Dropping tests】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...
- 【POJ 3080 Blue Jeans】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...
- 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)
1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
随机推荐
- 【AtCoder】ARC096(C - F)
听说日本题思维都很棒,去涨涨智商qwq C - Half and Half 题解 枚举买多少个AB披萨也行 但是关于买x个AB披萨最后的总花费是个单峰函数,可以三分 这题有点像六省联考2017D1T1 ...
- PHP的单引号和双引号
单引号内部的变量不会执行,双引号会执行. <?php $name = 'hello php'; echo "<h1>$name</h1>"; echo ...
- 牛客练习赛1 C - 圈圈
链接:https://www.nowcoder.com/acm/contest/2/C来源:牛客网 题目描述 shy有一个队列a[1], a[2],…,a[n].现在我们不停地把头上的元素放到尾巴上. ...
- 三种显著性检测算法(SR,HFT,GBMR)
一.谱残差(Spectral Residual, SR) 一种简单的图像显著性计算模型 http://www.cnblogs.com/CCBB/archive/2011/05/19/2051442. ...
- 《Multi-Agent Actor-Critic for Mixed Cooperative-Competitive Environments》论文解读
MADDPG原文链接 OpenAI bog DDPG链接 目录 一.摘要 二.效果展示 三.方法细节 问题分析 具体方法 伪代码 网络结构 四.实验结果 五.总结 附录 Proposition 1 一 ...
- modernizr.js的介绍和使用
原文链接:https://www.cnblogs.com/-simon/p/5907053.html Modernizr帮助我们检测浏览器是否实现了某个feature,如果实现了那么开发人员就可以充分 ...
- python list的应用
先看下面的操作 In [2]: lis = [(1,2),(3,4),(5,6)] In [3]: for a,b in lis: ...: if a == 1: ...: print (" ...
- Redis在Window服务下的安装
Redis 安装 1.首先在Windows下下载安装Redis 下载地址:https://github.com/MicrosoftArchive/redis/releases 根据你电脑系统的实际情况 ...
- Splay和LCT的复杂度分析
\(Splay\)的复杂度分析 不论插入,删除还是访问,我们可以发现它们的复杂度都和\(splay\)操作的复杂度同阶,只是一点常数的区别 我们不妨假设有\(n\)个点的\(splay\),进行了\( ...
- [Luogu5106]dkw的lcm
https://minamoto.blog.luogu.org/solution-p5106 容易想到枚举质因子及其次数计算其贡献,容斥计算$\varphi(p^i)$的次方数. #include&l ...