计算几何/旋转卡壳


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

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

  嗯反正就是这样……

  这是一道模板题

  好像必须写成循环访问?我在原数组后面复制了一遍点,结果挂了……改成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. loadrunner学习笔记之参数设置

    一.关于参数的定义 在你录制程序运行的过程中,脚本生成器自动生成由函数组成的用户脚本.函数中参数的值就是在录制过程中输入的实际值. 例如,你录制了一个Web应用程序的脚本.脚本生成器生成了一个声明,该 ...

  2. loadrunner 的Administration Page里面设置

    loadrunner 的Administration Page里面设置   1.Set LOGIN form's action tag to an error page.在登录的时候,传递一个动态变量 ...

  3. ECSHOP中 {insert name='ads' id=$ads_id num=$ads_num}含义

    <div class="smallban">        <ul>                <!-- TemplateBeginEditabl ...

  4. 四、redis系列之主从复制与哨兵机制

    1. 绪言 在现实应用环境中,出于数据容量.容灾.性能等因素的考虑,往往不会只使用一台服务器,而是使用集群的方式.Redis 中也有类似的维持一主多从的方式提高 Redis 集群的高可用性的方案,而其 ...

  5. Java反射机制demo(四)—获取一个类的父类和实现的接口

    Java反射机制demo(四)—获取一个类的父类和实现的接口 1,Java反射机制得到一个类的父类 使用Class类中的getSuperClass()方法能够得到一个类的父类 如果此 Class 表示 ...

  6. [ 原创 ]Centos 7.0下安装 Tomcat8.5.15

    Tomcat下载地址:http://tomcat.apache.org/download-80.cgi#8.5.15 上传到文件夹 并解压缩 出现问题: 解决方法: http://blog.csdn. ...

  7. Django url 标签和reverse()函数的使用(转)

    使用url标签和reverse()函数,可以避免在模板和view中对url进行硬编码,这样即使url改变了,对模板和view也没有影响, 其实在模板, view中,如果想获取当前访问的url,那用re ...

  8. BZOJ 2726: [SDOI2012]任务安排 [斜率优化DP 二分 提前计算代价]

    2726: [SDOI2012]任务安排 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 868  Solved: 236[Submit][Status ...

  9. px em rem 字体单位问题

    px:相对长度单位,相对于屏幕分辨率 em:相对长度单位,相对于body而言 rem:相对长度单位,相对于html根元素 注意:浏览器默认大小:16px;

  10. poj 3660 Cow Contest Flyod

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...