• hdu2722 简单最短路,处理好输入就行


    题意:
          从左上角走到右下角,有的最短时间,每段路径的长度都是2520,每段上都有自己的限制速度,方向。
    思路:
         直接写就行了,就是个最短路,权值是2520/限制,输入的时候细心点就行了。


    #include<stdio.h>
    #include<string.h>
    #include<queue>
    
    #define N_node 500 + 50
    #define N_edge 2000 + 200
    #define INF 1000000000
    
    using namespace std;
    
    typedef struct
    {
       int to ,next ,cost;
    }STAR;
    
    STAR E[N_edge];
    int list[N_node] ,tot;
    int s_x[N_node] ,mark[N_node];
    
    void add(int a ,int b ,int c)
    {
       E[++tot].to = b;
       E[tot].cost = c;
       E[tot].next = list[a];
       list[a] = tot;
    }
    
    void Spfa(int s ,int n)
    {
       for(int i = 0 ;i <= n ;i ++)
       s_x[i] = INF ,mark[i] = 0;
       s_x[s] = 0;
       mark[s] = 1;
       queue<int>q;
       q.push(s);
       while(!q.empty())
       {
          int xin ,tou;
          tou = q.front();
          q.pop();
          mark[tou] = 0;
          for(int k = list[tou] ;k ;k = E[k].next)
          {
             xin = E[k].to;
             if(s_x[xin] > s_x[tou] + E[k].cost)
             {
                s_x[xin] = s_x[tou] + E[k].cost;
                if(!mark[xin])
                {
                   mark[xin] = 1;
                   q.push(xin);
                }
             }
          }
       }
       return ;
    } 
    
    int main ()
    {
       int i ,j ,n ,m ,num;
       char str[10];
       while(~scanf("%d %d" ,&n ,&m) && n + m)
       {
          int mm = m + 1 ,nn = n + 1;
          memset(list ,0 ,sizeof(list)) ,tot = 1;
          for(i = 1 ;i <= nn ;i ++)
          {
             for(j = 1 ;j <= m ;j ++)
             {
                int now = (i - 1) * mm + j;
                scanf("%d %s" ,&num ,str);
                if(!num) continue;
                num = 2520 / num;
                if(str[0] == '*') add(now ,now + 1 ,num) ,add(now + 1 ,now ,num);
                if(str[0] == '>') add(now ,now + 1 ,num);
                if(str[0] == '<') add(now + 1 ,now ,num);
             }
             if(i <= n)
             for(j = 1 ;j <= mm ;j ++)
             {
                scanf("%d %s" ,&num ,str);
                int now = (i - 1) * mm + j;
                if(!num) continue;
                num = 2520 / num;
                if(str[0] == '*') add(now ,now + mm ,num) ,add(now + mm ,now ,num);
                if(str[0] == '^') add(now + mm ,now ,num);
                if(str[0] == 'v') add(now ,now + mm ,num);
             }
          }
          Spfa(1 ,nn * mm);
          if(s_x[nn * mm] == INF) printf("Holiday
    ");
          else printf("%d blips
    " ,s_x[nn * mm]);
       }
       return 0;
    }
    


  • 相关阅读:
    Jfinal附件上传与重命名
    JFinal-BBS
    jFinal怎样连接sqlserver?
    关于jmeter响应结果用html查看乱码
    jmeter启动报错Error occurred during initialization of VM Could not reserve enough space for object heap errorlevel=1的解决方法
    Genymotion创建下载模拟器的时候出现Unable to create Genymotion virtual devices:Connection timeout错误
    Selenium IDE和Selenium RC的安装
    python+eclipse环境搭建
    第一个jemter测试脚本
    ulipad源码包配置环境及安装
  • 原文地址:https://www.cnblogs.com/csnd/p/12063035.html
Copyright © 2020-2023  润新知