2017中兴算法挑战赛(迪杰斯特拉)

和刚刚结束的2017华为软件精英挑战赛相比,中兴的题目不难,花了两天时间随便搞了一下(其实也没多长时间,因为是周末,还打了农药偷笑),没什么意思,结果刚刚揭晓,58分,评价是“算法尚可,代码一般”,GG,写的太水,大佬莫笑~

赛题:

最强大脑中的收官蜂巢迷宫变态级挑战,相信大家都叹为观止!最强大脑收官战打响后,收视率节节攀升,就连蚁后也不时出题难为一下她的子民们。在动物世界中,称得上活地图的,除了蜜蜂,蚂蚁当仁不让。在复杂多变的蚁巢中, 蚂蚁总是能以最快、最高效的方式游历在各个储藏间(存储食物)。今天,她看完最新一期节目,又发布了一项新任务:小蚁同学,我需要玉米库的玉米,再要配点水果,去帮我找来吧。小蚁正准备出发,蚁后又说:哎呀,回来,我还没说完呢,还有若干要求如下:

1.小蚁同学,你需要尽可能以最少的花费拿到食物(附件图中路线上的数值表示每两个储物间的花费);

2.小蚁同学,你最多只能经过9个储藏间拿到食物(包含起止两个节点,多次通过同一节点按重复次数计算);

3.小蚁同学,你必须经过玉米间,水果间(附件图中标绿色节点);

4.别忘了,食蚁兽也在路上活动呢,一旦与食蚁兽相遇,性命危矣!不过小蚁微信群公告已经公布了敌人信息(附件图中标红色路段);

5.最后,千万别忘了,还有两段路是必须经过的,那里有我准备的神秘礼物等着你呢(附件图中标绿色路段)。

这下小蚁犯难了,这和它们平时找食物的集体活动规则不一样嘛,看来这次需要单独行动了。要怎么选路呢?小蚁经过一番苦思冥想,稿纸堆了一摞,啊,终于找到了!亲爱的同学们,你们能否也设计一种通用的路径搜索算法,来应对各种搜索限制条件,找到一条最优路径,顺利完成蚁后布置的任务呢?


注:

1、蚁巢,有若干个储藏间(附件图中圆圈表示),储藏间之间有诸多路可以到达(各储藏间拓扑图见附件);

2、节点本身通行无花费;

3、该图为无向图,可以正反两方向通行,两方向都会计费,并且花费相同;

4、起止节点分别为附件图中S点和E点。

5、最优路径:即满足限制条件的路径。


算法思路:

贪心算法求解初始解+分段求解最短路+模拟退火算法逐步寻优(实践证明,对于这个对这个问题,贪心算法求出的初始解基本接近最优解,所以说这个比赛很水啦。。。。)


源代码:

/************************************************************
 *
 * Shortest Path Search for ZTE Fantastic Algorithm
 * Author:      chyeer
 * Datetime:    2017-05-02
 * Description: multiple constrainted shortest path search
 *              based on Shortested Path Faster Algorithm and
 *              Simulated Anneling Algorithm
 *
************************************************************/

#ifndef ZTE_H
#define ZTE_H

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
            
              #include 
             
               #include 
              
                #include 
               
                 #include 
                
                  using namespace std; namespace pan{ const int maxn = 1001; const int INF = 1<<10; const int MAX_LINE_LEN = 50000; struct edge //edge { int to; int cost; }; struct node { int from; int to; }; extern vector 
                 
                   myV[maxn]; // adjacecy list used for topo structure of graph extern vector 
                  
                    constraints; // storage for multiple constraints extern vector 
                   
                     group; // storage for combination of multiple constraints extern vector 
                    
                      path; // storage for shortest path extern int numNode, numEdge; // vertexes, edges extern int minPath[maxn]; // shortest path extern int source[maxn]; // source[a]=b, the node before a is b extern int start, End; // srouce node, sink node extern int S, E; // Source Node: S, End Node: E extern bool inQ[maxn]; // in queue or not extern int wholeDis; // storage of the miniCost for the shortest path extern int distance; // distance between two nodes extern vector 
                     
                       mustPassedNode; // Node set that must be passed extern vector 
                       
                       
                         > forbidPassedEdge; // Edge set that can not be passed extern vector 
                         
                         
                           > mustPassedEdge; // Edge set that must be passed void LoadDataFromFile(const char* filename); // load basic graph data void loadConstraints(); // used for adding constraints void inputItial(); // input data from screen void output(int start, int end); // compute shortest path void SPFA(int start, int end); // shortest path faster algorithm void greedyAlgorithmForFindingInitialSolution(vector 
                          
      
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值