[uva] 10136 Chocolate Chip Cookies
来源:互联网 发布:视频爬虫 python 编辑:程序博客网 时间:2024/05/19 12:23
[uva] 10136 Chocolate Chip Cookies
【题目】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=1077&mosmsg=Submission+received+with+ID+10618954
【题意】求一个饼干最多巧克力
【算法】简单几何+枚举
【题解】根据两个点恰在圆上枚举出可能的圆心,再遍历每个圆心,求其圆内有多少个巧克力。
【注意】注意输入和输出,都有空行- -
求圆心可以先求直线的法向量,然后标准化后,乘以长度,再加上线段中心就是圆心坐标了。
【测试】
10
4.0 4.0
4.0 5.0
1.0 20.0
1.0 21.0
1.0 22.0
1.0 25.0
1.0 26.0
1.0 1.0
1.0 0
0.0 1.0
ans:
4
1
2
【代码】
#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;struct point{ double x,y;}a[500],c[250000];char ch[100];double di(point x1,point x2){ return sqrt((x1.x-x2.x)*(x1.x-x2.x)+(x1.y-x2.y)*(x1.y-x2.y));}int main(){ int T,n,s,max=0,k,i,j; double t,x,y,z; double pi = 4*atan(1.0); scanf("%d",&T); getchar(); getchar(); while(T-->0){ if(max!=0)putchar('\n'); for(n=0;gets(ch)&&ch[0]!='\0';n++)sscanf(ch,"%lf%lf",&a[n].x,&a[n].y); if(n==0) { printf("0\n"); continue; } k=0; for(i=1;i<n;i++) for(j=0;j<i;j++){ t=di(a[i],a[j]); if(t<=5){ t = sqrt(6.25-t*t/4.0); //printf("%.2f\n",t); x=a[j].y-a[i].y; y=a[i].x-a[j].x; z=sqrt(x*x+y*y); x=x/z*t; //标准法向量 y=y/z*t; c[k].x=(a[i].x+a[j].x)/2.0+x; c[k++].y=(a[i].y+a[j].y)/2.0+y; c[k].x=(a[i].x+a[j].x)/2.0-x; c[k++].y=(a[i].y+a[j].y)/2.0-y; //printf("%d %d %.2f %.2f %.2f %.2f\n",i,j,c[k-2].x,c[k-2].y,c[k-1].x,c[k-1].y); } } max=1; for(i=0;i<k;i++){ s=0; for(j=0;j<n;j++){ //printf("%f\n",di(c[i],a[j])); if(di(c[i],a[j])<=2.5)s++; } if(s>max)max=s; } printf("%d\n",max); } return 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
- oracle中exp,imp的使用详解
- 小白对Ubuntu 12.04 LTS和windows 7的看法
- (转)一些软件设计的原则
- 为程序员量身定制的12个目标
- java反射
- [uva] 10136 Chocolate Chip Cookies
- 路上看水
- 客户端和服务器后退操作防止表单重复提交
- 如何修改Struts2 FiledError样式
- 程序运行时间
- 阿里面试总结
- CMake编译OGRE source code时Boost的一些问题解决方法
- Android调用WebService
- IE smartdraw 等软件打开时Visual Studio 实时调试器的关闭方法