题目链接

旋转卡壳模板题把。

有时间再补总结吧。

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 100010;
struct point{
int x, y;
}p[MAXN];
int operator * (point a, point b){ // a x b
return a.x * b.y - b.x * a.y;
}
point operator - (point a, point b){
return (point){ a.x - b.x, a.y - b.y };
}
int cmp1(const point a, const point b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
inline double k(point a, point b){
return a.x == b.x ? 1e18 : ((double)b.y - a.y) / (b.x - a.x);
}
inline double dis(point a, point b){
int px = b.x - a.x, py = b.y - a.y;
return sqrt(px * px + py * py);
}
inline int dp(point a, point b){
int px = b.x - a.x, py = b.y - a.y;
return px * px + py * py;
}
int n, top, tp, ans;
point st[MAXN], ts[MAXN];
inline double mult(point a, point b, point c){
return (a - c) * (b - c);
}
int SpecialJudge(){
for(int i = 2; i <= n; ++i)
if(p[i].y != p[i - 1].y)
return 0;
return 1;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d%d", &p[i].x, &p[i].y);
if(SpecialJudge()){
int Min = 0x3f3f3f3f, Max = -0x3f3f3f3f;
for(int i = 1; i <= n; ++i){
Min = min(Min, p[i].x);
Max = max(Max, p[i].x);
}
printf("%d\n", (Max - Min) * (Max - Min));
return 0;
}
sort(p + 1, p + n + 1, cmp1);
for(int i = 1; i <= n; ++i){
while(top > 1 && k(st[top - 1], p[i]) < k(st[top - 1], st[top])) --top;
st[++top] = p[i];
}
for(int i = 1; i <= n; ++i){
while(tp > 1 && k(ts[tp - 1], p[i]) > k(ts[tp - 1], ts[tp])) --tp;
ts[++tp] = p[i];
}
for(int i = tp - 1; i; --i) st[++top] = ts[i];
int j = 2;
for(int i = 1; i <= top; ++i){
while(mult(st[i], st[i + 1], st[j]) < mult(st[i], st[i + 1], st[j + 1]))
if(++j > top) j = 1;
ans = max(ans, max(dp(st[i], st[j]), dp(st[i + 1], st[j])));
}
printf("%d\n", ans);
return 0;
}

【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)的更多相关文章

  1. poj 2187 Beauty Contest(二维凸包旋转卡壳)

    D - Beauty Contest Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  2. poj 2079 Triangle (二维凸包旋转卡壳)

    Triangle Time Limit: 3000MS   Memory Limit: 30000KB   64bit IO Format: %I64d & %I64u Submit Stat ...

  3. 洛谷 P1452 Beauty Contest 解题报告

    P1452 Beauty Contest 题意 求平面\(n(\le 50000)\)个点的最远点对 收获了一堆计算几何的卡点.. 凸包如果不保留共线的点,在加入上凸壳时搞一个相对栈顶,以免把\(n\ ...

  4. 洛谷 P1452 Beauty Contest

    题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...

  5. HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)

    题目链接   题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积. 题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点. 利用叉积面积求高,利用点积的性质求最左右点和长度 ...

  6. [洛谷P1452]Beauty Contest

    题目大意:给你$n$个点,求出其中最远点的距离 题解:求出凸包,最远点一定都在凸包上,可以对每条边求出最远的点(可以双指针),然后求出和这条边的端点的距离,更新答案 卡点:最开始对每个点求出最远点,但 ...

  7. 洛谷P4054 [JSOI2009]计数问题(二维树状数组)

    题意 题目链接 Sol 很傻x的题.. c才100, n, m才300,直接开100个二维树状数组就做完了.. #include<bits/stdc++.h> using namespac ...

  8. 【洛谷】【动态规划/二维背包】P1855 榨取kkksc03

    [题目描述:] ... (宣传luogu2的内容被自动省略) 洛谷的运营组决定,如果...,那么他可以浪费掉kkksc03的一些时间的同时消耗掉kkksc03的一些金钱以满足自己的一个愿望. Kkks ...

  9. 【洛谷】【动态规划(二维)】P1508 Likecloud-吃、吃、吃

    [题目描述:] 正处在某一特定时期之中的李大水牛由于消化系统比较发达,最近一直处在饥饿的状态中.某日上课,正当他饿得头昏眼花之时,眼前突然闪现出了一个n*m(n and m<=200)的矩型的巨 ...

  10. 洛谷 P3397 地毯 【二维差分标记】

    题目背景 此题约为NOIP提高组Day2T1难度. 题目描述 在n*n的格子上有m个地毯. 给出这些地毯的信息,问每个点被多少个地毯覆盖. 输入输出格式 输入格式: 第一行,两个正整数n.m.意义如题 ...

随机推荐

  1. Python 零碎信息-基础 02

    1. range xrange 的差别 1.1 range 返回列表对象. 1.2 xrange 返回xrange对象  不需要返回列表里面的值, 节省内存. >>> range(1 ...

  2. TCP系列35—窗口管理&流控—9、紧急机制

    一.概述 我们在最开始介绍TCP头结构的时候,里面有个URG的标志位,还有一个Urgent Pointer的16bits字段.当URG标志位有效的时候,Urgent Poinert用来指示紧急数据的相 ...

  3. An Introduction to Lock-Free Programming

    Lock-free programming is a challenge, not just because of the complexity of the task itself, but bec ...

  4. SpringBoot2.0(三) 文件上传

    SpringBoot中发起文件上传示例: /** * 文件上传 * @param multipartFile * @param path * @return */ @RequestMapping(va ...

  5. jCanvaScript canvas的操作库

    在jcscript.com上下载最新的jCanvaScript.1.5.18.min.js文件  里面有很多关于canvas的方法都已经是封装好了的,只需直接调用,但是要注意调用之前和调用之后都要写: ...

  6. wsgiref 源码解析

    Web Server Gateway Interface(wsgi),即Web服务器网关接口,是Web服务器软件和用Python编写的Web应用程序之间的标准接口. 想了解更多关于WSGI请前往: h ...

  7. 透彻掌握Promise的使用,读这篇就够了

    透彻掌握Promise的使用,读这篇就够了 Promise的重要性我认为我没有必要多讲,概括起来说就是必须得掌握,而且还要掌握透彻.这篇文章的开头,主要跟大家分析一下,为什么会有Promise出现. ...

  8. Linux相关——关于gdb的checkpoint & breakpoints指令

    1,checkpoint ,,,这个指令简直,,,相见恨晚啊,居然现在才发现,.. 好吧来介绍一下这个指令:checkpoint(检查点) 我们调试程序,常常会出现好不容易发现了错误,却已经跑完那个地 ...

  9. PE格式示意图

  10. Navcat中Oracle连接的坑-Instant Client

    报错信息: 官方下载Instant Client下载: http://www.oracle.com/technetwork/cn/topics/intel-macsoft-102027-zhs.htm ...