计算几何/旋转卡壳


  学习旋转卡壳请戳这里~感觉讲的最好的就是这个了……

  其实就是找面积最大的三角形?。。。并且满足单调……

  嗯反正就是这样……

  这是一道模板题

  好像必须写成循环访问?我在原数组后面复制了一遍点,结果挂了……改成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 ;
}
Beauty Contest
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 29879   Accepted: 9260

Description

Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world in order to spread goodwill between farmers and their cows. For simplicity, the world will be represented as a two-dimensional plane, where each farm is located at a pair of integer coordinates (x,y), each having a value in the range -10,000 ... 10,000. No two farms share the same pair of coordinates.

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

* Line 1: A single integer, N

* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm

Output

* Line 1: A single integer that is the squared distance between the pair of farms that are farthest apart from each other.

Sample Input

4
0 0
0 1
1 1
1 0

Sample Output

2

Hint

Farm 1 (0, 0) and farm 3 (1, 1) have the longest distance (square root of 2)

Source

[Submit]   [Go Back]   [Status]   [Discuss]

【POJ】【2187】Beauty Contest的更多相关文章

  1. POJ 2187: Beauty Contest(旋转卡)

    id=2187">Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27218   ...

  2. POJ - 2187:Beauty Contest (最简单的旋转卡壳,求最远距离)

    Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ti ...

  3. POJ 2187:Beauty Contest 求给定一些点集里最远的两个点距离

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 31414   Accepted: 9749 D ...

  4. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  5. 【POJ 1459 power network】

    不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...

  6. 【POJ 2728 Desert King】

    Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...

  7. 【POJ 2976 Dropping tests】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...

  8. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  9. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  10. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

随机推荐

  1. 001 Anaconda的介绍与安装

    1.官网 www.continuum.io 2.ananconda的版本 同一个版本下对应一个python3与python2,在这里下载使用python 2.7的版本. 3.概述 Anaconda是一 ...

  2. Ionic Js十三:平台

    $ionicPlatform $ionicPlatform 用来检测当前的平台,以及诸如在PhoneGap/Cordova中覆盖Android后退按钮.  

  3. Ionic入门六:按钮

    1.基本使用 按钮是移动app不可或缺的一部分,不同风格的app,需要的不同按钮的样式. 默认情况下,按钮显示样式为:display: inline-block. <button class=& ...

  4. CSU - 2061 Z‘s Coffee

    Description Z is crazy about coffee. One day he bought three cups of coffee. The first cup has a cap ...

  5. 洛谷——P2083 找人

    P2083 找人 题目背景 无 题目描述 小明要到他的同学家玩,可他只知道他住在某一单元,却不知住在哪个房间.那个单元有N层(1,2……N),每层有M(1,2……M)个房间. 小明会从第一层的某个房间 ...

  6. 1017 Queueing at Bank (25)(25 point(s))

    problem Suppose a bank has K windows open for service. There is a yellow line in front of the window ...

  7. android setContentView

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha setContentView  这个 就是 设置内容视图. 装饰视图 DecorView ...

  8. Java 中的浮点数取精度方法

    Java 中的浮点数取精度方法 一.内容 一般在Java代码中取一个double类型的浮点数的精度,四舍五入或者直接舍去等的方式,使用了4种方法,推荐使用第一种,我已经封装成工具类了. 二.代码实现 ...

  9. luoguP4101 [HEOI2014]人人尽说江南好 结论

    题目大意: 给定\(n\)堆初始大小为\(1\)的石堆 每次选择两堆石子合并,特别的,合并之后的两堆石子不能\(> m\) 询问先手必赢? 不妨设我们是先手,且最后我们必胜 我们考虑构造局面\( ...

  10. 【2016NOIP十连测】【test4】【状压DP】【容斥原理】巨神兵

    题目大意: 给一个n个点(n<=17),m条边的有向图(无自环.无重边),求其无环子图的方案数. 题解: 看到n<=17,显然是用状压dp. 用f[i]表示点集i的满足条件的方案数. 状态 ...