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 ...
随机推荐
- CF839 B 贪心
很玄的一道贪心题,大意是给出k排 XX - XXXX - XX这样的座位,有n个团体,要求不同团体不能相邻而坐,中间可以空一个座位或是由走廊隔开. 很明显最先想到可以以2为单位划分座位,但是中间4连座 ...
- CF835 C 前缀和
100*100规模上第一象限坐标系上有1e5规模的点,每个点随时间在同一个值域内(最大10)周期递增,但初始值不同,给出一个矩阵和时间询问此时范围内点的值的和. 预处理初始时刻不同权值下的二维前缀和, ...
- 三星c7换屏幕教程
https://jingyan.baidu.com/article/20b68a88f49cb9796cec6282.html
- 解决gridview row 左边序列号 显示不完全的技巧
放在主程序 入口处, public Form1() { InitializeComponent(); gridView1.IndicatorWidth = ; //<宽度值>官方推荐常用是 ...
- [php]http响应头解析
(Status-Line) HTTP/ OK Cache-Control no-cache Content-Length Content-Type image/gif Date Sat, Dec :: ...
- 网络流入门--最大流算法Dicnic 算法
感谢WHD的大力支持 最早知道网络流的内容便是最大流问题,最大流问题很好理解: 解释一定要通俗! 如右图所示,有一个管道系统,节点{1,2,3,4},有向管道{A,B,C,D,E},即有向图一张. ...
- c++都忘记了,看了看那本发黄的C++primer,还是要去翻下了
char *s="string"和char s[]="string"的区别 void main() { char* pStr1 = "Hello!&q ...
- 爬虫--PySpider框架
PySpider框架 PySpider框架的作用
- 服务器端包含 SSI简介
服务器端包含 SSI,是英文 Server Side Includes的简写.SSI是一种可以指挥服务器动态声称网页内容的HTML指令. 通常SSI可以用来确保网页中的一些通用内容,比如版权信息.联系 ...
- 仿360影视网站模板html
链接:http://pan.baidu.com/s/1mhIkV4s 密码:9wgq