uva 10245 The Closest Pair Problem_枚举
生活随笔
收集整理的這篇文章主要介紹了
uva 10245 The Closest Pair Problem_枚举
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題意:求任意兩點(diǎn)之間的距離的最少一個(gè)距離
思路:枚舉一下就可以了
#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; }轉(zhuǎn)載于:https://www.cnblogs.com/neng18/p/3676409.html
總結(jié)
以上是生活随笔為你收集整理的uva 10245 The Closest Pair Problem_枚举的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。