青蛙跳
来源:互联网 发布:javascript php 混合 编辑:程序博客网 时间:2024/04/28 16:37
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <climits>#include <cmath>#include <cfloat>#include <algorithm>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#include <functional>#include <string>#define EXP 1e-9#define LL long long#define PB push_back#define N 100010using namespace std;int a, b, p;int x[15][15], f[15][15], visit[15][15];int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};int cost[4] = {1, 1, 3, 0};void solve() { int dis[15][15]; memset(dis, -1, sizeof(dis)); memset(visit, 0, sizeof(visit)); queue< pair<int, int> > Q; Q.push(make_pair(0, 0)); dis[0][0] = 1; visit[0][0] = 1; f[0][0] = -1; while(!Q.empty()) { pair<int, int> tmp = Q.front(); Q.pop(); int xx = tmp.first, yy = tmp.second; visit[xx][yy] = 0; for(int i = 0; i < 4; ++i) { int m = xx + dir[i][0]; int n = yy + dir[i][1]; if(m>=0&&m<a && n>=0&&n<b && x[m][n] != 0) { if(dis[m][n]==-1 || dis[m][n] > dis[xx][yy]+cost[i]) { dis[m][n] = dis[xx][yy] + cost[i]; f[m][n] = xx * b + yy; if(visit[m][n] == 0) { visit[m][n] = 1; Q.push(make_pair(m, n)); } } } } } cout << dis[0][b-1] << endl; if(dis[0][b-1]==-1 || dis[0][b-1] > p) { cout << "Can not escape!" << endl; } else { vector< pair<int, int > > re; int ff = b-1; while(ff != -1) { int x = ff / b; int y = ff % b; re.push_back( make_pair(x, y) ); ff = f[x][y]; } for(int i = (int)re.size()-1; i>=0; --i) { cout << "[" << re[i].first << "," << re[i].second << "]"; if(i != 0) { cout << ","; } } cout << endl; }}int main(int argc, char* argv[]) { while(cin >> a >> b >> p) { for(int i = 0; i < a; ++i) for(int j = 0; j < b; ++j) { cin >> x[i][j]; } solve(); } return 0;}
0 0
- 青蛙跳
- 青蛙跳
- 青蛙跳
- 青蛙跳
- 青蛙跳和变态青蛙跳问题
- 青蛙跳阶问题
- 青蛙台阶跳
- 牛客网-青蛙跳迷宫
- 青蛙跳问题
- 青蛙跳阶
- 青蛙跳阶
- 变态青蛙跳问题
- 青蛙跳2
- 青蛙跳-LintCode
- 变态青蛙跳
- 青蛙
- 青蛙
- 大家一起来跳青蛙--智力考验
- C语言学习——动态内存
- 2016春晚的烧钱营销:阿里与腾讯
- 类似新浪微博帖子显示话题、@好友、表情解析等
- hdu1863
- Error Domain=com.alamofire.error.serialization.response Code=-1016 "(AFN问题)
- 青蛙跳
- java 中的jdbc的连接和使用
- Android网络框架综述(一)OkHttp、NoHttp、Volley
- Chapter 02 - JAVA语言的基本组成
- 老羊摘编自《罗辑思维跨年演讲》分享1--万物有灵
- Eclipse中jsp、js文件编辑时,卡死现象解决汇总
- 【codeforces】New Year Transportation
- mysql单字段任意字符匹配模糊查询
- Linux的进程/线程间通信