xuán zhuǎn qiǎ ké模板题

是这么读吧(≖ ‿ ≖)✧

算法挺简单:找对踵点即可,顺便更新答案。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define read(x) x=getint()
#define max(a,b) (a)>(b)?(a):(b)
#define N 50003
using namespace std;
inline int getint() {
int k = 0, fh = 1; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = k * 10 + c - '0';
return k * fh;
}
inline int sqr(int x) {
return x * x;
}
struct Point {
int x, y;
Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
} a[N], tu[N];
Point operator - (Point a, Point b) {
return Point(a.x - b.x, a.y - b.y);
}
inline int Cross(Point a, Point b) {
return a.x * b.y - a.y * b.x;
} int n, top = 0;
inline bool cmp(Point X, Point Y) {
return X.y == Y.y ? X.x < Y.x : X.y < Y.y;
}
inline void mktb() {
for(int i = 1; i <= n; ++i) {
while (top > 1 && Cross(tu[top] - tu[top - 1], a[i] - tu[top]) <= 0)
--top;
tu[++top] = a[i];
}
int k = top;
for(int i = n - 1; i > 0; --i) {
while (top > k && Cross(tu[top] - tu[top - 1], a[i] - tu[top]) <= 0)
--top;
tu[++top] = a[i];
}
}
int main() {
read(n);
for(int i = 1; i <= n; ++i)
read(a[i].x), read(a[i].y);
sort(a + 1, a + n + 1, cmp);
mktb();
int nxt = 2, ans = 0;
for(int i = 1; i < top; ++i) {
while (Cross(tu[i + 1] - tu[i], tu[nxt + 1] - tu[i]) > Cross(tu[i + 1] - tu[i], tu[nxt] - tu[i])) {
++nxt;
if (nxt == top)
nxt = 1;
}
ans = max(ans, sqr(tu[i].x - tu[nxt].x) + sqr(tu[i].y - tu[nxt].y));
}
printf("%d\n", ans);
return 0;
}

更新求凸包的模板,之前那个太麻烦了hhh

【POJ 2187】Beauty Contest 凸包+旋转卡壳的更多相关文章

  1. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  2. POJ 2187 Beauty Contest [凸包 旋转卡壳]

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36113   Accepted: 11204 ...

  3. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  4. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  5. 【POJ】2187 Beauty Contest(旋转卡壳)

    http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...

  6. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  7. Beauty Contest 凸包+旋转卡壳法

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27507   Accepted: 8493 D ...

  8. poj 2187 Beauty Contest 凸包模板+求最远点对

    题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...

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

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

随机推荐

  1. 线程同步以及yield()、wait()、Notify()、Notifyall()

    一.线程同步 1.线程同步的目的是为了保护多个线程访问一个资源时对资源的破坏. 2.线程同步方法是通过锁来实现,每个对象都有切仅有一个锁,这个锁与一个特定的对象关联,线程一旦获取了对象锁,其他访问该对 ...

  2. poj[2392]space elevator

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  3. Xcode 快捷键

    1.commmand +shift +k ,隐藏模拟器键盘,用户可以在真实键盘输入到模拟屏幕上.

  4. 開博客了, 因為搞Delphi 開發的關於Delphi學習

    開博客了, 因為搞Delphi 開發的關於Delphi學習,之前都是用本地TXT文件保存,發現在本地電腦保存非常不方面,而且只能在一台電腦上保存,不容易查看和修改內容.便於以後的記錄只用,以及經驗交流 ...

  5. SQL Server之游标的基础知识

    什么是游标: 游标是可以在结果集中上下游动的指针. 游标的作用: --允许定位到结果集中的特定行. --从结果集的当前位置检索一行或多行数据. --支持对结果集中当前位置的行进行修改. 注意:游标虽然 ...

  6. ASP.NET 中执行 URL 重写

    具体实现步骤(其中的一种实现方法): 一.下载相关的DLL(ActionlessForm.dll和UrlRewriter.dll) http://download.csdn.net/detail/yi ...

  7. Linux 网络编程详解二(socket创建流程、多进程版)

    netstat -na | grep " --查看TCP/IP协议连接状态 //socket编程提高版--服务器 #include <stdio.h> #include < ...

  8. TinyFrame升级之五:全局缓存的设计及实现

    在任何框架中,缓存都是不可或缺的一部分,本框架亦然.在这个框架中,我们的缓存分为两部分:内存缓存和单次请求缓存.简单说来,就是一个使用微软提供的MemoryCache做扩展,并提供全局唯一实例:另一个 ...

  9. ios蓝牙开发(三)ios连接外设的代码实现:手机app去读写蓝牙设备。

    手机app去读写蓝牙设备....... 代码下载: 原文博客主提供Github代码连接,地址是:https://github.com/coolnameismy/demo ios连接外设的代码实现流程: ...

  10. 玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)

    前文 的最后给出了玉伯的一道课后题,今天我们来讲讲这题的思路. 题目是这样的: Number.MAX_VALUE + 1 == Number.MAX_VALUE; Number.MAX_VALUE + ...