zoukankan      html  css  js  c++  java
  • 2012 #1 Saving Princess claire_

    Saving Princess claire_
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    Princess claire_ was jailed in a maze by Grand Demon Monster(GDM) teoy. 
    Out of anger, little Prince ykwd decides to break into the maze to rescue his lovely Princess. 
    The maze can be described as a matrix of r rows and c columns, with grids, such as 'Y', 'C', '*', '#' and 'P', in it. Every grid is connected with its up, down, left and right grids. 
    There is only one 'Y' which means the initial position when Prince ykwd breaks into the maze. 
    There is only one 'C' which means the position where Princess claire_ is jailed. 
    There may be many '*'s in the maze, representing the corresponding grid can be passed through with a cost of certain amount of money, as GDM teoy has set a toll station. 
    The grid represented by '#' means that you can not pass it. 
    It is said that as GDM teoy likes to pee and shit everywhere, this grid is unfortunately damaged by his ugly behavior. 
    'P' means it is a transmission port and there may be some in the maze. These ports( if exist) are connected with each other and Prince ykwd can jump from one of them to another. 

    They say that there used to be some toll stations, but they exploded(surely they didn't exist any more) because of GDM teoy's savage act(pee and shit!), thus some wormholes turned into existence and you know the following things. Remember, Prince ykwd has his mysterious power that he can choose his way among the wormholes, even he can choose to ignore the wormholes. 
    Although Prince ykwd deeply loves Princess claire_, he is so mean that he doesn't want to spend too much of his money in the maze. Then he turns up to you, the Great Worker who loves moving bricks, for help and he hopes you can calculate the minimum money he needs to take his princess back.
     

    Input

    Multiple cases.(No more than fifty.) 
    The 1st line contains 3 integers, r, c and cost. 'r', 'c' and 'cost' is as described above.(0 < r * c <= 5000 and money is in the range of (0, 10000] ) 
    Then an r * c character matrix with 'P' no more than 10% of the number of all grids and we promise there will be no toll stations where the prince and princess exist. 
     

    Output

    One line with an integer, representing the minimum cost. If Prince ykwd cannot rescue his princess whatever he does, then output "Damn teoy!".(See the sample for details.)
     

    Sample Input

    1 3 3 Y*C 1 3 2 Y#C 1 5 2 YP#PC
     

    Sample Output

    3 Damn teoy! 0
      1 #include <stdio.h>
      2 #include <string.h>
      3 #include <queue>
      4 #include <algorithm>
      5 using namespace std;
      6 const int inf=0x3f3f3f3f;
      7 
      8 struct Node
      9 {
     10     int x;
     11     int y;
     12 };
     13 char mp[5005][5005];
     14 int d[5005][5005],sx,sy,gx,gy,nump;
     15 int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
     16 Node P[505];
     17 
     18 int main()
     19 {
     20     int n,m,c;
     21     int i,j;
     22     while(scanf("%d %d %d",&n,&m,&c)!=EOF)
     23     {
     24         nump=0;
     25         getchar();
     26         for(i=1;i<=n;i++)
     27         {
     28             for(j=1;j<=m;j++)
     29             {
     30                 d[i][j]=inf;
     31                 scanf("%c",&mp[i][j]);
     32                 if(mp[i][j]=='Y')
     33                     sx=i,sy=j;
     34                 if(mp[i][j]=='C')
     35                     gx=i,gy=j;
     36                 if(mp[i][j]=='P')
     37                 {
     38                     nump++;
     39                     P[nump].x=i,P[nump].y=j;
     40                 }
     41             }
     42             getchar();
     43         }
     44 
     45         queue<Node> que;
     46         while(que.size()) que.pop();
     47         Node s;
     48         s.x=sx,s.y=sy;
     49         que.push(s);d[sx][sy]=0;
     50 
     51         while(que.size())
     52         {
     53             Node now=que.front(),nex;
     54             /*for(i=1;i<=m;i++)
     55                 printf("%d ",d[1][i]);
     56             printf("
    ");
     57             printf("%d
    ",now.y);*/
     58             que.pop();
     59 
     60             for(i=0;i<4;i++)
     61             {
     62                 int nx=now.x+dx[i],ny=now.y+dy[i];
     63                 if(1<=nx && nx<=n && 1<=ny && ny<=m && mp[nx][ny]!='#')
     64                 {
     65                     int value=d[now.x][now.y];
     66                     if(mp[nx][ny]=='*')
     67                         value++;
     68                     if(mp[nx][ny]=='P')
     69                     {
     70                         for(j=1;j<=nump;j++)
     71                         {
     72                             if(value<d[P[j].x][P[j].y])
     73                             {
     74                                 que.push(P[j]);
     75                                 d[P[j].x][P[j].y]=value;
     76                             }
     77                         }
     78                     }
     79                     else
     80                     {
     81                         if(value<d[nx][ny])
     82                         {
     83                             //printf("%d %d %d
    ",now.x,ny,value);
     84                             nex.x=nx,nex.y=ny;
     85                             que.push(nex);
     86                             d[nx][ny]=value;
     87                         }
     88                     }
     89                 }
     90             }
     91         }
     92 
     93         if(d[gx][gy]==inf)
     94             printf("Damn teoy!
    ");
     95         else
     96             printf("%d
    ",d[gx][gy]*c);
     97     }
     98     return 0;
     99 }
    100 /*
    101 1 7 5
    102 PY**C*P
    103 */
    View Code
  • 相关阅读:
    使用本地系统帐户和域用户帐户两者区别(microsoft SQLServer2000)(ZT)
    Winform中消息循环、异步操作、Control.Invoke&Control.BeginInvoke学习
    SQL字符串的分组聚合(ZT)
    一次项目维护案例而对事务学习的笔记
    NOIP2011提高组 选择客栈
    NOIP2012提高组 Day 2 Problem 2 借教室
    201793模拟赛T2 取数(win)
    201793模拟赛T1 卡片(card)
    01Dart 变量常量
    01TypeScript 基础类型
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771438.html
Copyright © 2011-2022 走看看