hnu 12921 Enterprising Escape
来源:互联网 发布:mac 因为找不到原身 编辑:程序博客网 时间:2024/05/22 01:37
The Enterprise is surrounded by Klingons! Find the escape route that has the quickest exit time, and print that time.
Input is a rectangular grid; each grid square either has the Enterprise or some class of a Klingon warship. Associated with each class of Klingon warship is a time that it takes for the Enterprise to defeat that Klingon. To escape, the Enterprise must defeat each Klingon on some path to the perimeter. Squares are connected by their edges, not by corners (thus, four neighbors).
The first line will contain T, the number of cases; 2 ≤ T ≤ 100. Each case will start with line containing three numbers k, w, and h. The value for k is the number of different Klingon classes and will be between 1 and 25, inclusive. The value for w is the width of the grid and will be between 1 and 1000, inclusive. The value for h is the height of the grid and will be between 1 and 1000, inclusive.
Following that will be k lines. Each will consist of a capital letter used to label the class of Klingon ships followed by the duration required to defeat that class of Klingon. The label will not be “E”. The duration is in minutes and will be between 0 and 100,000, inclusive. Each label will be distinct.
Following that will be h lines. Each will consist of w capital letters (with no spaces between them). There will be exactly one “E” across all h lines, denoting the location of the Enterprise; all other capital letters will be one of the k labels given above, denoting the class of Klingon warship in the square.
Your output should be a single integer value indicating the time required for the Enterprise to escape.
Sample Input26 3 3A 1B 2C 3D 4F 5G 6ABCFECDBG2 6 3A 100B 1000BBBBBBAAAAEBBBBBBBSample Output
2400
题目没看 就是知道大概的意思 就是会有K个字母 每个字母对应相应的值 在一个地图中 从E字母开始出发 直到最外面记录走过的点的值 求走到外面值的最小值
第一反映就是优先队列+bfs 写起来还算简单 因为只有大写字母 直接用数组存储点的值就好 遍历过的点要标记
代码如下:
<span style="font-size:18px;">#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <queue>#define eps 1e-8#define op operator#define MOD 10009#define MAXN 100100#define FOR(i,a,b) for(int i=a;i<=b;i++)#define FOV(i,a,b) for(int i=a;i>=b;i--)#define REP(i,a,b) for(int i=a;i<b;i++)#define REV(i,a,b) for(int i=a-1;i>=b;i--)#define MEM(a,x) memset(a,x,sizeof a)#define ll __int64using namespace std;int num[26];bool vis[1005][1005];char map[1005][1005];int sx,sy;int dir[4][2]={{0,-1},{1,0},{0,1},{-1,0}};int k,w,h;struct node{ int x,y; int sum; bool operator <(const node p)const { return sum>p.sum; }};node p,q;void bfs(){ priority_queue<node> Q; q.x=sx; q.y=sy; q.sum=0; vis[q.x][q.y]=1; Q.push(q); while(!Q.empty()) { q=Q.top(); Q.pop();// cout<<q.x<<" "<<q.y<<" "<<q.sum<<endl; if(q.x<0||q.x>=h||q.y<0||q.y>=w) { printf("%d\n",q.sum);// cout<<"ww"<<w<<"hh"<<h<<endl;// cout<<"11111111111"<<endl; return; } for(int i=0;i<4;i++) { p.x=q.x+dir[i][0]; p.y=q.y+dir[i][1]; if(p.x<0||p.x>=h||p.y<0||p.y>=w) { printf("%d\n",q.sum); return; } if(!vis[p.x][p.y]) { int tt=map[p.x][p.y]-'A'; vis[p.x][p.y]=1; p.sum=q.sum+num[tt]; Q.push(p); } } }}int main(){//freopen("ceshi.txt","r",stdin); int tc; scanf("%d",&tc); while(tc--) { scanf("%d%d%d\n",&k,&w,&h); MEM(vis,0); for(int i=0;i<k;i++) { char c; int n; scanf("%c %d\n",&c,&n); num[c-'A']=n; } for(int i=0;i<h;i++) { scanf("%s",map[i]); for(int j=0;j<w;j++) if(map[i][j]=='E') { sx=i; sy=j; } } bfs(); } return 0;}</span>
- hnu 12921 Enterprising Escape
- Enterprising Escape
- Enterprising Escape
- CSU 1815: Enterprising Escape (BFS搜索)
- 2017湖南多校第一场-Enterprising Escape
- 文章标题 CSU 1815 : Enterprising Escape(BFS--优先队列)
- CSU 1815:Enterprising Escape(BFS+优先队列)
- escape
- escape
- escape
- Escape
- Escape
- Escape
- HNU 11877
- hnu 病毒
- hnu 12948
- HNU Profits
- HNU 21
- bat字符串替换
- Redis设置过期时间
- UVa 297 四分树
- poj 1458 Common Subsequence (DP:LCS)
- 字符串null和“”的区别
- hnu 12921 Enterprising Escape
- 【Oracle】RAC 10.2.0.1升级10.2.0.5
- LeetCode总结 -- 一维数据合并篇
- Oracle R12 多组织访问的控制 - MOAC(Multi-Org Access Control)
- poj 2250 Compromise (DP:LCS加强版+记忆化搜索)
- 除法(Division ,UVA 725)-ACM集训
- C++ primer 第五版 中文版 9.3.4 节练习
- 正则表达式
- Linux创始人莱纳斯·托瓦兹“依然想占领桌面市场”