URAL 1775 B - Space Bowling 计算几何
B - Space Bowling
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87643#problem/B
Description
Input
The first line contains space-separated integers n and k (1 ≤ k ≤ n ≤ 200) . The i-th of following n lines contains space-separated integersxi and yi (−10 5 ≤ xi, yi ≤ 10 5) , which are the coordinates of the centers of pins. All pins are situated at different points.
Output
Output the minimal possible diameter of a ball which can be used to score a strike, with absolute or relative error not exceeding 10 −6. If a strike can be scored with a ball of arbitrarily small diameter, output “0.000000”.
Sample Input
5 4
0 4
0 6
6 4
6 6
3 0
Sample Output
1.0000000000
HINT
题意
平面上有n个直径为1的圆,然后让你飞出一个球,要求触碰至少k个圆,问这个球的半径至少为多少
题解:
直接暴力枚举两个圆,然后直线方向就是这两个圆的中垂线,然后暴力算距离,取第k大的就好了
有一些小细节
代码前面都是模板,无视就好了
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <complex>
#include <vector>
using namespace std; const double eps = 1e-; //精度控制
const double pi = acos(-); int dcmp(double p) // 三态比较, 负数返回 -1 , 0 返回 0 , 正数返回 1
{
if (fabs(p) < eps) return ;
else return p < ? - : ;
} inline double Deg2Rad(const double & p) // 角度转弧度
{
return pi*p/180.0;
} inline double Rad2Deg(const double & p) // 弧度转角度
{
return p * 180.0 / pi;
} struct Point
{
long long x , y ;
Point (double x = . , double y = .)
{
this->x = x , this->y = y;
}
//***********重载函数*****************
friend Point operator + (const Point & T1, const Point & T2)
{
return Point(T1.x + T2.x , T1.y + T2.y);
}
friend Point operator - (const Point & T1, const Point & T2)
{
return Point(T1.x - T2.x , T1.y - T2.y);
}
friend Point operator * (const Point & T1 , const double p)
{
return Point(T1.x * p , T1.y * p);
}
friend Point operator * (const Point & T1 , const int p)
{
return Point(T1.x * p , T1.y * p);
}
friend bool operator == (const Point & T1 , const Point & T2) // 三态比较,精度较高
{
return dcmp(T1.x - T2.x) == && dcmp(T1.y - T2.y) == ;
}
friend ostream& operator << (ostream & os,const Point & x)
{
os << "x is " << x.x << " y is " << x.y;
return os;
}
//************************************
}; typedef Point Vector;
double Dot(const Vector & T1 , const Vector & T2)
{
return T1.x * T2.x + T1.y * T2.y;
} double Length(const Vector & T1)
{
return sqrt(Dot(T1,T1));
} double Angle(const Vector & T1 , const Vector & T2)
{
return acos(Dot(T1,T2)/ Length(T1) / Length(T2));
} double Cross(const Vector & T1, const Vector & T2)
{
return T1.x * T2.y - T2.x * T1.y;
} double Area2(const Point & T1 , const Point & T2, const Point & T3)
{
return Cross(T3-T1,T2-T1);
} // 将T1向量绕着起点逆时针旋转 rad 弧度
Vector Rotate(const Vector & T1 , const double rad)
{
return Vector(T1.x*cos(rad) - T1.y * sin(rad) , T1.x*sin(rad) + T1.y*cos(rad));
} // 返回向量T1的单位向量,调用时确保向量长度不为 0
Vector Normal(const Vector & T1)
{
double L = Length(T1);
return Vector(T1.x/L,T1.y/L);
} bool cmp1(const Point & a,const Point & b)
{
return a.x < b.x || (dcmp(a.x-b.x) == && a.y < b.y);
} //按照极角排序
bool cmp2(const Point & a,const Point & b)
{
double t1 = atan2(a.y,a.x);
double t2 = atan2(b.y,b.x);
if (t1 < ) t1 += 360.0;
if (t2 < ) t2 += 360.0;
return t1 < t2;
} // 点 A 到 点 u 和点 v 组成的直线的距离
double DistanceToLine(const Point & A , const Point & u , const Point &v)
{
Vector v1(A-u) , v2(v-u);
return fabs(Cross(v1,v2)) / Length(v2);
} double DistanceToSegment(const Point & A,const Point & u,const Point & v)
{
if (u == v) return Length(A-u);
Vector v1 = v - u , v2 = A - u , v3 = A - v;
if (dcmp(Dot(v1,v2)) < ) return Length(v2);
else if(dcmp(Dot(v1,v3)) > ) return Length(v3);
else return fabs(Cross(v1,v2)) / Length(v1);
} // 求两直线交点 , Line A上一点a , 向量 va , Line B上一点 b ,向量vb
Point GetLineIntersection(const Point & a , const Vector & va, const Point & b , const Vector & vb)
{
Vector u = a-b;
double t = Cross(vb, u) / Cross(va, vb);
return a+va*t;
} // 规范相交判断
bool SegmentProperIntersection(const Point & a1,const Point & a2,const Point & b1,const Point & b2)
{
double c1 = Cross(b2-b1,a1-b1) , c2 = Cross(b2-b1,a2-b1) , c3 = Cross(a2-a1,b1-a1) , c4 = Cross(a2-a1,b2-a1);
return dcmp(c1) * dcmp(c2) < && dcmp(c3) * dcmp(c4) < ;
} // 判断点p是否在 a1 和 a2构成的线段上( 不包括端点 )
bool IsPointOnSegment(const Point & p,const Point & a1 , const Point & a2)
{
return dcmp(Cross(a1-p,a2-p)) == && Dot(a1-p,a2-p) < ;
} // Pay attention !!!
// 下面的多边形函数带入的多边形点集必须全部为多边形上的点 , 且 必须已经按照极坐标排序(逆时针) // 返回凸包的面积,p 必须全部是凸包上的点
double ConvexPolygonArea(Point * Polygon , int n)
{
double area = ;
for(int i = ; i < n - ; ++ i) area += Cross(Polygon[i]-Polygon[],Polygon[i+]-Polygon[]);
return area / 2.0;
} // 复杂度 O(n)
// 点在多边形内的判断
int PointInPolygon(const Point & p,const Point * Polygon,const int n)
{
int wn = ;
for(int i = ; i < n ; ++ i)
{
int t1 = i;
int t2 = (i+) >= n ? i+-n : i+;
if (IsPointOnSegment(p,Polygon[t1],Polygon[t2])) return -; // 点在多边形边界上
int k = dcmp(Cross(Polygon[t2] - Polygon[t1],p - Polygon[t1]));
int d1 = dcmp(Polygon[t1].y - p.y);
int d2 = dcmp(Polygon[t2].y - Polygon[t1].y);
if (k > && d1 <= && d2 > ) wn ++;
if (k < && d2 <= && d1 > ) wn --;
}
if (wn != ) return ; //在多边形内部
return ; // 外部
} //********************************************************************************************** // 计算凸包
// 输入的p数组不允许有重复点
// 如果不希望在凸包的边上有输入点,把两个<= 该成 <
// 精度要求较高时用dcmp
int ConvexHull(Point * p , int n , Point * ch)
{
sort(p,p+n,cmp1);
int m = ;
for(int i = ; i < n ; ++ i)
{
while(m > && Cross(ch[m-] - ch[m-] , p[i] - ch[m-]) <= ) m --;
ch[m++] = p[i];
}
int k = m;
for(int i = n - ; i >= ; -- i)
{
while(m > k && Cross(ch[m-] - ch[m-] , p[i] - ch[m-]) <= ) m --;
ch[m++] = p[i];
}
if (n > ) m--;
return m;
} const int maxn = 2e2 + ;
int n , k ,cot;
Point p[maxn];
long long pos[maxn]; int main(int argc,char *argv[])
{
double ans = 1e200;
scanf("%d%d",&n,&k);
if (n == )
{
printf("0\n");
return ;
}
for(int i = ; i < n ; ++ i) scanf("%I64d%I64d",&p[i].x,&p[i].y);
for(int i = ; i < n ; ++ i)
for(int j = ; j < n ; ++ j)
{
// if (i == j) continue;
long long dx = p[j].y - p[i].y;
long long dy = p[i].x - p[j].x;
long long c = dx * p[i].x + dy * p[i].y;
int cur = ;
for(int kk = ; kk < n ; ++ kk)
{
long long d = dx * p[kk].x + dy*p[kk].y;
if (d - c >= )
{
pos[cur++] = d-c;
}
}
if (cur >= k)
{
sort(pos,pos+cur);
ans = min(ans , (double)pos[k-] / sqrt(dx*dx + dy*dy));
}
}
if (dcmp(ans-1.00) <= ) ans = 0.0;
else ans -= 1.00;
printf("%.10lf\n",ans);
return ;
}
URAL 1775 B - Space Bowling 计算几何的更多相关文章
- POJ 2031 Building a Space Station (计算几何+最小生成树)
题目: Description You are a member of the space station engineering team, and are assigned a task in t ...
- URAL 2078~2089
URAL 2078~2089 A - Bowling game 题目描述:给出保龄球每一局击倒的球数,按照保龄球的规则,算出总得分的最小值和最大值. solution 首先是最小值:每一局第一球击倒\ ...
- URAL 2099 Space Invader题解 (计算几何)
啥也不说了,直接看图吧…… 代码如下: #include<stdio.h> #include<iostream> #include<math.h> using na ...
- ural 1075. Thread in a Space
1075. Thread in a Space Time limit: 1.0 secondMemory limit: 64 MB There are three points in a 3-dime ...
- Ural 2036. Intersect Until You're Sick of It 计算几何
2036. Intersect Until You're Sick of It 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2036 ...
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2876 Accepted: 1839 Descrip ...
- URAL 2078 Bowling game
题目: Bowling game In all asocial teams members ignore each other uniformly, each tight-knit team buil ...
- Ural 1046 Geometrical Dreams(解方程+计算几何)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1046 参考博客:http://hi.baidu.com/cloudygoose/item ...
- POJ - 2031 Building a Space Station(计算几何+最小生成树)
http://poj.org/problem?id=2031 题意 给出三维坐标系下的n个球体,求把它们联通的最小代价. 分析 最小生成树加上一点计算几何.建图,若两球体原本有接触,则边权为0:否则边 ...
随机推荐
- executeQuery,executeUpdate 和 execute 区别
http://www.360doc.com/content/14/0315/09/16068204_360719186.shtml http://i-feng.iteye.com/blog/17066 ...
- ajax-Ajax试题
ylbtech-doc:ajax-Ajax试题 Ajax 1.A,Ajax试题返回顶部 001.{Ajax题目}使用Ajax可带来便捷有()(选择3项) A)减轻服务器的负担 B) ...
- android 触摸事件、点击事件的区别
针对屏幕上的一个View控件,Android如何区分应当触发onTouchEvent,还是onClick,亦或是onLongClick事件? 在Android中,一次用户操作可以被不同的View按次序 ...
- [转]LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 原文地址:http://yacare.iteye.com/blog/2010049 很多伙伴在更新VS ...
- Procdure for wanfo business report
CREATE OR REPLACE PROCEDURE PROC_TZ_EXEC_N_YEARREPORT(ssrq varchar2 ) as -----声明变量 v_raise EXCEPTION ...
- 在word中显示漂亮的代码
在word中粘贴或写代码时,通常得不到想要的格式,可用‘Notepad++’工具实现. 步骤: (1)安装Notepad++软件,把代码粘贴进去,选择菜单栏中的语言,然后选择相应代码语言,如P-> ...
- qt 在指定区域添加图片
博客出处:http://www.devdiv.com/thread-39111-1-1.html 折腾了几天,终于实现了图片的淡出淡入的效果. 其实也应该是说实现了图片的淡入效果,因为淡出效果我暂时还 ...
- linux交叉环境的搭建以及嵌入式开发概述
嵌入式开发概述 由嵌入式本身的特性所影响,嵌入式系统开发与通用系统的开发有很大的区别,嵌入式的开发分为系统总体开发,嵌入式硬件开发,嵌入式系统软件开发3大部分 在系统总体开发中,由于嵌入式系统与硬件依 ...
- Java内部类this$0字段产生的一个bug
首先查看下面一段代码,我指出了问题代码的所在,读者先自己思考一下这段代码会有什么问题. 这是用clone方法完整拷贝一个二项堆(BinomialHeap)结构的代码.二项堆中包含一个内部类Binomi ...
- codeforce 702C Cellular Network 二分答案
http://codeforces.com/contest/702 题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄 思路:直接二分答案 二分太弱,调了半天..... // #pragma co ...