Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:谁帮看一下代码错在哪里?

Posted by luxury2664 at 2010-12-05 13:01:36 on Problem 1915
In Reply To:谁帮看一下代码错在哪里? Posted by:xiaoqiang008 at 2010-11-29 23:33:00
> #include <iostream>
> #include <vector>
> #include <cstring>
> using namespace std;
> int x0,y0,x1,y1,length,in,n;
> struct point{
>     int x;
>     int y;
> }temp;
> vector<point> vec;
> int fnd;
> int dix[8][2]={1,2,1,-2,-1,2,-1,-2,2,1,2,-1,-2,1,-2,-2};
> int map[301][301];
> void deal(int x,int y,int time)
> {
>     int tempx,tempy;
>     if(x==x1&&y==y1) {fnd=1;return;}
>     for(int i=0;i<8;i++)
>     {
>         tempx=x+dix[i][0];tempy=y+dix[i][1];//cout<<tempx<<' '<<tempy<<endl;
>         if(tempx>=0&&tempx<length&&tempy>=0&&tempy<length&&map[tempx][tempy]==-1) {temp.x=tempx;temp.y=tempy;vec.push_back(temp);map[tempx][tempy]=time+1;}
>     }
> 
> 
> }
> int main()
> {
>     cin>>n;
>     while(n--)
>     {
>         cin>>length>>x0>>y0>>x1>>y1;
>         vec.clear();
>         //cout<<length<<" "<<x0<<" "<<y0<<" "<<x1<<" "<<y1;
>         temp.x=x0;temp.y=y0;
>         //cout<<temp.x<<" "<<temp.y<<endl;
>         in=0;
>         fnd=0;
>         vec.push_back(temp);
>         memset(map,-1,sizeof(map));
>         map[x0][y0]=0;
>         while(in<vec.size()&&fnd!=1)
>         {
>                 deal(vec[in].x,vec[in].y,map[vec[in].x][vec[in].y]);
>                 in++;
>         }
> 
>         cout<<map[x1][y1]<<endl;
>         //cout<<vec.size()<<endl;
> 
> 
>     }
> 
>     return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator