24小时热门版块排行榜    

查看: 2137  |  回复: 7
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

nenyan

铜虫 (初入文坛)


[交流] 【求助】求算法,两点间距离问题

求算法:
平面上有很多点,每个点的坐标x,y已知。求相邻两点距离最大的值。
点大概如下分布

。 。 。 。 。 。。。  
。 。。 。。 。 。 。。  
。 。 。 。 。 。 。 。 。
。 。。 。。。 。 。。。
上下也算相邻,左右也算相邻。不是求所有这些点中距离最大的那两点,而是相邻的这么多距离最大的那个距离。
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

» 抢金币啦!回帖就可以得到:

查看全部散金贴

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

smart0193

木虫 (小有名气)


★ ★ ★
余泽成(金币+3):谢谢参与应助!欢迎常来程序语言版! 2010-12-07 16:23:38
nenyan(金币+10):xiexie le 2010-12-14 11:38:05
#include
#include
#define ROWS 2
#define COLS 2
typedef struct
{
        double x;
        double y;
}POINT;

void main()
{
        POINT coords[ROWS][COLS];
        int i,j;
        double dis,max=0;

        for(i=0;i                 for (j=0;j                         cin>>coords[j].x>>coords[j].y;
       
        for(i=0;i                 for(j=0;j                 {
                        if (j                         {
                                dis=sqrt((coords[j].x-coords[j+1].x)*(coords[j].x-coords[j+1].x)+(coords[j].y-coords[j+1].y)*(coords[j].y-coords[j+1].y));
                                if (dis>max)
                                        max=dis;
                        }
                        if (i                         {
                                dis=sqrt((coords[j].x-coords[i+1][j].x)*(coords[j].x-coords[i+1][j].x)+(coords[j].y-coords[i+1][j].y)*(coords[j].y-coords[i+1][j].y));
                                if (dis>max)
                                        max=dis;
                        }
                }
        cout<<"the maximum distance is "< }
2楼2010-12-07 09:34:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

smart0193

木虫 (小有名气)



小木虫(金币+0.5):给个红包,谢谢回帖交流
遗传算法可能得到的是近似最优解。其实这个问题还有很多方法,关键是算法设计,呵呵。
6楼2010-12-14 20:35:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 nenyan 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见