题目链接: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. c语言实现数字的倒序输出

    c语言实现数字的倒序输出, 例如: 输入数值:1234倒序输出: 4321 #include <stdio.h> int main(int argc, char *argv[]) { in ...

  2. IDEA 之 常用快捷键

    1. 编辑 No. 快捷键 功能描述 01 Ctrl+Space 补全代码 02 Ctrl+Shift+Space 补全代码,添加分号结束符 03 Ctrl+q 展示某个类或方法的API说明文档 04 ...

  3. Xftp的下载安装,以及如何使用XFtp连接虚拟主机/服务器

    1.下载ftp软件  下载地址: 点我立即下载 2.下载后双击安装  下一步  选择Free for Home/School   然后其他的默认下一步即可 3.打开之前领取的免费一年虚拟主机的网址,登 ...

  4. Codeforces Round 623(Div. 2,based on VK Cup 2019-2020 - Elimination Round,Engine)D. Recommendations

    VK news recommendation system daily selects interesting publications of one of n disjoint categories ...

  5. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 B so easy

    题目链接:https://nanti.jisuanke.com/t/41384 这题暴力能过,我用的是并查集的思想,这个题的数据是为暴力设置的,所以暴力挺快的,但是当他转移的点多了之后,我觉得还是我这 ...

  6. [UWP]推荐一款很Fluent Design的bilibili UWP客户端 : 哔哩

    UWP已经有好几个Bilibili的客户端,最近有多了一个: 哔哩 - Microsoft Store 作者云之幻是一位很擅长设计的UWP开发者,我也从他那里学到了很多设计方面的技巧.它还是一位Bil ...

  7. Linux常用的安全加固

    一.账号和口令 1.1 禁用或删除无用账号 减少系统无用账号,降低安全风险. 操作步骤userdel <用户名> //删除不必要的账号.passwd -l <用户名> //锁定 ...

  8. Python基础01 集合

    初始化 # python3 # coding = utf-8 mylist = [] for item in range(10): mylist.append(item * 10 + 3) myset ...

  9. 如何使用Golang实现一个API网关

    你是否也存在过这样的需求,想要公开一个接口到网络上.但是还得加点权限,否则被人乱调用就不好了.这个权限验证的过程,最好越简单越好,可能只是对比两个字符串相等就够了.一般情况下我们遇到这种需要,就是在函 ...

  10. openCV从入门到放弃

    与图像处理之间的关系,opencv的简介和使用定位 如题...因为偶然的机会需要用到图像处理,像我这么爱学习 并且动手能力又强的人怎么能没有心得笔记呢,哇哈哈哈.非要说的low逼点这玩意儿这玩意儿就是 ...