【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)不能再经过(被封 ...
随机推荐
- linux保证程序单实例运行
static int proc_detect(const char *procname){ char filename[100] = {0}; sprintf(filename, "%s/% ...
- HTML5 Canvas游戏开发(三)lufylegend开源库件(上)
lufylegend可以解决HTML5开发游戏中会遇到的一些问题: 1.各种浏览器对于JavaScript和HTML的解析是不一致的. 2.手机浏览器和PC浏览器的区别. 3.JavaScript并非 ...
- 纯CSS仿制Google女生节Doodle
看到google今天的女生节Doodle,自己用纯css仿制一个,送给老妈.老婆.女儿. 大家可以点这里在线观看效果,点这里下载收藏效果. 实现原理 1.利用checkbox侦听处理单击事件. 2.单 ...
- CODEVS 4655 序列终结者-splay(区间更新、区间翻转、区间最值)
4655 序列终结者 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 题目描述 Description 网上有许多题,就是给定一个序列,要 ...
- 回顾2014 Java发生的5件大事
回顾2014 Java发生的5件大事 1.2月1日:RedMonk分析师确认并宣布Java是最受欢迎和多样化的语言! 2014年,Java生态圈伴随着引擎的轰鸣起步,随着FOSDEM年会的Free J ...
- golang make()的第三个参数
golang分配内存有一个make函数,该函数第一个参数是类型,第二个参数是分配的空间,第三个参数是预留分配空间,前两个参数都很好理解, 对于第三个参数,例如a:=make([]int, 5, 10) ...
- 《jQuery基础教程》读书笔记
最近在看<jQuery基础教程>这本书,做了点读书笔记以备回顾,不定期更新. 第一章第二章比较基础,就此略过了... 第三章 事件 jQuery中$(document).ready()与j ...
- PHP中var_export和var_dump的区别
var_dump -- 此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值. var_export -- 输出或返回一个变量的字符串表示, 它和 var_dump() 类似,不同的是其返回 ...
- CF280C Game on Tree 期望
期望多少次操作,我们可以看做是染黑了多少节点 那么,我们可以用期望的线性性质,求出每个节点被染黑的概率之和(权值为$1$) 一个节点$u$被染黑仅跟祖先有关 我们把$u$到祖先的链抽出来 只要选取链上 ...
- BZOJ 1975: [Sdoi2010]魔法猪学院 大水题 第k短路 spfa
https://www.lydsy.com/JudgeOnline/problem.php?id=1975 我好像到现在了第k短路都不会写,mdzz. 先spfa求出最短路,然后扫点存各种前置路径已经 ...