hdu 4308 - Saving Princess claire_
来源:互联网 发布:阿里云学生机认证 编辑:程序博客网 时间:2024/05/01 06:12
题目:
Saving Princess claire_
题意:
王子救公主 , 蛋疼的王子希望支付最小的费用
给一张r*c的图,图上有'Y', 'C', '*', '#' 和 'P' , 各表示:
Y:王子的起始点
C:公主的地点,即终点
*:需要王子支付一定费用才能过 , 支付费用为cost
#:不能通行
P:传送点,每一个传送点可以无消耗直接通往任意一个其余传送点
普通移动无消耗
求救出公主的最小费用
思路:很简单的广搜 , 只是多了P,处理法:只要走上了P,就把所有的P相关位置全部压入队列,继续广搜就是了
代码:
//#pragma comment(linker, "/STACK:102400000,102400000")#include "iostream"#include "cstring"#include "algorithm"#include "cmath"#include "cstdio"#include "sstream"#include "queue"#include "vector"#include "string"#include "stack"#include "cstdlib"#include "deque"#include "fstream"#include "map"using namespace std;typedef long long LL;const long long LINF = (long long)1e30;const int INF = 522133279;const int MAXN = 100000+100;#define eps 1e-14const int mod = 100000007;char G[5010][5010];bool vis[5010][5010];int dir[4][2] = {1,0,0,1,-1,0,0,-1};struct pr{ int x; int y; LL cost; pr(int _x = 0 , int _y = 0 , int _cost = 0) : x(_x) , y(_y) , cost(_cost) {} bool operator < (const pr & b)const { return cost > b.cost; }}s,e;vector<pr> place_Of_P;int ok;int r,c,cost;LL minc;LL minll(LL a , LL b){ return a > b ? b : a;}bool border(int x , int y){ return (x >= 0 && x < r) && (y >= 0 && y < c);}void bfs(pr s){ priority_queue<pr> que; que.push(s); pr cur,tmp; int x,y; while(!que.empty()) { cur = que.top(); que.pop(); for(int i = 0 ; i < 4 ; i++) { x = cur.x + dir[i][0]; y = cur.y + dir[i][1]; if(border(x,y) && !vis[x][y] && G[x][y] != '#') { vis[x][y] = 1; tmp.x = x; tmp.y = y; tmp.cost = (G[x][y] == '*' ? cur.cost + cost: cur.cost); if(G[x][y] == 'P') for(int j = 0 ; j < place_Of_P.size() ; j++) { que.push(pr(place_Of_P[j].x , place_Of_P[j].y , tmp.cost)); vis[place_Of_P[j].x][place_Of_P[j].y] = 1; } else if(x == e.x && y == e.y) { minc = minll(minc , tmp.cost); ok=1; return ; } else que.push(tmp); } } }}int main(){ //freopen("in","r",stdin); while(cin >> r >> c >> cost) { memset(vis , 0 , sizeof(vis)); ok=0; place_Of_P.clear(); minc = LINF; for(int i = 0 ; i < r ; i++) for(int j = 0 ; j < c ; j++) { cin >> G[i][j]; if(G[i][j] == 'Y') { vis[i][j]=1; s.x = i; s.y = j; } else if(G[i][j] == 'C') { e.x = i; e.y = j; } else if(G[i][j] == 'P') place_Of_P.push_back(pr(i,j,0)); } bfs(s); if(!ok) cout << "Damn teoy!" << endl; else cout << minc << endl; } return 0;}
- hdu 4308 Saving Princess claire_
- HDU 4308 Saving Princess claire_
- HDU 4308 - Saving Princess claire_
- HDU 4308 Saving Princess claire_
- HDU 4308 Saving Princess claire_
- hdu 4308 - Saving Princess claire_
- HDU 4308 Saving Princess claire_
- HDU 4308 Saving Princess claire_
- hdu 4308 Saving Princess claire_
- HDU/HDOJ----4308 Saving Princess claire_
- hdu 4308 Saving Princess claire_(bfs)
- 【BFS】 HDU 4308 Saving Princess claire_
- hdu 4308 Saving Princess claire_(BFS)
- hdu 4308 Saving Princess claire_ BFS
- hdu 4308 Saving Princess claire_ (多校联合1)
- hdu 4308 Saving Princess claire_(bfs,4级)
- hdu 4308 Saving Princess claire_(BFS+优先队列)
- HDOJ 4308 - Saving Princess claire_ 水BFS...
- JEDIS
- 设计模式之代理模式(Proxy)
- 学习交流群
- SVM入门(七)为何需要核函数
- 351A Jeff and Rounding
- hdu 4308 - Saving Princess claire_
- Android学习笔记之AndroidManifest.xml文件解析
- I/O多路复用之poll
- java中的堆、栈、常量池
- 阻塞与非阻塞、select关于深入网络编程
- 杜克大学怪诞行为学
- 各种音视频编解码学习详解 h264 ,mpeg4 ,aac 等所有音视频格式
- Java遍历Set集合
- 配置管理--文档的状态