直接贴代码,我自己都觉得有点丑陋,,
我建了点的类,把点放到一个数组里来表示图,剩下的就按照老师给的代码写
另,求教,我的迭代函数的参数太多了,每次使用数组的时候都要分别传数组地址和下标,有什么优化方法吗
#include <iostream>
using namespace std;
//怎么样不用邻接矩阵和邻接表表示一个图
class Point {
public:
Point() :x(0),y(0) {};
bool first_jump(int step) {
if ((step + 7.5) * (step + 7.5) >= (x * x + y * y)) return true;
else return false;
}
bool then_jump(Point p2, int step) {
if ((step* step) >= ((p2.x - x) * (p2.x - x) + (p2.y - y) * (p2.y - y))) return true;
else return false;
}
bool is_safe(int step) {
if ((50 - abs(x) <= step) || (50 - abs(y) <= step)) return true;
else return false;
}
Point* Creat_arr(int num) {
Point* arr_p = new Point[num];
for (int i = 0; i < num; i++) {
cin >> arr_p[i].x >> arr_p[i].y;
}
return arr_p;
}
public:
int x;
int y;
};
int DFS007(Point* arr_