zoukankan      html  css  js  c++  java
  • 多校联赛(1)Saving Princess claire_

    View Code
      1 #include<stdio.h>
      2 #include<string.h>
      3 typedef struct que
      4 {
      5     int x,y;
      6     long num;
      7 }st;
      8 st q[10001];
      9 char str[1001][1001];
     10 int f[1001][1001];
     11 int p,d;
     12 void inque(int a,int b)
     13 {
     14     d++;
     15     if(d>10000)
     16     d = d%10000;
     17     q[d].x = a;
     18     q[d].y = b;
     19 }
     20 int main()
     21 {
     22     int i,j,x3,y3,r,flag,c,w,cost,a[501],b[501],x1,y1,dis[2]={-1,1};
     23     while(scanf("%d%d%d%*c", &r,&c,&cost)!=EOF)
     24     {
     25         int g = 0;
     26         flag = 0;
     27         memset(q,0,sizeof(q));
     28         memset(f,0,sizeof(f));
     29         for(i = 1 ; i <= r ; i++)
     30         {
     31             for(j = 1; j <= c ; j++)
     32             {
     33                 scanf("%c", &str[i][j]);
     34                 if(str[i][j]=='Y')
     35                 {
     36                     x1 = i;
     37                     y1 = j;
     38                 }
     39                 if(str[i][j]=='P')
     40                 {
     41                     a[g] = i;
     42                     b[g] = j;
     43                     g++;
     44                 }
     45             }
     46             getchar();
     47         }
     48         p = 0;
     49         d = 0;
     50         w = 0;
     51         q[1].num = 0;
     52         inque(x1,y1);
     53         f[x1][y1] = 1;
     54         do
     55         {
     56             p++;
     57             if(p>10000)
     58             p = p%10000;
     59             x3 = q[p].x;
     60             y3 = q[p].y;
     61             for(i = 0 ; i < 2  ;i++)
     62             {
     63                 int px = x3+dis[i];
     64                 int py = y3+dis[i];
     65                 if(!f[px][y3]&&px>0&&px<=r&&(str[px][y3]=='*'||str[px][y3]=='P'||str[px][y3]=='C'))
     66                 {
     67                     if(str[px][y3]=='*')
     68                     {
     69                         inque(px,y3);
     70                         q[d].num = q[p].num+cost;
     71                         f[px][y3] = 1;
     72                     }
     73                     else
     74                     if(str[px][y3]=='P'&&!w)
     75                     {
     76                         inque(px,y3);
     77                         q[d].num = q[p].num;
     78                         f[px][y3] = 1;
     79                         for(j = 0 ; j < g ; j++)
     80                         {
     81                             inque(a[j],b[j]);
     82                             f[a[j]][b[j]] = 1;
     83                             q[d].num = q[p].num;
     84                         }
     85                         w = 1;
     86                     }
     87                     else
     88                         if(str[px][y3]=='C')
     89                         {
     90                             flag = 1;
     91                             break;
     92                         }
     93                 }
     94                 if(!f[x3][py]&&py>0&&py<=c&&(str[x3][py]=='*'||str[x3][py]=='P'||str[x3][py]=='C'))
     95                 {
     96                     if(str[x3][py]=='*')
     97                     {
     98                         inque(x3,py);
     99                         q[d].num = q[p].num+cost;
    100                         f[x3][py] = 1;
    101                     }
    102                     else
    103                     if(str[x3][py]=='P'&&!w)
    104                     {
    105                         inque(x3,py);
    106                         q[d].num = q[p].num;
    107                         f[x3][py] = 1;
    108                         for(j = 0 ; j < g ; j++)
    109                         {                            
    110                             if(a[j]!=x3||b[j]!=py)
    111                             {
    112                                 inque(a[j],b[j]);
    113                                 q[d].num = q[p].num;
    114                                 f[a[j]][b[j]] = 1;
    115                             }
    116                         }
    117                         w = 1;
    118                     }
    119                     else
    120                         if(str[x3][py]=='C')
    121                         {
    122                             flag = 1;
    123                             break;
    124                         }
    125                 }
    126             }
    127             if(flag)
    128                 break;
    129         }while(p!=d);
    130         if(flag)
    131         printf("%ld\n",q[p].num);
    132         else
    133             printf("Damn teoy!\n");
    134     }
    135     return 0;
    136 }

    Saving Princess claire_

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

    Problem 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
    BFS  题意描述不清楚 害得超了两次内存
     
  • 相关阅读:
    vue----计算与监听属性
    vue---条件与循环语句
    vue--模板语法
    git版本控制系统--介绍
    HttpWebRequest使用总结
    计算机专业的书普遍都这么贵,你们都是怎么获取资源的?
    130 个相见恨晚的超实用网站,一次性分享出来
    实现客户端与服务端的HTTP通讯
    默认网关(地址)
    .NET Reactor使用教程(加密源代码示例)
  • 原文地址:https://www.cnblogs.com/shangyu/p/2599603.html
Copyright © 2011-2022 走看看