没有合适的资源?快使用搜索试试~ 我知道了~
最近对问题,分治法与蛮力法
5星 · 超过95%的资源 需积分: 10 31 下载量 49 浏览量
2011-10-24
17:13:00
上传
评论
收藏 3KB TXT 举报
温馨提示
试读
6页
这个是根据算法分析与设计写出来的用分治法和蛮力法求解最近对问题的代码,可以直接运行。手动输入产生点的个数,输出蛮力和分治的时间。嗯,分治法我没有给出最近对的参数,有兴趣的可以自己试着写写。
资源推荐
资源详情
资源评论
#define LENGTH 10000
#define min(X,Y) ((X)<(Y)?(X):(Y))
#include <FLOAT.H>
#include <WINDOWS.H>
#include <TIME.H>
#include <MATH.H>
#include <algorithm>
#include <IOSTREAM>
using namespace std;
struct point{
double x;
double y;
};
point points[LENGTH*2];
// point tempLeft[LENGTH];
// point tempRight[LENGTH];
//排序
int cmpy(point a,point b)
{
return a.y<b.y;
}
int cmpp(point a,point b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
#define min(X,Y) ((X)<(Y)?(X):(Y))
#include <FLOAT.H>
#include <WINDOWS.H>
#include <TIME.H>
#include <MATH.H>
#include <algorithm>
#include <IOSTREAM>
using namespace std;
struct point{
double x;
double y;
};
point points[LENGTH*2];
// point tempLeft[LENGTH];
// point tempRight[LENGTH];
//排序
int cmpy(point a,point b)
{
return a.y<b.y;
}
int cmpp(point a,point b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
//求距离的平方
double Distence(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
//蛮力法函数
double ClosestPoints(int n,point p[],int &index1,int &index2)
{
double minDist=DBL_MAX;
double temp;
for (int i=0;i<n;i++)
for (int j=i+1;j<=n;j++)
{
temp=Distence(p[i],p[j]);
if(temp<minDist)
{
minDist=temp;
index1=i;
index2=j;
}
}
return sqrt(minDist);
}
//分治法函数
double DivPoints(point p[],int begin,int end)
剩余5页未读,继续阅读
资源评论
- shenwenwen212011-12-09代码可以正确运行,对我很有帮助。
- Lueyin_v2014-04-06适合初学者学习
- liulitianji2015-11-23好用,课程设计帮大忙了
葡萄棍
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功