class GeoPoint{ public: int x; int y; public: bool operator == (const GeoPoint& p){ return p.x == this->x && p.y == this->y; } GeoPoint(int x, int y):x(x), y(y){ } }; void findGrids(int x, int y, int limit, std::vector<GeoPoint>& list){ if(limit <= 0){ return; } if(std::find(list.begin(), list.end(), GeoPoint(x, y)) == list.end()){ list.push_back(GeoPoint(x, y)); } findGrids(x, y + 1, limit - 1, list); findGrids(x, y - 1, limit - 1, list); findGrids(x - 1, y, limit - 1, list); findGrids(x + 1, y, limit - 1, list); } void main(){ std::vector<GeoPoint> rangeList; int x = 3; int y = 2; int r = 3; findGrids(x, y, r, rangeList); }
记得好久曾经看过一个日本人写的算法..很赞..可是曾经看不懂,,只是记得很清楚..就是效率很的快.
并且边扩张边保存自带中心点到目的点的路径....
= =今晚试下能不能模仿一个...
先写一个最主要的算法