题目链接:http://codeforces.com/gym/101635

题目大意:

  推荐一篇文章:https://blog.csdn.net/wang_heng199/article/details/74477738

  该题就是要求凸包的宽度(即平行切线间的最小距离)。

AC代码:

 #include <bits/stdc++.h>

 using namespace std;
const double inf = 2e9;
const double esp = 1e-;
int sgn(double x){
if(fabs(x)<esp) return ;
if(x<) return -;
else return ;
}
struct Point{
double x,y;
Point (double _x=,double _y=){
x=_x,y=_y;
}
Point operator - (const Point &b) const{
return Point(x-b.x,y-b.y);
}
double operator ^ (const Point &b) const {
return x*b.y-y*b.x;
}
double operator * (const Point &b) const {
return x*b.x+y*b.y;
}
void input(){
scanf("%lf%lf",&x,&y);
}
};
double dist(Point a,Point b){
return sqrt((a-b)*(a-b));
}
const int maxn = 2e5+;
Point List[maxn];
int Stack[maxn],top;
bool _cmp(Point p1,Point p2){
double tmp=(p1-List[])^(p2-List[]);
if(sgn(tmp)>) return true;
else if(sgn(tmp)== && sgn(dist(p1,List[])-dist(p2,List[])) <= )
return true;
else
return false;
}
void Graham(int n){
Point p0=List[];
int k=;
for(int i=;i<n;i++){
if(p0.y>List[i].y || (p0.y == List[i].y && p0.x > List[i].x)){
p0=List[i];
k=i;
}
}
swap(List[k],List[]);
sort(List+,List+n,_cmp);
if(n==){
top = ;
Stack[]=;
return;
}
if(n==){
top=;
Stack[]=,Stack[]=;
return;
}
Stack[]=,Stack[]=;
top=;
for(int i=;i<n;i++){
while(top> &&
(sgn((List[Stack[top-]]-List[Stack[top-]])^(List[i]-List[Stack[top-]]))<=))
top--;
Stack[top++]=i;
}
}
double rotating_calipers(Point p[],int n){
double ans=inf;
Point v;
int cur=;
for(int i=;i<n;i++){
v=p[i]-p[(i+)%n];
while(sgn(v^(p[(cur+)%n]-p[cur]))<)
cur=(cur+)%n;
ans=min(ans,
((p[cur]-p[(i+)%n])^(p[i]-p[(i+)%n]))/(dist(p[i],p[(i+)%n])));
}
return ans;
}
Point p[maxn];
int main(){
int N,R;
scanf("%d%d",&N,&R);
for(int i=;i<N;i++)
List[i].input(); Graham(N);
for(int i=;i<top;i++)
p[i]=List[Stack[i]];
double ans=rotating_calipers(p,top);
printf("%.16lf\n",ans);
return ;
}

  

Gym101635K Blowing Candles的更多相关文章

  1. Gym - 101635K:Blowing Candles (简单旋转卡壳,求凸包宽度)

    题意:给定N个点,用矩形将所有点覆盖,要求矩形宽度最小. 思路:裸体,旋转卡壳去rotate即可. 最远距离是点到点:宽度是点到边. #include<bits/stdc++.h> #de ...

  2. 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)

    A. Cakey McCakeFace 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string.h&g ...

  3. 2017 SWERC

    2017 SWERC A:Cakey McCakeFace 题目描述:有一个炉每次只能放一个蛋糕,炉的进口和出口各放了一个探测器,当放蛋糕进去时,进口的探测器会记录时刻,当蛋糕做好后,蛋糕从出口出来, ...

  4. C - New Year Candles

    Problem description Vasily the Programmer loves romance, so this year he decided to illuminate his r ...

  5. codeforces A. New Year Candles 解题报告

    题目链接:http://codeforces.com/problemset/problem/379/A 题目意思:给定a支蜡烛(每支蜡烛可以燃烧1小时),可以在燃尽的a支蜡烛中看能组成多少组b支蜡烛, ...

  6. uvalive5810 uva12368 Candles

    题意:每组数据给出n个数,每个数在1-100,问组成这些数的蜡烛的权值的最小值.权值=把选的蜡烛从大到小排列组成的数 组成方式:比如有1 3两个蜡烛 可以组成13(1和3)或4(1+3) 只有一个加号 ...

  7. ARC 101 C - Candles

    题面在这里! 显然直接枚举左端点(右端点)就OK啦. #include<cstdio> #include<cstdlib> #include<algorithm> ...

  8. POJ1484(Blowing Fuses)--简单模拟

    题目链接:http://poj.org/problem?id=1484 这题直接简单模拟即可.给你n个容器,m个操作,最大容量C.模拟每一个对器件的开关操作.如果原来是关闭的,则打开,同时最大功耗加上 ...

  9. Solution -「ABC 219H」Candles

    \(\mathcal{Description}\)   Link.   有 \(n\) 支蜡烛,第 \(i\) 支的坐标为 \(x_i\),初始长度为 \(a_i\),每单位时间燃烧变短 \(1\) ...

随机推荐

  1. NFS共享设置

    一.安装所需要的软件环境[root@fengling ~]# yum -y install rpcbind nfs-utils二.创建共享目录mkdir /web三.启动服务[root@fenglin ...

  2. HDU 2513 Cake slicing

    #include<bits/stdc++.h> using namespace std; int n,m,k; int cherry[405],dp[405][405]; int solv ...

  3. Python 3之bytes新特性

    转载: Python 3最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分. 文本总是Unicode,由str类型表示,二进制数据则由bytes类型表示. Python 3不会以任意隐式的方 ...

  4. Windows10中打开git bash闪退解决方案

    重装系统后打开gitbash莫名其妙闪退... 究其原因,好像是盗版系统的null.sys文件损坏 那就在这里附上null.sys文件的下载链接: https://pan.baidu.com/s/1V ...

  5. Spark学习笔记(一)

    概念: Spark是加州大学伯克利分校AMP实验室,开发的通用内存并行计算框架. 支持用scala.java和Python等语言编写应用程序.相较于Hdoop,往往有更好的运行效率. Spark包括了 ...

  6. 图论--2-SAT--HDU/HDOJ 4115 Eliminate the Conflict

    Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...

  7. CentOS启用iptables防火墙

    centos 7默认的防火墙使用firewall,系统服务管理方式也变更了,可以通过systemctl命令控制. 可以参考这个链接 但是习惯用iptables,可以按下面的操作改下 1.关闭firew ...

  8. 自定义Element父子不关联的穿梭树

    Element自身是有一个Transfer穿梭框组件的,这个组件是穿梭框结合checkbox复选框来实现的,功能比较单一,自己想实现这个功能也是很简单的,只是在项目开发中,项目排期紧,没有闲功夫来实现 ...

  9. P2380狗哥采矿(状态不易设计)

    描述:https://www.luogu.com.cn/problem/P2380 首先分析一下,易知传送带一定是要么向上,要么向右.且一定摆满了整个矩阵. 所以我们设 f [ i ] [ j ]表示 ...

  10. Listener:监听器

    目录 Listener概述 ServletContextListener Listener概述 web的三大组件之一 Servlet.Filter.Listener 事件监听机制 事件:一件事情 事件 ...