当前位置:
首页 >
uva 10245 The Closest Pair Problem_枚举
发布时间:2023/12/9
67
豆豆
生活随笔
收集整理的这篇文章主要介绍了
uva 10245 The Closest Pair Problem_枚举
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题意:求任意两点之间的距离的最少一个距离
思路:枚举一下就可以了
#include <iostream> #include<cstdio> #include<cmath> using namespace std; #define N 10010 struct node{double x,y; }p[N]; int main(int argc, char** argv) {int n,i,j;double mdist,tmp;while(scanf("%d",&n)&&n){for(i=0;i<n;i++){scanf("%lf%lf",&p[i].x,&p[i].y);}mdist=0xfffffff;for(i=0;i<n;i++){for(j=i+1;j<n;j++){tmp=(p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y);mdist=min(mdist,tmp);}}mdist=sqrt(mdist);if(mdist>=10000)printf("INFINITY\n");elseprintf("%.4lf\n",mdist);}return 0; }转载于:https://www.cnblogs.com/neng18/p/3676409.html
总结
以上是生活随笔为你收集整理的uva 10245 The Closest Pair Problem_枚举的全部内容,希望文章能够帮你解决所遇到的问题。