zoukankan      html  css  js  c++  java
  • 蓝桥杯---平面四点最小距离

    没什么意思


    已知平面上若干个点的坐标。

    需要求出在所有的组合中,4个点间平均距离的最小值(四舍五入,保留2位小数)。

    比如有4个点:a,b,c,d, 则平均距离是指:ab, ac, ad, bc, bd, cd 这6个距离的平均值。

    每个点的坐标表示为:横坐标,纵坐标

    坐标的取值范围是:1~1000

    例如,如果程序输入:
    10,10
    20,20
    80,50
    10,20
    20,10

    则程序应该输出:
    11.38

    但是因为空间的限制,最后一组数据始终没有过,所以只能呵呵了。。。

    #include <iostream>
    #include <stdio.h>
    #include <memory.h>
    #include <cmath>
    using namespace std;
    #define EN cout<<endl;
    #define  SP cout<<' ';
    struct T{
    int x,y;
    } point[1000];
    int main(){
    int count=0,xx,yy;
    double avr=-1;
    while(~scanf("%d,%d",&xx,&yy))
      point[count].x=xx,point[count++].y=yy;
    short int distan[1005][1005];
    for(int i=0;i<count-1;i++)
     for(int j=i+1;j<count;j++)
       distan[i][j]=distan[j][i]=sqrt(pow( (point[i].x-point[j].x),2 )  +  pow((point[i].y-point[j].y),2)  );
    for(int i=0;i<count-3;i++)
      for(int j=i+1;j<count-2;j++){
      	if(distan[i][j]>avr&&avr!=-1) continue;
      	for(int x=j+1;x<count-1;x++){
      		if( (distan[i][x]>avr||distan[j][x]>avr)&&avr!=-1) continue;
      		for(int y=x+1;y<count;y++){
      			if( (distan[i][y]>avr||distan[j][y]>avr||distan[x][y]>avr)&&avr!=-1 )continue;
    	        double temp = sqrt(pow( (point[i].x-point[j].x),2 )  +  pow((point[i].y-point[j].y),2)  );
    	        temp+=sqrt(pow( (point[i].x-point[x].x),2 )  +  pow((point[i].y-point[x].y),2)  );
    	        temp+=sqrt(pow( (point[i].x-point[y].x),2 )  +  pow((point[i].y-point[y].y),2)  );
    	        temp+=sqrt(pow( (point[j].x-point[x].x),2 )  +  pow((point[j].y-point[x].y),2)  );
    	        temp+=sqrt(pow( (point[j].x-point[y].x),2 )  +  pow((point[j].y-point[y].y),2)  );
    	        temp+=sqrt(pow( (point[x].x-point[y].x),2 )  +  pow((point[x].y-point[y].y),2)  );
    	        temp/=6;
    	        if(avr==-1||avr>temp) avr=temp;
    	      }
          }
      }   
        
      printf("%.2lf",avr);
    return 0;
    }
    


  • 相关阅读:
    hdoj 3599 最小费用最大流
    poj 2516 最小费用最大流
    poj 3281 最大流拆点
    poj 3436 网络最大流加打印路径
    邻接表模板
    hdu 2102 搜索
    hdoj 1533 最小费用最大流
    HDU 1231 最大连续子序列
    NYOJ 2 括号配对问题
    POJ 1163 / NYOJ 16 The Triangle(数字三角形)
  • 原文地址:https://www.cnblogs.com/zswbky/p/5431971.html
Copyright © 2011-2022 走看看