ural 1215 Exactness of Projectile Hit
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 20000
using namespace std;
const double eps=1e-; inline double sqr(double x)
{
return x*x;
}
inline int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
struct node
{
double x,y;
}p[maxn]; double dis(node a,node b)
{
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
} double cross(node a,node b,node c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} double dot(node a,node b)
{
return a.x*b.x+a.y*b.y;
}
bool in(node *p,int n,node a)
{
p[n]=p[];p[n+]=p[];
for(int i=; i<n; i++)
{
if(-cross(p[i],p[i+],a)*cross(p[i+],p[i+],a)>eps)
{
return false;
}
}
return true;
} double disten(node pp,node a,node b)
{
if(a.x==b.x&&a.y==b.y) return dis(pp,a);
node st1;st1.x=b.x-a.x; st1.y=b.y-a.y;
node st2;st2.x=pp.x-a.x; st2.y=pp.y-a.y;
node st3;st3.x=pp.x-b.x; st3.y=pp.y-b.y;
if(dcmp(dot(st1,st2))<) return dis(pp,a);
else if(dcmp(dot(st1,st3)>)) return dis(pp,b);
else return fabs(cross(a,b,pp))/(dis(a,b));
} int main()
{
int n;
node c;
scanf("%lf%lf%d",&c.x,&c.y,&n);
double min1=1e10;
for(int i=; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
if(in(p,n,c))
{
printf("%.3lf\n",0.0);
}
else
{
for(int i=; i<n; i++)
{
min1=min(min1,disten(c,p[i],p[i+]));
}
printf("%.3lf\n",*min1);
}
return ;
}
ural 1215 Exactness of Projectile Hit的更多相关文章
- URAL 1873. GOV Chronicles
唔 神题一道 大家感受一下 1873. GOV Chronicles Time limit: 0.5 secondMemory limit: 64 MB A chilly autumn night. ...
- [LeetCode] Design Hit Counter 设计点击计数器
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- Buffer cache hit ratio性能计数器真的可以作为内存瓶颈的判断指标吗?
Buffer cache hit ratio官方是这么解释的:“指示在缓冲区高速缓存中找到而不需要从磁盘中读取的页的百分比.” Buffer cache hit ratio被很多人当做判断内存的性能指 ...
- LeetCode Design Hit Counter
原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...
- Breakpoint is not hit
新拿到一个Silverlight项目,能够正常运行,但是一旦运行起来,断点处由实心点变成了空心的,并警告:The breakpoint will not currently be hit. No sy ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
随机推荐
- openStack telemetry/ceilometry 云平台资源监控度量
- windows 编程—— 常用函数 与 操作
目录: MessageBox() 和 PlaySound() 获得窗口 或屏幕大小 获得字体大小 输出文字 屏蔽和显示控制台窗口 1. MessageBox() 和 PlaySound() Messa ...
- AFNetworking (3.1.0) 源码解析 <三>
今天要介绍的是Reachability文件夹下的AFNetworkReachabilityManager类.通过字面意思我们就可以知道AFNetworkReachabilityManager是用来监测 ...
- 工作的准备:atoi,itoa,strcpy,memcpy,strcmp,二分查找,strcat
对常见的几个函数,周末没事写写,绝对是笔试面试中非频繁,前面n届学长无数次强调了,大家就别怀疑了.从今天开始,每天10道题. int atoi(const char* str) { if(str==N ...
- 使用nice命令调整进程优先级
Adjusting Process Priority with nice When Linux processes are started, they are started with a spe ...
- MM32/STM32中断和事件梳理
Interrupt_event梳理 预备资料 MM32/stm32中文参考手册 Cortex-M3权威指南(深入了解中断和异常) MM32F103产品手册(配置GPIO的复用功能可能用到) 提出问题 ...
- python的按位运算
#coding=utf-8#"&"按位与运算,是指一个数字转化为二进制,然后这些二进制的数按位来进行与运算a=7&18print a'''首先将7转化为二进制,得到 ...
- oracle的一知半解
这里只讲第一次开发运用oracle数据库的.net程序遇到问题: 1.程序与oracle数据库在同一台的服务器,貌似设置好连接字符串就可以直接访问( 需要主要的问题: 字符串格式:Data Sourc ...
- 浅谈PHP代码设计结构
浅谈PHP代码设计结构 您的评价: 还行 收藏该经验 coding多年,各种代码日夜相伴,如何跟代码友好的相处,不光成为职业生涯的一种回应,也是编写者功力的直接显露. 如何看 ...
- Ubuntu桌面版与服务器版有什么不同?
提到安装Linux,Ubuntu可谓是最受欢迎的.为了满足每个人的需求,出现了不少版本或风格的Ubuntu;其中两项便是桌面版与服务器版.只要发布版本号一致,这两者从核心来说也就是相同的,唯 ...