布线问题--队列式分支界限法

#include <iostream>
#include <queue>
#include <algorithm>
#include <utility>
#include <stack>
using namespace std;

typedef pair<int, int> posi;
queue<posi> q;
const int n = 100;
int graph[n+2][n+2] = {0};
posi start;
posi end;
int best_path = 0;
void initParament()
{

}

void findPath()
{
        if(start.first == end.first && start.second==end.second){
                return;
        }

        for(int i=0; i<=n; i++){
                graph[0][i] = 1;
                graph[n+1][i] = 1;
                graph[i][0] = 1;
                graph[i][n+1] = 1;
        }

        posi offset[5];
        offset[1].first = 1; offset[1].second = 0;
        offset[2].first = 0; offset[1].second = -1;
        offset[1].first = -1; offset[1].second = 0;
        offset[1].first = 0; offset[1].second = 1;

        posi current = start;
        graph[current.first][current.second] = 2;
        while( true ){
                posi here;
                for(int i=1; i<=4; i++){
                        here.first = current.first+offset[i].first;
                        here.second = current.second+offset[i].second;

                        if(graph[here.first][here.second] == 0){
                                q.push(here);
                                graph[here.first][here.second] = graph[current.first][current.second] + 1;

                                if(here.first == end.first && here.second == end.second){
                                        best_path = graph[here.first][here.second];
                                        break;
                                }
                        }
                }

                if(here.first==end.first && here.second==end.second){
                        break;
                }

                if( q.empty() ){
                        break;
                }

                current = q.front();
                q.pop();
        }

        stack<posi> path;
        path.push(end);
        current = end;
        for(int i=best_path; i>2; i--){
                posi here;
                for(int j=1; j<=4; j++){
                        here.first = end.first+offset[j].first;
                        here.second = end.second+offset[j].second;

                        if(graph[here.first][here.second] == i-1){
                                path.push(here);
                                break;
                        }
                }
                current = here;
        }
        path.push(start);

        while( !path.empty() ){
                current = path.top();
                cout << current.first << "," << current.second << endl;
                path.pop();
        }
}

int main()
{
        initParament();

        findPath();

        return 0;
}

【6层】一字型框架办公楼(含建筑结构图、计算书) 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值