标签:单位 用例 efi 表示 整数 ret style clu turn
3 3 3 2 1 1 1 1 3 2 10 2 2 2 10
6
#include <cstdio> #include <algorithm> #include <queue> #define N 102 #define M 102 /* 3 3 4 2 1 1 1 1 3 2 10 3 2 3 3 2 3 3 10 */ using namespace std; typedef pair<int,int> PAIR; int go[][2] = {0,1,1,0,-1,0,0,-1}; bool vis[N][M][302] = {0}; struct node{ int x,y,t; node(int a,int b,int c){x = a;y = b;t = c;} }; int n,m,t; PAIR time[N][M]; int main() { scanf("%d%d%d",&n,&m,&t); for(int i = 0;i < t;i++){ int x,y; scanf("%d%d",&x,&y); scanf("%d%d",&time[x][y].first,&time[x][y].second); } queue<node> Q; Q.push(node(1,1,0)); while(!Q.empty()){ node tmp = Q.front(); Q.pop(); if(tmp.x == n && tmp.y == m){printf("%d",tmp.t);break;} for(int i = 0;i < 4;i++){ int p = tmp.x+go[i][0]; int q = tmp.y+go[i][1]; if(p == 0 || q == 0 || p == n+1 || q == m+1)continue; if(time[p][q].first <= tmp.t+1 && time[p][q].second >= tmp.t+1 || vis[p][q][tmp.t+1])continue; vis[p][q][tmp.t+1] = 1; Q.push(node(p,q,tmp.t+1)); } } return 0; }
标签:单位 用例 efi 表示 整数 ret style clu turn
原文地址:http://www.cnblogs.com/starryxsky/p/7279912.html