CodeForces 772B Volatile Kite
计算几何,直觉。
凭直觉猜的做法,把每条线段的中点连起来,每个点到对应内部线段的距离,取个最小值。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std; #define eps 1e-8
#define zero(x)(((x)>0?(x):-(x))<eps) int T,n; struct point
{
double x,y;
}; double xmult(point p1,point p2,point p0)
{
return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} double distance(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
} point intersection(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
} point ptoseg(point p,point l1,point l2)
{
point t=p; t.x+=l1.y-l2.y,t.y+=l2.x-l1.x;
if(xmult(l1,t,p)*xmult(l2,t,p)>eps)
return distance(p,l1)<distance(p,l2)?l1:l2;
return intersection(p,t,l1,l2);
} point p[]; int main()
{ scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); double ans = 99999999999999.0;
for(int i=;i<=n;i++)
{
int A = i-;
int B = i;
int C = i+; if(i-==) A=n;
if(i+==n+) C=; point a,b; a.x = (p[A].x+p[B].x)/;
a.y = (p[A].y+p[B].y)/; b.x = (p[C].x+p[B].x)/;
b.y = (p[C].y+p[B].y)/; point c = ptoseg(p[B],a,b);
ans = min(ans,distance(p[B],c)); } printf("%f\n",ans); return ;
}
CodeForces 772B Volatile Kite的更多相关文章
- CodeForces 800B Volatile Kite(点与直线的距离)(Java 实现)
CodeForces 800B Volatile Kite(点与直线的距离)(Java 实现) 传送门 如果想要一个凸多边形不退化为凹多边形,那么任意的相邻的三个点必然最多形成一条直线.因此我们可以求 ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) D. Volatile Kite
地址:http://codeforces.com/contest/801/problem/D 题目: D. Volatile Kite time limit per test 2 seconds me ...
- Codeforces801D Volatile Kite 2017-04-19 00:30 122人阅读 评论(0) 收藏
D. Volatile Kite time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 【codeforces 801D】Volatile Kite
[题目链接]:http://codeforces.com/contest/801/problem/D [题意] 给你一个凸多边形的n个点; 然后允许你将每个点移动到距离不超过D的范围内; 要求无论如何 ...
- codeforces 801 D. Volatile Kite(数学题)
题目链接:http://codeforces.com/contest/801/problem/D 题意:求出一个最大值D,使得一个给定的凸多边形任意点移动范围在半径为D的圆中,都不会构成一个凹都边形. ...
- Codeforces Round#409/VK-Cup 2017 Round2
来自FallDream的博客,未经允许,请勿转载,谢谢. 和ditoly组队打VK-Cup,起了个名字叫Vegetable Chicken(意思显然),然后昨天我做AB他切C 很不幸的是.....我写 ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】
A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- VK Cup 2017 - Round 2
FallDream打的AB都FFT了,只剩一个我打的C,没进前一百,之后看看马拉松复活赛有没机会呗. A. Voltage Keepsake 题目大意:n个东西,每个东西一开始有bi能源,每秒消耗ai ...
随机推荐
- ios 虚拟机中文件下载路径
每个人mac上的路径会有不同,你可以打印出你文件下载存放的路径,然后拷贝一下,再单击桌面空白处,最上面的导航栏上有个“前往”,然后找到“前往文件夹”,粘贴一下,就可以找到了.
- Eclipse 重构功能的使用与重构快捷键
重构是什么? 在代码写好之后改进它的设计. 重构分类:物理结构.类层次结构.类内部结构. 名称 快捷键 直译 作用范围 描述 Rename Alt + Shift + R 可以对任意变量.类. ...
- Google Map API 应用实例说明
目录 Google Map API 1基础知识 1.1 Google 地图 API 概念 1.2 Google 地图的"Hello, World" 1.2.1 加载 Google ...
- CF821 E. Okabe and El Psy Kongroo 矩阵快速幂
LINK 题意:给出$n$条平行于x轴的线段,终点$k$坐标$(k <= 10^{18})$,现在可以在线段之间进行移动,但不能超出两条线段的y坐标所夹范围,问到达终点有几种方案. 思路:刚开始 ...
- [Luogu 2023] AHOI2009 维护序列
[Luogu 2023] AHOI2009 维护序列 恕我冒昧这和线段树模板二有个琴梨区别? #include <cstdio> int n,m; long long p; class S ...
- JVM调优总结(3):垃圾回收面临的问题
如何区分垃圾 上面说到的“引用计数”法,通过统计控制生成对象和删除对象时的引用数来判断.垃圾回收程序收集计数为0的对象即可.但是这种方法无法解决循环引用.所以,后来实现的垃圾判断算法中,都是从程序运行 ...
- hadoop之安全篇
---------------持续更新中------------------- hadoop集群安全架构 如下图所示: --------------------------未完待续---------- ...
- 你不知道的Static
Static静态字段,静态方法,静态代码块 壹 简介 一些场景下会要求一个类的多个实例共享一个成员变量:有时候想定义一些不和具体对象关联.不需要new就调用的方法 举例:Console类的Write ...
- vue-cli使用说明
一.安装npm install -g vue-cli 推荐使用国内镜像 先设置cnpm npm install -g cnpm --registry=https://registry.npm.taob ...
- Ajax请求数据与删除数据后刷新页面
1.ajax异步请求数据后填入模态框 请求数据的按钮(HTML) <a class="queryA" href="javascript:void(0)" ...