题目:

Saving Princess claire_

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

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
Damn teoy!
0

开始想错了,不过很快就看出可以直接广搜(当然是在王文超童鞋一起讨论后才知道),不过因为不会写广搜。
1h写代码,2days's debug。
让大仙帮我看,大仙不干,我我只得自己debug,经过一步一步打印,最终确定输入格式有误,main里面初始化忘了写,就这么两个bug浪费了2days,以后要更加注意,敲代码前要想好运行的步骤。
还有一点,在所有bug改完之后,在杭电上交了好几遍都WA,后来把提交语言改为C++,就AC了。
代码:
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
struct M
{int x,y;
}Q[5005],p[505];
int head,teal;
void push( int a,int b )
{Q[teal].x=a;Q[teal].y=b;teal=(teal++)%5005;
}
M pop()
{M temp;temp=Q[head];head=(head++)%5005;return temp;
}
char map[5005];     //存放输入的字符矩阵
bool vis[5005]={0}; //vis[i*c+j]记录矩阵中[i,j]是否走过
int v[5005]={0};    //V[i*c+j]表示从起点到i,j的步数
int np;             //记录'P'的个数
const int xx[4]={ 1,-1,0,0 };
const int yy[4]={ 0,0,1,-1 };
int sx,sy,ex,ey;    //起点终点
int r,c,cost;       //行数列数,每一步的花费数
int bfs(  )
{push( sx,sy );//首先起点入队vis[sx*c+sy]=1;v[sx*c+sy]=0;M t;int i,j,x,y;while( head!=teal ){t=pop();if( t.x==ex&&t.y==ey )//若队头是终点,直接结束循环break;for( i=0;i<4;i++ ){x=t.x+xx[i];y=t.y+yy[i];if( vis[ x*c+y ]==0 && x<r && y<c && x>=0 && y>=0 )  //没走过且不超边界
            {if( map[x*c+y]=='P' )//如果遇到P,所有P全部入队
                {for( j=0;j<=np;j++ ){vis[ p[j].x*c+p[j].y ]=1;if( map[ t.x*c+t.y ]=='*' )//若是从*来,则要耗费一个cost,下同v[p[j].x*c+p[j].y]=v[ t.x*c+t.y ]+1;elsev[p[j].x*c+p[j].y]=v[t.x*c+t.y];push( p[j].x,p[j].y );}}else//若不是P,直接入队
                {vis[x*c+y]=1;if( map[ t.x*c+t.y ]=='*' )v[x*c+y]=v[ t.x*c+t.y ]+1;elsev[x*c+y]=v[t.x*c+t.y];push(x,y);}}}}if( vis[ex*c+ey]==0 )//目标位置没有走到return -1;elsereturn v[ex*c+ey];
}
int main()
{int i,j;while( scanf("%d%d%d",&r,&c,&cost)!=EOF ){memset(vis,0,sizeof(vis));memset(v,0,sizeof(v));//       getchar();head=0;teal=0;np=-1;for( i=0;i<r;i++ ){getchar();for( j=0;j<c;j++ ){scanf("%c",&map[i*c+j]);if( map[i*c+j]=='Y' ){sx=i;sy=j;}if( map[i*c+j]=='C' ){ex=i;ey=j;}if( map[i*c+j]=='#' )vis[i*c+j]=1;if( map[i*c+j]=='P' )//记录P的位置
                {np++;p[np].x=i;p[np].y=j;}}}int ans;ans=bfs();if( ans==-1 ){printf("Damn teoy!\n");}elseprintf("%d\n",ans*cost);}return 0;
}

转载于:https://www.cnblogs.com/rolyxiao/archive/2012/07/21/2602448.html

多校1(1009)(杭电4308)相关推荐

  1. 暑假N天乐【比赛篇】 —— 2019杭电暑期多校训练营(第一场)

    杭电多校第一场属实恐怖,我连补题的冲动都莫得了. 本来还想说按去年的经验来说,杭电是要比牛客稍微友好那么一丢丢的吧.结果当场打脸,签到题来了个最短路*2+网络流,这谁顶得住啊. 所以这两天都没在补这场 ...

  2. 2022杭电多校(十)

    2022杭电多校(十) 文章目录 2022杭电多校(十) 一.比赛小结 二.题目分析及解法(基础题) 1001.Winner Prediction 1003.Wavy Tree 1004.Averag ...

  3. 2022杭电多校(二)

    2022杭电多校(二) 文章目录 2022杭电多校(二) 一.比赛小结 二.题目分析及解法(基础题) 1001.Static Query on Tree 1002.C++ to Python 1003 ...

  4. 2022杭电多校(四)

    2022杭电多校(四) 文章目录 2022杭电多校(四) 一.比赛小结 二.题目分析及解法(基础题) 1001.Link with Bracket Sequence II 1002.Link with ...

  5. 2022杭电多校(一)

    2022杭电多校(一) 文章目录 2022杭电多校(一) 一.比赛小结 二.题目分析及解法(基础题) 1001.String 1002.Dragon slayer 1003.BackPack 1004 ...

  6. 2022杭电多校(五)

    2022杭电多校(五) 文章目录 2022杭电多校(五) 一.比赛小结 二.题目分析及解法(基础题) 1003.Slipper 1006.BBQ 1007.Count Set 1010.Braggin ...

  7. 2022杭电多校(三)

    2022杭电多校(三) 文章目录 2022杭电多校(三) 一.比赛小结 二.题目分析及解法(基础题) 1001.Equipment Upgrade 1002.Boss Rush 1003.Cyber ...

  8. 2018杭电暑假多校知识点总结(附大一结语)

    大学的第一个年头就这样过去了,在这一年里,有着迷茫也有着奋斗,可惜没有什么汗水.我有不幸,不幸调剂到了软件工程这个陌生的专业,但我却又是幸运的,因为我遇到了一位优秀的学长,在他的指导下才步入了ACM的 ...

  9. 杭电多校联赛2017年总结

    杭电多校联赛2017年总结   时间确实过得挺快,一个月很快结束,说实在的,一个月了,每次比赛都是混两道签到题,然后就开始挂机了,确实很不甘心,看着联赛的排名,确实感觉,和强校之前的差距还是很大的,P ...

最新文章

  1. x20 android7.0性能,vivoX7Plus和vivoX20综合对比评测 看完这些优缺点再做判断
  2. java怎么创建log4_如何使用log4j记录日志
  3. Kafka解惑之Old Producer(1)—— Beginning
  4. 如何正确的通过 C++ Primer 学习 C++?(转自知乎)
  5. SQL Case When Then
  6. java远程桌面连接不上_Java远程桌面调用失败
  7. .NET库和向后兼容的技巧——第2部分
  8. Effective C++读书笔记 第1章
  9. 从城市到矿山!成都睿铂与Microdrones 海外三维建模案例
  10. 《数据库系统概念》14-静态散列
  11. ES6学习笔记(对象新增方法)
  12. 深度学习2.08.tensorflow的高阶操作之张量排序
  13. vagrant 错误记录
  14. mysql实现axure协同工作_AxureUX CRM及协同办公APP高保真原型模板(带移动端实用元件库)...
  15. 浅识Tomcat10和Tomcat9的区别
  16. SDelete-Gui – 用右键安全的删除文件,不可恢复[Windows]
  17. 2018年安徽批捕涉黑涉恶犯罪2691人
  18. 互联网大数据与物联网大数据的区别 你有必要了解下
  19. 100ask imx6ull开发板移植NXP官方UBOOT
  20. 丽江文化旅游学院易腾创想Java实训第14组总结

热门文章

  1. Qt5.10编写俄罗斯方块
  2. C++新生入学管理系统
  3. 全国职业院校技能大赛改革试点赛云计算赛项
  4. 三、docker镜像创建
  5. aubo-i5机械臂(1)-正运动学求解
  6. 论文阅读笔记:Multi-model Databases: A New Journey to Handle the Variety of Data
  7. 奋进新时代 和数BaaS开启下一个波澜壮阔科技新世界
  8. lij IDEA快速编写代码
  9. HNUST 1231 趣味程序设计_猜牌术(-)
  10. 如何使用HTML5自定义数据属性以及原因