Codevs 2059 Escape from Clone Island

Source: Internet
Author: User

2059 Escape from the clone island time limit: 1 s space limit: 128000 KB title level: Golden Gold Title Description Description

Oi Group of YH love to play Warcraft RPG, every day in U9 search the latest RPG map.

Today, he found a map called "Escape from the island of cloning," in this map, there is an n-row m-column matrix, the matrix consists of ' Y ', ' C ', ' # ', ' * ', ' P ', 5 elements. ' Y ' denotes the birth location of the YH, C denotes the exit of the Clone Island, ' # ' indicates that the place is not approved, ' * ' means that it needs to be consumed by the cost of gold, ' P ' means that the transmission array, any two of the transmission array can be transmitted to each other free. Since this is only the first level, YH do not want to waste too much energy, smart you can help him to calculate from ' Y ' to ' C ' minimum need to consume how much gold? Of course, if YH can never reach ' C ', output "screw you!" Dissatisfaction with the table to YH.

Enter a description input Description

The first row of two integers, n,m, indicates that the matrix has n rows m columns

Next is the N-row m-column matrix, composed of ' Y ', ' C ', ' # ', ' * ', ' P ', meaning as described in the title.

outputs description output Description

Output 1 lines, indicating the minimum amount of physical energy required by the YH (if the output "screw you!" cannot be reached )。

sample input to sample

"Sample Input 1"

1 3 3

Y*c

"Sample Input 2"

1 3 2

Y#c

"Sample Input 3"

1 5 2

Yp#pc

Sample output Sample outputs

"Sample Output 1"

3

"Sample Output 2"

Screw you!

"Sample Output 3"

0

data size & Hint

"Data Range"

For 100% of data, n*m≤5000, the number of transmit array ' P ' ≤500

#include <cstdio> #include <cstring> #include <iostream>using namespace Std;int N,m,cost,sx,sy,ex,ey , Tot=0;int u[5]={0,0,1,0,-1};int v[5]={0,1,0,-1,0};int X[10010],y[10010],dis[10010];//dis array record takes char map[1010][1010 ];bool used[1010][1010],chuan[1010][1010];//Record Portal coordinates bool flag;void BFS (int x1,int y1) {int tt=0,ww=1;used[x1][y1]=1;x[    1]=x1;y[1]=y1;dis[1]=0;        while (TT&LT;WW) {tt++;            for (int i=1;i<=4;i++)//Four directions {int xx=x[tt]+u[i];            int yy=y[tt]+v[i];                if (Xx==ex&&yy==ey) {flag=1;            printf ("%d", Dis[tt]);//output cost return; } if (xx>0&&xx<=n&&yy>0&&yy<=m&&map[xx][yy]!= ' # ' &&!used[xx][                    YY]) {if (Chuan[xx][yy]) {chuan[xx][yy]=0;            for (int i=1;i<=n;i++) for (int j=1;j<=m;j++)                if (Chuan[i][j]) {ww++;                                x[ww]=i;y[ww]=j;chuan[i][j]=0; dis[ww]=dis[tt];//update Dis Array}} ww++;x[ww]=xx;y[ww]=yy;used[xx][yy                ]=1;                if (map[xx][yy]== ' * ') dis[ww]=dis[tt]+cost; If Go is * let dis array plus cost else dis[ww]=dis[tt];//otherwise do not add}}}}int main () {scanf ("%d%d%d", &    Amp;n,&m,&cost);            for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) {cin>>map[i][j];            if (map[i][j]== ' Y ') sx=i,sy=j;            else if (map[i][j]== ' C ') ex=i,ey=j;        else if (map[i][j]== ' P ') chuan[i][j]=1;    } BFS (Sx,sy);    if (!flag) printf ("Screw you!\n"); return 0;}

Idea: When you go to the portal, the points on the other side of the portal will be joined to the queue, wide search.

Codevs 2059 Escape from Clone Island

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.