UVa 10136 - Chocolate Chip Cookies
来源:互联网 发布:8051 单片机内部实现 编辑:程序博客网 时间:2024/05/19 14:56
题目:平面上有很多个点,画一个直径的5cm的圆,问这个圆最多能包含几个点。
分析:计算几何。一直半径和圆周上两点可以确定2个(或1个)圆,枚举圆周上的两端,统计即可。
时间复杂度为O(n^3),如果两点距离大于直径直接不用计算。
说明:第600题了╮(╯▽╰)╭。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef struct pnode{double x,y,r;}point;point P[202],cl,cr;double dist_p2p(point a, point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}//一直圆上两点和半径求圆心 void circle(point a, point b, double r, point &c1, point &c2){double dist_c2ab = sqrt(r*r-dist_p2p(a, b)*dist_p2p(a, b)/4);if (a.x == b.x) {c1.y = c2.y = (a.y+b.y)/2;c1.x = a.x + dist_c2ab;c2.x = a.x - dist_c2ab;}else {double k = atan((b.x-a.x)/(a.y-b.y));c1.x = (a.x+b.x)/2+dist_c2ab*cos(k);c1.y = (a.y+b.y)/2+dist_c2ab*sin(k);c2.x = (a.x+b.x)/2-dist_c2ab*cos(k);c2.y = (a.y+b.y)/2-dist_c2ab*sin(k);}}int main(){int n;char buf[100];scanf("%d",&n);getchar();getchar();while (n --) {int count = 0;while (gets(buf) && buf[0]) {sscanf(buf,"%lf%lf",&P[count].x,&P[count].y);count ++;}int max_count = 1;for (int i = 1; i < count; ++ i)for (int j = 0; j < i; ++ j)if (dist_p2p(P[i], P[j]) <= 5) {circle(P[i], P[j], 2.5, cl, cr);int l_count = 0,r_count = 0;for (int k = 0; k < count; ++ k) {if (dist_p2p(P[k], cl) <= 2.5)l_count ++;if (dist_p2p(P[k], cr) <= 2.5)r_count ++;}if (max_count < l_count)max_count = l_count;if (max_count < r_count)max_count = r_count;}printf("%d\n",max_count);if (n) printf("\n");} return 0;}
0 0
- [uva] 10136 Chocolate Chip Cookies
- UVa 10136 - Chocolate Chip Cookies
- UVa Problem 10136 Chocolate Chip Cookies (巧克力片饼干)
- poj 1981 Circle and Points poj 2693 Chocolate Chip Cookies
- UVa 10970 - Big Chocolate
- uva 10970 Big Chocolate
- UVA 10970 - Big Chocolate
- uva 10970 - Big Chocolate
- Uva-10970-Big Chocolate
- UVA 10970 Big Chocolate
- UVA 10970 Big Chocolate
- UVa 10970 - Big Chocolate
- UVA 10970 Big Chocolate
- uva 10970 Big Chocolate
- Uva - 10970 - Big Chocolate
- uva 10970 - Big Chocolate
- Uva-10648-Chocolate Box
- uva 10970 Big Chocolate
- android.view.InflateException....Error inflating class...
- php打印一些图形
- C语言—switch、while、do while、for、break和countinue
- CSU1552: Friends(快速判断大数是不是素数+二分匹配)
- Jquery实际应用,判断radio,selelct,checkbox是否选中及选中的值
- UVa 10136 - Chocolate Chip Cookies
- i2c设备与驱动匹配过程
- Linux GRUB 引导Win 7 ---- error: invalid EFI file path
- & 与 | ,变量,if else Switch case:
- $JAVA_HOME/bin下命令总结
- Shell脚本调试技术
- C语言—函数、include、多文件开发、进制和内存管理细节
- 内存泄漏以及常见的解决方法
- 堆排序