HDU 4308 Contest 1
纯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的更多相关文章
- HDU 4308 BFS Saving Princess claire_
原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...
- hdu 4308 Saving Princess claire_
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...
- Saving Princess claire_(hdu 4308 bfs模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...
- HDU 5045 Contest(状压DP)
Problem Description In the ACM International Collegiate Programming Contest, each team consist of th ...
- hdu - 5045 - Contest(国家压缩dp)
意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...
- [ACM] hdu 5045 Contest (减少国家Dp)
Contest Problem Description In the ACM International Collegiate Programming Contest, each team consi ...
- HDU–5988-Coding Contest(最小费用最大流变形)
Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- hdu 4308 Saving Princess claire_ BFS
为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...
- hdu 5045 Contest(状态压缩DP)
题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...
随机推荐
- 机房-动环-江森ODS系统
优势: 标准的BACnet系统平台 开放的集成特性 支持Desktop and Server平台 支持多达100个NxE 支持无线应用,可以手机访问 DCIM---数据中心基础架构管理平台介绍 不同于 ...
- lpa标签传播算法解说及代码实现
package lpa; import java.util.Arrays; import java.util.HashMap; import java.util.Map; public class L ...
- xcodeproj cannot be opened because the project file cannot be parsed.
解决方法: 1.对.xcodeproj文件右键,显示包内容 2.双击打开 project.pbxproj 文件 3.找到以上类似的冲突信息(能够用commad + f搜索) 4.删除<&l ...
- 21.QT二进制文件
#include "mainwindow.h" #include <QApplication> #include <QFile> #include < ...
- 粘性固定属性 -- position:sticky
概述 position: sticky,这是一个比较容易忽略的css3 position 新属性,它的作用即为实现粘性布局,它是 relative 与 fixed 的结合. 用法 默认情况下,其表现为 ...
- Python—JSON数据解析
1.安装pip pip是python的包管理工具,使用它能非常方便地安装和卸载各种python工具包 第一步:直接用浏览器访问地址:https://raw.github.com/pypa/pip/ma ...
- Vue中问题总结 与未解决问题总结
问题一: Error in render: "TypeError: Cannot read property 'matched' of undefined" 使用路由之后报错,路由 ...
- Core Java(五)
类和对象&方法 ——类的定义 现实世界的事物 属性:人的身高,体重等 行为:人可以学习,吃饭等 Java中用class描述事物也是如此 成员变量:就是事物的属性 成员方法:就是事物的行为 ...
- jQuery分页插件pagination的用法
https://www.zhangxinxu.com/jq/pagination_zh/ 参数: 参数名 描述 参数值 maxentries 总条目数 必选参数,整数 items_per_page 每 ...
- mac下生成ssh key
ssh -v usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address: ...