【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)不能再经过(被封 ...
随机推荐
- 三种显著性检测算法(SR,HFT,GBMR)
一.谱残差(Spectral Residual, SR) 一种简单的图像显著性计算模型 http://www.cnblogs.com/CCBB/archive/2011/05/19/2051442. ...
- ASP.NET MVC , ASP.NET Web API 的路由系统与 ASP.NET 的路由系统是怎么衔接的?
ASP.NET MVC 的路由实际上是建立在 ASP.NET 的路由系统之上的. MVC 路由注册通常是这样的: RouteTable 是一个全局路由表, 它的 Routes 静态属性是一个 Ro ...
- JIT即时编译器
一.什么是JIT? 即时编译器,负责将IL转换成本机CPU指令 二.JIT编译原理 ①在Main方法执行之前,CLR会检测出Main的代码引用的所有类型.会导致CLR分配一个内部结构.在这个结构中,C ...
- CORS跨域请求[简单请求与复杂请求]
CORS即Cross Origin Resource Sharing(跨来源资源共享),通俗说就是我们所熟知的跨域请求.众所周知,在以前,跨域可以采用代理.JSONP等方式,而在Modern浏览器面前 ...
- springboot中使用JOIN实现关联表查询
* 首先要确保你的表和想要关联的表有外键连接 repository中添加接口JpaSpecificationExecutor<?>,就可以使用springboot jpa 提供的API了. ...
- WinlogonHack获取系统密码
实验环境: win03 sp1 Gina.dll与Msgina.dll Gina.dll在NT/2000中交互式的登陆支持是由WinLogon调用Gina.dll实现的,Gina.dll提供了一个交互 ...
- hdu 1698 线段树 成段更新
题意:一段钩子,每个钩子的值为1,有若干更新,每次跟新某段的值,若干查询某段的和 基础题了 #include<cstdio> #include<iostream> #inclu ...
- sgu 261
学习了元根的一些知识,哈哈. 总结一下: 几个概念: 阶:对于模数m和整数a,并且gcd(m,a)==1,那么定义a在模m下的阶r为满足ar=1 mod m的最小正整数. 性质1:r in [1,ph ...
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- This seems to be a pre-built javascript file. webpack报这个警告怎么办?
增加 module.noParse 进行解决 例如: { resolve: { alias: { 'react': 'my/react/path' } }, module: { noParse: [/ ...