• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

HDU 2722 Here We Go(relians) Again

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
Here We Go(relians) Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1080    Accepted Submission(s): 530


Problem Description
The Gorelians are a warlike race that travel the universe conquering new worlds as a form of recreation. Given their violent, fun-loving nature, keeping their leaders alive is of serious concern. Part of the Gorelian security plan involves changing the traffic patterns of their cities on a daily basis, and routing all Gorelian Government Officials to the Government Building by the fastest possible route.

Fortunately for the Gorelian Minister of Traffic (that would be you), all Gorelian cities are laid out as a rectangular grid of blocks, where each block is a square measuring 2520 rels per side (a rel is the Gorelian Official Unit of Distance). The speed limit between two adjacent intersections is always constant, and may range from 1 to 9 rels per blip (a blip, of course, being the Gorelian Official Unit of Time). Since Gorelians have outlawed decimal numbers as unholy (hey, if you're the dominant force in the known universe, you can outlaw whatever you want), speed limits are always integer values. This explains why Gorelian blocks are precisely 2520 rels in length: 2520 is the least common multiple of the integers 1 through 9. Thus, the time required to travel between two adjacent intersections is always an integer number of blips.

In all Gorelian cities, Government Housing is always at the northwest corner of the city, while the Government Building is always at the southeast corner. Streets between intersections might be one-way or two-way, or possibly even closed for repair (all this tinkering with traffic patterns causes a lot of accidents). Your job, given the details of speed limits, street directions, and street closures for a Gorelian city, is to determine the fastest route from Government Housing to the Government Building. (It is possible, due to street directions and closures, that no route exists, in which case a Gorelian Official Temporary Holiday is declared, and the Gorelian Officials take the day off.)

The picture above shows a Gorelian City marked with speed limits, one way streets, and one closed street. It is assumed that streets are always traveled at the exact posted speed limit, and that turning a corner takes zero time. Under these conditions, you should be able to determine that the fastest route from Government Housing to the Government Building in this city is 1715 blips. And if the next day, the only change is that the closed road is opened to two way traffic at 9 rels per blip, the fastest route becomes 1295 blips. On the other hand, suppose the three one-way streets are switched from southbound to northbound (with the closed road remaining closed). In that case, no route would be possible and the day would be declared a holiday.
 
Input
The input consists of a set of cities for which you must find a fastest route if one exists. The first line of an input case contains two integers, which are the vertical and horizontal number of city blocks, respectively. The smallest city is a single block, or 1 by 1, and the largest city is 20 by 20 blocks. The remainder of the input specifies speed limits and traffic directions for streets between intersections, one row of street segments at a time. The first line of the input (after the dimensions line) contains the data for the northernmost east-west street segments. The next line contains the data for the northernmost row of north-south street segments. Then the next row of east-west streets, then north-south streets, and so on, until the southernmost row of east-west streets. Speed limits and directions of travel are specified in order from west to east, and each consists of an integer from 0 to 9 indicating speed limit, and a symbol indicating which direction traffic may flow. A zero speed limit means the road is closed. All digits and symbols are delimited by a single space. For east-west streets, the symbol will be an asterisk '*' which indicates travel is allowed in both directions, a less-than symbol '<' which indicates travel is allowed only in an east-to-west direction, or a greater-than symbol '>' which indicates travel is allowed only in a west-to-east direction. For north-south streets, an asterisk again indicates travel is allowed in either direction, a lowercase "vee" character 'v' indicates travel is allowed only in a north-to-south directions, and a caret symbol '^' indicates travel is allowed only in a south-to-north direction. A zero speed, indicating a closed road, is always followed by an asterisk. Input cities continue in this manner until a value of zero is specified for both the vertical and horizontal dimensions.
 
Output
For each input scenario, output a line specifying the integer number of blips of the shortest route, a space, and then the word "blips". For scenarios which have no route, output a line with the word "Holiday".
 
Sample Input
2 2
9 * 9 *
6 v 0 * 8 v
3 * 7 *
3 * 6 v 3 *
4 * 8 *
2 2
9 * 9 *
6 v 9 * 8 v
3 * 7 *
3 * 6 v 3 *
4 * 8 *
2 2
9 * 9 *
6 ^ 0 * 8 ^
3 * 7 *
3 * 6 ^ 3 *
4 * 8 *
0 0
 
Sample Output
1715 blips
1295 blips
Holiday

 

最近智障了,居然把‘=’写成‘==’,WA到死

  1 #include <iostream>
  2 #include <cstring>
  3 #define N 1100
  4 #define inf 0X3f3f3f3f
  5 using namespace std;
  6 int mapp[N][N];
  7 int len[N];
  8 int nn;
  9 //void floyd(){
 10 //    for(int k=0;k<nn;k++){
 11 //        for(int i=0;i<nn;i++){
 12 //            if(mapp[i][k]==inf){
 13 //                continue;
 14 //            }
 15 //            for(int j=0;j<nn;j++){
 16 //                mapp[i][j]=min(mapp[i][j],mapp[i][k]+mapp[k][j]);
 17 //            }
 18 //        }
 19 //    }
 20 //}
 21 
 22 void Dijkstra(){
 23     for(int i=0;i<nn;i++){
 24         len[i]=mapp[0][i];
 25     }
 26     bool vis[N];
 27     memset(vis,false,sizeof(vis));
 28     vis[0]=true;
 29     for(int t=0;t<nn;t++){
 30         int k=-1;
 31         for(int i=0;i<nn;i++){
 32             if(!vis[i]&&(k==-1||len[k]>len[i])){
 33                 k=i;
 34             }
 35         }
 36         if(k==-1){
 37             return ;
 38         }
 39         vis[k]=true;
 40         for(int i=0;i<nn;i++){
 41             if(len[i]>len[k]+mapp[k][i]){
 42                 len[i]=len[k]+mapp[k][i];
 43             }
 44         }
 45     }
 46 }
 47 int main(){
 48     int mm,num,n,m;
 49     char str;
 50     cin.sync_with_stdio(false);
 51     while(cin>>n>>m&&(n+m)){
 52         nn=(n+1)*(m+1);
 53         for(int i=0;i<nn;i++){
 54             for(int j=0;j<nn;j++){
 55                 mapp[i][j]=inf;
 56             }
 57             mapp[i][i]=0;
 58         }
 59         for(int i=0;i<n*2+1;i++){
 60             if(i%2){
 61                 mm=m+1;
 62             }
 63             else{
 64                 mm=m;
 65             }
 66             for(int j=0;j<mm;j++){
 67                 int a,b;
 68                 cin>>num>>str;
 69                 a=(i/2)*(m+1)+j;
 70                 if(mm==m+1){
 71                     b=a+m+1;
 72                 }
 73                 else{
 74                     b=a+1;
 75                 }
 76                 if(num){
 77                     num=2520/num;
 78                     if(str=='*'){
 79                         mapp[a][b]=num;
 80                         mapp[b][a]=num;
 81                     }
 82                     else if(str=='>'){
 83                         mapp[a][b]=num;
 84                     }
 85                     else if(str=='<'){
 86                         mapp[b][a]=num;
 87                     }
 88                     else if(str=='v'){
 89                         mapp[a][b]=num;
 90                     }
 91                     else{
 92                         mapp[b][a]=num;
 93                     }
 94                 }
 95             }
 96         }
 97 //        floyd();
 98         Dijkstra();
 99         if(len[nn-1]!=inf){
100             cout<<len[nn-1]<<" blips"<<endl;
101         }
102         else{
103             cout<<"Holiday"<<endl;
104         }
105 //        if(mapp[0][nn-1]!=inf){
106 //            cout<<mapp[0][nn-1]<<" blips"<<endl;
107 //        }
108 //        else{
109 //            cout<<"Holiday"<<endl;
110 //        }
111     }
112     return 0;
113 }

2016-12-18 21:41:37


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
GO使用动态链接库(共享链接库)进行编译生成动态链接可执行文件 ...发布时间:2022-07-10
下一篇:
GO环境搭建发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap