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 ...
随机推荐
- CDN问题积累
我见到的CDN服务器只支持GET方法,只能以URL为索引来缓存内容. 有的时候我用相同的URL,相同的GET方法,但是不同Header参数时,后台对应的应该是不同的方法,返回不同的结果. 而这时候使用 ...
- --BEA官方网站(http: //www.bea.com)甲骨文已完成对该公司的收购BEA Weblogic Server 7.0x应用服务器简明安 装、配置手册 1
====================简 介: BEA公司是业内著名的中间件产商,以Tuxedo及Weblogic闻名于世,而其基础件平台(infrastructure)Weblogic platf ...
- form:select form:options 标签数据回显
在jsp页面中经常会使用到 form:select form:options 遍历后台List集合生成 select 下拉选择器,但是 form:options 标签并没有提供一个可以回显数据的属性. ...
- [转]标准C++中的string类的用法总结
原文地址:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非常 ...
- 使用JSON Web Token设计单点登录系统
用户认证八步走 所谓用户认证(Authentication),就是让用户登录,并且在接下来的一段时间内让用户访问网站时可以使用其账户,而不需要再次登录的机制. 小知识:可别把用户认证和用户授权(Aut ...
- eclipse加速/Nginx配置跨域代理
下班时间到啦! --下班都是他们的,而我,还是什么都没有. eclipse加速 去掉包含js文件的包的js验证,否则每次启动都需要进行校验(右击项目->properties) Nginx配置跨域 ...
- .net APIHelper client获取数据
using Newtonsoft.Json; using System.Net.Http.Headers; public static class APIHepler { public static ...
- Ajax+innerHTML+Dgls=好的用户体验+高性能+高效率
为了引入Dgls,我们从创建Dom节点说起. 用JS创建Dom节点 var div = document.createElement('div'); div.className = 'gdls'; v ...
- python 实现字符串转整型
def str2Int(s): l=list(s) if len(l)<=0: return 0 flag=0 sum=0 dict_num={':9} dict_tag={'+':1,'-': ...
- inet_confirm_addr && confirm_addr_indev
确认给定参数范围的ip地址是否存在: /* * Confirm that local IP address exists using wildcards: * - net: netns to chec ...