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. 谈谈 Google 的 Test Certified

    转载请联系作者,谢谢! 本文简单介绍下Google的Test Certified. Test Certified(后文简称TC)是Google内部的一个认证项目,在8年的时间里取得了多个里程碑,有17 ...

  2. Spring AOP 5种通知与java动态代理

    接口,要求为每个方法前后添加日志  @Component("arithmeticCalculator") public class ArithmeticCalculatorImpl ...

  3. 社交化分享SDK for Unity

    前言 社交化分享,即分享到社交网络. 本文主要记录的是在Unity集成社交化分享SDK,现主流的分享SDK有如下: 1.友盟社交化分享 for unity 2.ShareSDK分享 for unity ...

  4. Windows系统Stunnel客户端的配置

    Stunnel官方就有Windows版本,到下面的地址下载: https://www.stunnel.org/downloads.html 选择”stunnel-X.XX-installer.exe“ ...

  5. 理解Java中字符流与字节流的区别

    1. 什么是流 Java中的流是对字节序列的抽象,我们可以想象有一个水管,只不过现在流动在水管中的不再是水,而是字节序列.和水流一样,Java中的流也具有一个“流动的方向”,通常可以从中读入一个字节序 ...

  6. Canon

    .打开压缩包发现2个文件,1个是加密的zip.zip,另一个是music.mp3.猜测zip.zip的解压密码隐藏在music.mp3里 .用MP3Stego解密music.mp3,密码就是标题的Ca ...

  7. Hash链表

    <?php /* +------------------------------------------------------------------------------ | dateti ...

  8. Android项目,从web上取下汉字,中文部分乱码

    Android项目,从web上取下汉字,中文部分乱码. 常见问题,搜索一下,网上有很多办法解决.如果还没有试过这个办法,可以尝试一下. BufferedReader in = new Buffered ...

  9. Padrino 生成器指南

    英文版出处:http://www.padrinorb.com/guides/generators Padrino提供了用于快速创建应用的生成器,其优势在于构建推荐的Padrino应用结构.自动生成罗列 ...

  10. ASP.NET整理:Cookie,Application,Session,页面生命周期

    一.设置Cookie的2种方式 1.    Repsonse.Cookie[“名”] = 值; 2.    HttpCookie hcCookie = new HttpCookie(“名”,值); h ...