bzoj 1193

http://www.lydsy.com/JudgeOnline/problem.php?id=1193

大范围贪心,小范围宽搜。

膜拜大神

http://blog.csdn.net/u012915516/article/details/47447703

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj
 
using namespace std;

typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP;

#define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define fill(a,l,r,v) fill(a+l,a+r+1,v)
#define re(i,a,b)  for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define ire(i,x) for(typedef(x.begin()) i=x.begin();i!=x.end();i++)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define SF scanf
#define PF printf
#define two(k) (1<<(k))

template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;}

const DB EPS=1e-9;
inline int sgn(DB x){if(abs(x)<EPS)return 0;return(x>0)?1:-1;}
const DB Pi=acos(-1.0);

inline int gint()
  {
        int res=0;bool neg=0;char z;
        for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
        if(z==EOF)return 0;
        if(z=='-'){neg=1;z=getchar();}
        for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar());
        return (neg)?-res:res; 
    }
inline LL gll()
  {
      LL res=0;bool neg=0;char z;
        for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
        if(z==EOF)return 0;
        if(z=='-'){neg=1;z=getchar();}
        for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar());
        return (neg)?-res:res; 
    }

const int dx[]={2,2,1,1,-1,-1,-2,-2};
const int dy[]={1,-1,2,-2,2,-2,1,-1};

int sx,sy,ex,ey,x,y; 
int cnt;

int vis[2010][2010];
#define vis(i,j) vis[i+1000][j+1000]

int head,tail;
PII que[10000000];

int main()
  {
      freopen("bzoj1193.in","r",stdin);
        freopen("bzoj1193.out","w",stdout);
        int i;
        sx=gint();sy=gint();ex=gint();ey=gint();
        x=ex-sx;y=ey-sy;
        x=abs(x);y=abs(y);
        cnt=0;
        while(x+y>=50)
          {
              if(x<y)swap(x,y);
              if(x-4>2*y)x-=4;else x-=4,y-=2;
              cnt+=2;
          }
        mmst(vis,-1);
        que[head=tail=0]=PII(0,0);
        vis(0,0)=0;
        while(vis(x,y)==-1)
            {
                int ax=que[head].fi,ay=que[head].se;head++;
                re(i,0,7)
                  {
                      int bx=ax+dx[i],by=ay+dy[i];
                      if(vis(bx,by)==-1)
                        {
                            que[++tail]=PII(bx,by);
                            vis(bx,by)=vis(ax,ay)+1;
                            if(vis(x,y)!=-1)break;
                        }
                  }
            }
        cnt+=vis(x,y);
        PF("%d\n",cnt);
        return 0;
    }
            
View Code

 

posted @ 2015-08-21 14:02  maijing  阅读(157)  评论(0编辑  收藏  举报