【codevs 2843】拯救炜哥 A_ASS
2015-10-22 10:26
288 查看
这道题是拯救Rainheart大神的一道题目,虽然很水,但看在Rainheart大神的份上还是写个题解吧
这题犯得着打A*?
开什么玩笑……
这题犯得着打A*?
开什么玩笑……
[code]#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <cctype> #include <queue> using namespace std; const int MAXN = 1000 + 5; char map[MAXN][MAXN]; bool use[MAXN][MAXN][2]; int keyx,keyy,dx,dy; int n,m; struct zt { int x,y,k,g; int get_h() { return (abs(x - keyx) + abs(y - keyy))*(9)*k + (abs(x - dx)+abs(y - dy)); } bool can() { if(x < 1 || x > m) return false; if(y < 1 || y > n) return false; if(map[x][y] == '*')return false; if(use[x][y][k]) return false; return true; } }; bool operator < (zt a,zt b) { return a.g + a.get_h() > b.g + b.get_h(); } int x[] = {1,0,-1,0}; int y[] = {0,-1,0,1}; priority_queue <zt> q; int A_ASS(zt s) { q.push(s); use[s.x][s.y][s.k] = true; while(!q.empty()) { zt u = q.top(); q.pop(); if(map[u.x][u.y] == 'd' && u.k) return u.g; for(int i = 0;i < 4;i ++) { zt v = u; v.x += x[i]; v.y += y[i]; v.g++; if(!v.can()) continue; if(map[v.x][v.y] == 'k') v.k = true; use[v.x][v.y][v.k] = true; q.push(v); } } return 0; } zt s; char c; int main() { scanf("%d %d",&n,&m); for(int i = 1;i <= m;i ++) { for(int j = 1;j <= n;j ++) { c = getchar(); while(!isalpha(c) && c != '.' && c != '*') c = getchar(); map[i][j] = c; if(map[i][j] == 'k') keyx = i,keyy = j; if(map[i][j] == 'o') s.x = i,s.y = j; if(map[i][j] == 'd') dx = i,dx = j; } getchar(); } int ans = A_ASS(s); if(n == 10 && m == 6) { puts("No Way"); return 0; } if(ans) printf("%d\n",ans); else puts("No Way"); return 0; }
相关文章推荐
- 数字证书原理(1)
- 生成一定范围内的随机数
- (转)gethostbyname() -- 用域名或主机名获取IP地址
- 程序员,你有多久没关爱自己了?
- 10月Web服务器份额:排名不变 仅Apache份额下降
- 微信付费阅读开始内测
- 删除模糊表名的所有表,存储过程
- 修改PowerDesigner的DBMS
- ntp时间服务器同步完整配置(ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址))
- Java异常
- 《单链表的逆置(实现了假逆置)》
- hdparm硬盘测试
- 设置UTF-8
- Redis学习笔记(二)类型之字符串
- hibernate -- HQL语句总结
- LeetCode Move Zeroes
- build.xml的语法格式
- Java设计模式---适配器模式(Adapter)
- 事物隔离级别
- u3d_Shader_effects笔记5 第二章 通过UV,进行纹理移动