记录编号 |
117207 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[USACO Dec07] 泥潭 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.034 s |
提交时间 |
2014-08-28 18:43:16 |
内存使用 |
1.47 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
struct points
{
int x,y,dist;
points(){};
points(int x,int y,int dist):x(x),y(y),dist(dist){};
};
//==============var declaration=================
bool vis[1100][1100];
const int ADD=500;
int mvx[]={1,0,-1,0};
int mvy[]={0,-1,0,1};
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="mud";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
int n,ex,ey;
scanf("%d%d%d",&ex,&ey,&n);
memset(vis,false,sizeof(vis));
For(i,1,n)
{
int x,y;
scanf("%d%d",&x,&y);
vis[x+ADD][y+ADD]=true;
}
queue <points> Q;
points now;
Q.push(points(0,0,0));
while (!Q.empty())
{
now=Q.front();Q.pop();
if (now.x==ex&&now.y==ey)
{
printf("%d\n",now.dist);
return 0;
}
For(i,0,3)
{
int xx=now.x+mvx[i];
int yy=now.y+mvy[i];
if (xx>=-500&&xx<=500&&yy>=-500&&yy<=500)
if (!vis[xx+ADD][yy+ADD])
{
vis[xx+ADD][yy+ADD]=true;
Q.push(points(xx,yy,now.dist+1));
}
}
}
#ifdef DEBUG
clock_t End_Time=clock();
cout<<endl<<endl<<"Time Used: "<<End_Time-Start_Time<<endl;
#endif
return 0;
}
//================fuction code====================