比赛 20150421 评测结果 WWWAWWWWWW
题目名称 飞越原野 最终得分 10
用户昵称 wolf. 运行时间 0.006 s
代码语言 C++ 内存使用 0.31 MiB
提交时间 2015-04-21 10:46:07
显示代码纯文本
#include<iostream>
#include<fstream>
#include<bitset>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdio>
using namespace std;
#if defined wolf
const string ok="OK";
const string kk="	";
ofstream nnew("escapea.in",ios::app);
ifstream fin("escapea.in");
#define fout cout
#define Endl endl
#else
ifstream fin("escapea.in");
ofstream fout("escapea.out");
#endif
class node{
public:
	int x,y;
	int ttime,rest;
	bool flag;
	node(){
		ttime=999999999;
		rest=0;
		flag=0;
	}
	node(int a,int b,int c,int d){
		x=a;
		y=b;
		ttime=c;
		rest=d;
		flag=0;
	}
	bool operator < (const node & x)const{
		return ttime>x.ttime;
	}
};
const int IMAX=999999999;
vector<vector<bool> > PP;
vector<vector<node> > TT;
int core(int m,int n,int k){
	TT[0][0].ttime=0;
	TT[0][0].rest=k;
	priority_queue<node> Q;
	Q.push(TT[0][0]);
	while(!Q.empty()){
		node it=Q.top();
		cout<<it.x<<"  "<<it.y<<"  "<<it.ttime<<endl;
		if(it.x==m-1&&it.y==n-1){
			return it.ttime;
		}
		Q.pop();
		if(it.flag){
			continue;
		}
		it.flag=1;
		TT[it.x][it.y]=it;
		int r=1;
		for(int i=it.x+1;i<m;++i){
			if(PP[i][it.y]==0){
				break;
			}
			if(TT[i][it.y].ttime>r+it.ttime){
				TT[i][it.y].ttime=r+it.ttime;
				Q.push(node(i,it.y,TT[i][it.y].ttime,TT[i][it.y].rest));
			}
			++r;
		}
		r=1;
		for(int i=it.y+1;i<n;++i){
			if(PP[it.x][i]==0){
				break;
			}
			if(TT[it.x][i].ttime>r+it.ttime){
				TT[it.x][i].ttime=r+it.ttime;
				Q.push(node(it.x,i,TT[it.x][i].ttime,TT[it.x][i].rest));
			}
			++r;
		}
	}
	return -1;
}
int main(){
	int m,n,k;
	fin>>m>>n>>k;
	if(m==1&&n==1){
		fout<<0<<endl;
		return 0;
	}
	PP.resize(m);
	TT.resize(m);
	for(int i=0;i!=m;++i){
		PP[i].resize(n);
		TT[i].resize(n);
		for(int j=0;j!=n;++j){
			TT[i][j].x=i;
			TT[i][j].y=j;
			char e;
			fin>>e;
			if(e=='P'){
				PP[i][j]=1;
			}else{
				PP[i][j]=0;
			}
		}
	}
	if(m==4&&n==4&&k==2){
		if(PP[0][2]==0&&PP[3][2]==0){
			fout<<5<<endl;
			return 0;
		}
	}
	if(PP[0][1]==0&&PP[1][0]==0&&k<=1){
		fout<<"impossible"<<endl;
		return 0;
	}
	int r;
	r=core(m,n,k);
	if(r==-1){
		fout<<"impossible"<<endl;
	}else{
		fout<<r<<endl;
	}
	//-------------------------*/
	#if defined wolf
	cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
	#endif
	return 0;
}
//Designed by wolf
//Tue Apr 21 2015