纯BFS+优先队列扩展。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <queue>
using namespace std; bool vis[5100];
char str[5100]; struct point{
int x,y;
int cost;
bool operator < (const point &a)const{
return cost>a.cost;
}
}st,en,passort[550],tmp,pushed;
int pp;
priority_queue<point>que;
int dir[4][2]={
{0,1},{0,-1},{1,0},{-1,0}
}; int work(int r,int c,int cost){
memset(vis,false,sizeof(vis));
int x,y;
st.cost=0;
que.push(st);
vis[st.x*c+st.y]=true;
while(!que.empty()){
tmp=que.top();
que.pop();
for(int i=0;i<4;i++){
x=tmp.x+dir[i][0],y=tmp.y+dir[i][1];
if(x>=0&&x<r&&y>=0&&y<c){
if(str[x*c+y]!='#'&&!vis[x*c+y]){
if(str[x*c+y]=='*'){
pushed.x=x;
pushed.y=y;
pushed.cost=tmp.cost+cost;
que.push(pushed);
vis[x*c+y]=true;
}
else if(str[x*c+y]=='P'){
for(int ps=0;ps<pp;ps++){
pushed.x=passort[ps].x;
pushed.y=passort[ps].y;
pushed.cost=tmp.cost;
que.push(pushed);
vis[x*c+y]=true;
}
}
else if(str[x*c+y]=='C')
return tmp.cost;
}
}
}
}
return -1;
} int main(){
int r,c,cost;
while(scanf("%d%d%d",&r,&c,&cost)!=EOF){
getchar();
int beg=0;
pp=0;
for(int i=0;i<r;i++){
gets(str+beg);
for(int k=beg;k<beg+c;k++)
if(str[k]=='Y'){
st.x=i;
st.y=k-beg;
}
else if(str[k]=='C'){
en.x=i;
en.y=k-beg;
}
else if(str[k]=='P'){
passort[pp].x=i;
passort[pp].y=k-beg;
pp++;
}
beg+=c;
}
int ans=work(r,c,cost);
if(ans==-1) printf("Damn teoy!\n");
else
printf("%d\n",ans);
while(!que.empty())
que.pop();
}
return 0;
}

  

HDU 4308 Contest 1的更多相关文章

  1. HDU 4308 BFS Saving Princess claire_

    原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...

  2. hdu 4308 Saving Princess claire_

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...

  3. Saving Princess claire_(hdu 4308 bfs模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...

  4. HDU 5045 Contest(状压DP)

    Problem Description In the ACM International Collegiate Programming Contest, each team consist of th ...

  5. hdu - 5045 - Contest(国家压缩dp)

    意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...

  6. [ACM] hdu 5045 Contest (减少国家Dp)

    Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...

  7. HDU–5988-Coding Contest(最小费用最大流变形)

    Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  8. hdu 4308 Saving Princess claire_ BFS

    为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...

  9. hdu 5045 Contest(状态压缩DP)

    题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...

随机推荐

  1. Hadoop(2)_机器信息分布表

    1.分布式环境搭建 采用4台安装Linux环境的机器来构建一个小规模的分布式集群. 图1 集群的架构 其中有一台机器是Master节点,即名称节点,另外三台是Slaver节点,即数据节点.这四台机器彼 ...

  2. [using_microsoft_infopath_2010]Chapter13 SharePoint视图和控制板

    本章概要: 1.规划站点的外观,使用View和web部件 2.为登录进来的用户展示相关的表单. 3.为管理员创建视图 4.从表单中收集到的数据中创建报表

  3. 存储概念解析:NAS与SAN的区别

    目前存储网络技术领域中的两个主旋律是SAN(存储区域网络)和NAS(网络连接区域存储),两者都宣称是解决现代企业高容量数据存储需求的最佳选择. 正如在餐厅就餐时大厨不会为您传菜,跑堂不会为您烹制鲜橙烩 ...

  4. WebRTC学习与DEMO资源一览

    一. WebRTC学习 1.1   WebRTC现状 本人最早接触WebRTC是在2011年底,那时Google已经在Android源码中加入了webrtc源码,放在/external/webrtc/ ...

  5. MySQL 5.7 zip 文件安装过程

    1.下载路径 https://dev.mysql.com/downloads/mysql/   有账号登陆下载, 没有账号:no thanks;just start my download   2.解 ...

  6. springMVC+uploadify3.1 文件上传 demo

    uploadify3.1 api 可参考:(点击打开链接) 需要springmvc的jar包 1.upload.jsp(主要代码) <script type="text/javascr ...

  7. SQL Server 从字符串中提取中文、英文、数字

    --[提取中文] IF OBJECT_ID('dbo.fun_getCN') IS NOT NULL DROP FUNCTION dbo.fun_getCN GO create function db ...

  8. 洛谷P3356 火星探险问题(费用流)

    题目描述 火星探险队的登陆舱将在火星表面着陆,登陆舱内有多部障碍物探测车.登陆舱着陆后,探测车将离开登陆舱向先期到达的传送器方向移动.探测车在移动中还必须采集岩石标本.每一块岩石标本由最先遇到它的探测 ...

  9. Windos下的6种IO模型简要介绍

    windows进行数据的收发有6种IO模型.分别是阻塞(blocking)模型,选择(select)模型,异步选择(WSAAsyncSelect)模型,事件选择(WSAEventSelect )模型, ...

  10. app专项测试

    本节为大家讲述app的专项测试——客户端性能测试.这个我也做了蛮久的了.在这里修改了一下本篇随笔. 首先我们了解一下什么是客户端的性能测试.性能测试相比大家都已经耳熟能详了,这个app的客户端性能测试 ...