hdu 1007
2013-11-29 00:00
134 查看
设计最小的套环半径,令x,y分别从小到大排序,如果前一个X或前一个Y加上当前半径要大于后一个x或y则可以肯定这个半径必能一下子套中两个。所以要计算新的半径。
code:
code:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include "iostream" struct Point { double x,y; }; Point p[100005]; int cmps(Point a,Point b) //x从小到大 { if(a.x<b.x) { return 1; }else if(a.x==b.x&&a.y<b.y) { return 1; }else return 0; } int cmps2(Point a,Point b) //y从小到大 { if(a.y<b.y) { return 1; }else if(a.y==b.y&&a.x<b.x) { return 1; }else return 0; } using namespace std; int main() { int n,i; double s,tmp; while(scanf("%d",&n)!=EOF&&n) { for(i=0;i<n;i++) { scanf("%lf%lf",&p[i].x,&p[i].y); if(p[i].x>0&&p[i].y<0) { p[i].x*=-1; //第四像限的全弄到第三像限来 } } // qsort(p,n,sizeof(Point),cmp1); sort(p,p+n,cmps); for(i=1,s=111111111;i<n;i++) { if(p[i-1].x+s>p[i].x){ tmp=sqrt(pow(p[i].x-p[i-1].x,2)+pow(p[i].y-p[i-1].y,2))/2; if(s>tmp) { s=tmp; } } } //qsort(p,n,sizeof(Point),cmp1); sort(p,p+n,cmps2); for(i=1;i<n;i++) { if(p[i-1].y+s>p[i].y){ tmp=sqrt(pow(p[i].x-p[i-1].x,2)+pow(p[i].y-p[i-1].y,2))/2; if(s>tmp) { s=tmp; }} } printf("%.2lf\n",s); } return 0; }
相关文章推荐
- hdu 3177 差排
- myeclipse 在做项目复制时应该注意的问题
- Ubuntu终端命令
- SUSE11修改主机名方法
- MySQL slave状态之Seconds_Behind_Master
- Oracle如何根据SQL_TEXT生成SQL_ID
- 当前Javaweb应用中应用比较多的技术有些什么
- 使用NuGet安装redis
- OpenCart之选项(Option)教程
- 2013-11-29学习笔记(su)
- 2013-11-29学习(crontab)
- Optimistic vs Multi Version Concurrency Control - Differences?
- maven-dependency-plugin (goals "copy-dependencies","unpack") is not supported by m2e
- 代码核查工具ReviewBoard安装
- java的substring()方法在JDK 6和JDK 7中的运作机制
- Note: Balance of 2193 indicates you should push this ring, wait at least 1 hour, and rebalance/re...
- Android中定义接口的用法
- UVA10405最长公共子序列(递推和递归两种解法)
- apk的反编译
- 性能测试常见问题