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 ...
随机推荐
- bootstrap 栅格calss
container container-fluid row col-xs- col-sm- col-md- col-lg- col-md-offset- col-md-push- col-md-pul ...
- Idea工具常用技巧总结
转自:https://www.jianshu.com/p/131c2deb3ecf Idea常用技巧总结 1.无处不在的跳转 注:这里的快捷键是自己定义的,并非大家的都一样,可以通过findActio ...
- STL在算法比赛中简单应用
STL基础 和 简单的贪心问题 STL(Standard Template Library) 即 标准模板库. 它包含了诸多在计算机科学领域里所常用的基本数据结构和算法.这些数据结构可以与标准算法一起 ...
- 母版页 VS shtml—ASP.NET细枝末节(3)
这算是html的重用吧? 网页很多地方长得一样,也有不一样的地方. 把网页中一样的地方,提取出来,形成一个文档. 在其他网页中引用,是网站开发的一个传统的思维. 当然不同的技术有不同的表现形式. 例如 ...
- 数据库-Core Data
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong 数据库-Core Data 技术博客htt ...
- POJ - 1330 Nearest Common Ancestors 最近公共祖先+链式前向星 模板题
A rooted tree is a well-known data structure in computer science and engineering. An example is show ...
- c++刷题(3/100)数独,栈和队列
stack的基本操作 • s.size():返回栈中的元素数量 • s.empty():判断栈是否为空,返回true或false • s.push(元素):返回对栈顶部“元素”的可变(可修改)引用 • ...
- 旋转3D立方体
<!DOCTYPE html><html><head> <title>css-3d-盒子</title> <meta charset= ...
- windows+python3.6下安装fasttext+fasttext在win上的使用+gensim(fasttext)
真是坑了好久,faxttext对win并不是很友好,所以遇到了很多坑,记录下来,以供大家少走弯路. 法1:刚开始直接用pip install fasttext,最后一直报下面这个错误 “error:M ...
- 一键切图 PS 动作 【收藏】
使用方法 一键切图动作.zip 1. 下载动作 2. 打开PS 动作 窗口,导入动作 3. 选中图层后 点击 F2 一键切图 详情看原文链接 原文链接