201604-4 游戏 100分 531ms

点击前往试题目录:https://blog.csdn.net/best335/article/details/99550556
在这里插入图片描述

#include<iostream>
#include<cstring>
#include<queue>
#include<unordered_set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int main(){
	unordered_set<int> V[101][101];
	int n,m,t,T[101][101][2],N,M;
	cin>>n>>m>>t,memset(T,0,sizeof(T)),N=n+1,M=m+1;
	for(int i=0,r,c,a,b;i<t;++i) cin>>r>>c>>a>>b,T[r][c][0]=a,T[r][c][1]=b;
	queue<PP> q;
	q.push(PP(0,P(1,1)));
	while(!q.empty()){
		const PP& p=q.front();
		const int w=p.first+1,&x=p.second.first,&y=p.second.second,lx=x-1,rx=x+1,ly=y-1,ry=y+1;
		if(x==n&&y==m-1||x==n-1&&y==m){
			cout<<w<<endl;
			break;
		}
		if(rx<N&&V[rx][y].find(w)==V[rx][y].end()&&(w<T[rx][y][0]||w>T[rx][y][1]))V[rx][y].insert(w),q.push(PP(w,P(rx,y)));
		if(ry<M&&V[x][ry].find(w)==V[x][ry].end()&&(w<T[x][ry][0]||w>T[x][ry][1]))V[x][ry].insert(w),q.push(PP(w,P(x,ry)));
		if(lx>0&&V[lx][y].find(w)==V[lx][y].end()&&(w<T[lx][y][0]||w>T[lx][y][1]))V[lx][y].insert(w),q.push(PP(w,P(lx,y)));
		if(ly>0&&V[x][ly].find(w)==V[x][ly].end()&&(w<T[x][ly][0]||w>T[x][ly][1]))V[x][ly].insert(w),q.push(PP(w,P(x,ly)));
		q.pop();
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值