uva 10245 The Closest Pair Problem_枚举
生活随笔
收集整理的這篇文章主要介紹了
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_枚举的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: flot绘制折线图
- 下一篇: php扩展开发1--添加函数