【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)
题目链接
旋转卡壳模板题把。
有时间再补总结吧。
#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 (二维凸包,旋转卡壳)的更多相关文章
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
D - Beauty Contest Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 2079 Triangle (二维凸包旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Submit Stat ...
- 洛谷 P1452 Beauty Contest 解题报告
P1452 Beauty Contest 题意 求平面\(n(\le 50000)\)个点的最远点对 收获了一堆计算几何的卡点.. 凸包如果不保留共线的点,在加入上凸壳时搞一个相对栈顶,以免把\(n\ ...
- 洛谷 P1452 Beauty Contest
题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...
- HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)
题目链接 题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积. 题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点. 利用叉积面积求高,利用点积的性质求最左右点和长度 ...
- [洛谷P1452]Beauty Contest
题目大意:给你$n$个点,求出其中最远点的距离 题解:求出凸包,最远点一定都在凸包上,可以对每条边求出最远的点(可以双指针),然后求出和这条边的端点的距离,更新答案 卡点:最开始对每个点求出最远点,但 ...
- 洛谷P4054 [JSOI2009]计数问题(二维树状数组)
题意 题目链接 Sol 很傻x的题.. c才100, n, m才300,直接开100个二维树状数组就做完了.. #include<bits/stdc++.h> using namespac ...
- 【洛谷】【动态规划/二维背包】P1855 榨取kkksc03
[题目描述:] ... (宣传luogu2的内容被自动省略) 洛谷的运营组决定,如果...,那么他可以浪费掉kkksc03的一些时间的同时消耗掉kkksc03的一些金钱以满足自己的一个愿望. Kkks ...
- 【洛谷】【动态规划(二维)】P1508 Likecloud-吃、吃、吃
[题目描述:] 正处在某一特定时期之中的李大水牛由于消化系统比较发达,最近一直处在饥饿的状态中.某日上课,正当他饿得头昏眼花之时,眼前突然闪现出了一个n*m(n and m<=200)的矩型的巨 ...
- 洛谷 P3397 地毯 【二维差分标记】
题目背景 此题约为NOIP提高组Day2T1难度. 题目描述 在n*n的格子上有m个地毯. 给出这些地毯的信息,问每个点被多少个地毯覆盖. 输入输出格式 输入格式: 第一行,两个正整数n.m.意义如题 ...
随机推荐
- 3dContactPointAnnotationTool开发日志(十七)
今天又改进了一下算法,把生成出来的接触点按中心坐标拍了个序,再把中心坐标一样的坐标点合并,x,y,z每个维度都只保留大的值.然后来看看效果: 先是1倍的,只剩下4096个接触点了,2^12个, ...
- 通过access_token openid获取微信用户昵称等信息
<?php header('Access-Control-Allow-Origin:*'); $access_token = !empty($_GET['access_token'])?$_GE ...
- (转)Linux常用性能检测命令
一.uptime Uptime命令的显示结果包括服务器已经运行了多长时间,有多少登陆用户和对服务器性能的总体评估(load average).load average值分别记录了上个1分钟,5 ...
- PHP中如何使用Redis接管文件存储Session详解
https://www.jb51.net/article/151580.htm 前言 php默认使用文件存储session,如果并发量大,效率会非常低.而redis对高并发的支持非常好,可以利用red ...
- C# lamda表达式
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 系统管理员需知:25个Linux服务器安全技巧(转)
来源:51CTO 作者:51CTO 大家都认为 Linux 默认是安全的,我大体是认可的 (这是个有争议的话题).Linux默认确实有内置的安全模型.你需要打开它并且对其进行定制,这样才能 ...
- Android------BottonTabBar
前言:一款简单好用封装好的AndroidUI控件,底部导航栏. 1.使用 1.1添加 compile 'com.hjm:BottomTabBar:1.1.1' 1.2 activity_main. ...
- 在select中,载入时默认select为空白,选项内不显示空白项
有两种办法,一种纯css实现,一种借助js实现. html: <body onload="load()"> <select id="abc" ...
- jQuery返回顶部代码
页面较长时,使用返回顶部按钮比较方便,在电商中必备操作.下面自己制作一个js文件,totop.js,把它直接引用到需要的网页中即可. $(function () { $("body" ...
- 当要将其他类型转成String类型时候 看String的方法
当要将其他类型转成String类型时候 看String的方法进行转换