URAL 1775 Space Bowling
来源:互联网 发布:现货看盘软件 编辑:程序博客网 时间:2024/05/18 03:06
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1775
详细题解:很好的一道计算几何题目,考的就是想法,想到了就很简单了……
先算出每两个圆心间的距离,dis[i][j]表示第i和第j个圆心的距离
然后再以每条线段ij为边,求出以这样的线段为直线的左右两边的点的个数cnt和距离len[cnt],直线上的点要同时属于两边。 然后就可以排下len数组的序,ans = min(ans, len[m]);就ok了; 还有就是注意一下ans可能会小于0的情况。
G++不能用%lf真是个深坑……
#include<cstdio>#include<cmath>#include<climits>#include<iostream>#include<algorithm>using namespace std;#define N 210#define eps 1e-10double dis[N][N];struct Point{double x, y;Point(double x = 0, double y = 0) : x(x), y(y) {}};Point p[N];typedef Point Vector;Vector operator - (Point A, Point B) {return Vector(A.x-B.x, A.y-B.y);}double Dot(Vector A, Vector B){return A.x*B.x + A.y*B.y;}double Length(Vector A){return sqrt(Dot(A, A));}double Cross(Vector A, Vector B){return A.x*B.y - A.y*B.x;}int dcmp(double x){if(fabs(x) < eps) return 0;else return x < 0 ? -1 : 1;}int main (){ int n, m; while(scanf("%d %d", &n, &m) != EOF) { for(int i = 1; i <= n; i++) scanf("%lf %lf", &p[i].x, &p[i].y); if(m <= 2) { printf("0.000000\n"); continue;} for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dis[i][j] = Length(p[i] - p[j]); double ans = INT_MAX; for(int i = 1; i <= n; i++) for(int j = i+1; j <= n; j++) { double len_l[N], len_r[N]; int cnt_l = 0, cnt_r = 0; for(int k = 1; k <= n; k++) { double tmp = Cross(p[j]-p[i], p[k]-p[i]); int ha = dcmp(tmp); if(ha == 0) { cnt_l++;cnt_r++; len_l[cnt_l] = len_r[cnt_r] = 0; } else if(ha > 0) { cnt_l++; len_l[cnt_l] = fabs(tmp) / dis[i][j]; } else{ cnt_r++; len_r[cnt_r] = fabs(tmp)/ dis[i][j]; } } sort(len_l+1, len_l+cnt_l+1); sort(len_r+1, len_r+cnt_r+1); if(cnt_l >= m) ans = min(ans, len_l[m]); if(cnt_r >= m) ans = min(ans, len_r[m]); } ans--; if(ans <= 0) ans = 0; printf("%.10f\n", ans); } return 0;}
0 0
- URAL 1775 Space Bowling
- Space Bowling
- URAL 1901 Space Elevators(贪心)
- Bowling
- 『HTML5 canvas』HTML5练习之space bowling
- URAL 1075. Thread in a Space
- URAL 1901 Space Elevators (苦逼水题,2级)
- URAL 2099 Space Invader 计算几何、卡精度、好题
- Bowling Scores
- Cow Bowling
- poj3176cow bowling
- Cow Bowling
- Cow Bowling
- Cow Bowling
- Cow Bowling
- poj3176Cow Bowling
- Cow Bowling
- URAL
- MFC基本控件使用——列表控件(ListCtrl)
- POJ 2420 模拟退火法
- HTML中this与JQuery中$(this)的区别
- 刚整理的SQL常见替代点
- hdu4662 简单搜索打表
- URAL 1775 Space Bowling
- 白盒测试设计方法
- 有用的网址
- 黑盒测试设计方法
- jni指针和堆栈注意
- 使用 Intel HAXM 为 Android 模拟器加速,媲美真机
- Andriod Fragment---给Activity添加一个Fragment
- TOJ 3533 - 黑白图像
- Android Scroller简单用法