zoukankan      html  css  js  c++  java
  • SLG, 菱形格子的算法.(递归版

    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);
    }
    
    
    
    

    记得好久曾经看过一个日本人写的算法..很赞..可是曾经看不懂,,只是记得很清楚..就是效率很的快.

    并且边扩张边保存自带中心点到目的点的路径....

    = =今晚试下能不能模仿一个...

    先写一个最主要的算法



  • 相关阅读:
    Commander Nodejs 命令行接口
    数据库集群 ---续集
    数据库集群
    实时查看linux下的日志
    自动化测试
    python中list和dict
    super与this的用法
    数据类型
    父类调用子类方法
    子类调用父类方法
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7246906.html
Copyright © 2011-2022 走看看