无
- /**************************************************************
- Problem: 1193
- User: lxy8584099
- Language: C++
- Result: Accepted
- Time:24 ms
- Memory:820 kb
- ****************************************************************/
- /*
- 贪心 吧两点走进到 50 之内吧
- 然后 50 之内 bfs 打个表,,,
- */
- #include <cmath>
- #include <cstdio>
- using namespace std;
- int xp,yp,xs,ys,ans,m[100]={0,3,2,3,2,3,4,5,4,5,6,3,2,1,2,3,4,3,4,5,6,5,2,1,4,3,2,3,4,5,4,5,6,3,2,3,2,3,4,3,4,5,6,5,2,3,2,3,4,3,4,5,4,5,6,3,4,3,4,3,4,5,4,5,6,5};
- inline void swap(int &a,int &b) {int c=a; a=b; b=c;}
- int main()
- {
- scanf ("%d%d%d%d",&xp,&yp,&xs,&ys);
- if (xp>xs) swap(xp,xs);
- if (yp>ys) swap(yp,ys);// 确保马在左下角
- if (xs-xp<6&&ys-yp<11) printf ("%d",m[(xs-xp)*11+ys-yp]);// 如果可以直接贪心
- else while (1)
- {
- if (xp>xs) swap(xp,xs);
- if (yp>ys) swap(yp,ys);// 确保马在左下角
- if (xs-xp<6&&ys-yp<11)// 如果接近了
- {
- printf ("%d",ans+m[(xs-xp)*11+ys-yp]);
- return 0;
- }
- if (xp-xs>yp-ys) {xp+=1; yp+=2;}
- else {xp+=2; yp+=1;}// 贪心
- ++ans;
- }
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2949087.html