#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
using namespace std ; int d [ ] [ ] ;
int ha ( const int x , const int y ) {
if ( x == && y == ) return ;
typedef pair < int , int > p ;
queue < p > q ;
for ( int i = ; i < ; ++ i )
for ( int y = ; y < ; ++ y ) d [ i ] [ y ] = - ;
d [ ] [ ] = ;
q . push ( make_pair ( , ) ) ;
while ( q . size () ) {
const p o = q . front () ; q . pop () ;
if ( abs ( o . first - ) > || abs ( o . second - ) > ) continue ;
const int x_ [] = { , , , , - , - , - , - } ;
const int y_ [] = { , - , , - , , - , , - } ;
for ( int i = ; i < ; ++ i ) {
const int nx = o . first + x_ [ i ] ;
const int ny = o . second + y_ [ i ] ;
if ( nx == x + && ny == y + ) return d [ o . first ] [ o . second ] + ;
if ( d [ nx ] [ ny ] == - ) {
d [ nx ] [ ny ] = d [ o . first ] [ o . second ] + ;
q . push ( make_pair ( nx , ny ) ) ;
}
}
}
exit ( - ) ;
} int xp , yp , xs , ys ;
int x , y ;
int step_cnt = ;
int main () {
scanf ( "%d%d%d%d" , & xp , & yp , & xs , & ys ) ;
x = abs ( xp - xs ) ; y = abs ( yp - ys ) ;
while ( abs ( x ) + abs ( y ) >= ) {
if ( abs ( x ) >= abs ( y ) ) {
const int step = abs ( x / ) ;
x -= ( ( x > ) ? step : - step ) * ;
y -= ( y > ) ? step : - step ;
step_cnt += abs ( step ) ;
} else {
const int step = abs ( y / ) ;
x -= ( x > ) ? step : - step ;
y -= ( y > ? step : - step ) * ;
step_cnt += abs ( step ) ;
}
}
printf ( "%d\n" , step_cnt + ha ( abs ( x ) , abs ( y ) ) ) ;
return ;
}

贪心+bfs

bzoj1193的更多相关文章

  1. [BZOJ1193][HNOI2006]马步距离(贪心+dfs)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1193 分析: 首先小范围可以直接暴力.(其实只要用上题目中的表就行了) 如果范围比较大 ...

  2. bzoj1193: [HNOI2006]马步距离

    1193: [HNOI2006]马步距离 Time Limit: 10 Sec  Memory Limit: 162 MB Description 在国际象棋和中国象棋中,马的移动规则相同,都是走&q ...

  3. bzoj1193 马步距离

    Description 求点(xs,ys)走马步到(xp,yp)的最小步数   Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Out ...

  4. [BZOJ1193][HNOI2006]马步距离 大范围贪心小范围爆搜

    1193: [HNOI2006]马步距离 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1988  Solved: 905[Submit][Statu ...

  5. 【bzoj1193】[HNOI2006]马步距离

    [HNOI2006]马步距离 Description Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Output 含一个整数,表示从 ...

  6. BZOJ1193 马步距离 (贪心)

    恶心的题目= = #include <cstdio> #include <cmath> #include <algorithm> ][]={{,,,,},{,,,, ...

  7. bzoj1193: [HNOI2006]马步距离(贪心+bfs)

    1193: [HNOI2006]马步距离 题目:传送门 题解: 毒瘤题... 模拟赛时的一道题,刚开始以为是一道大难题...一直在拼命找规律 结果.... 还是说正解吧: 暴力的解法肯定是直接bfs, ...

  8. bzoj 1193

    http://www.lydsy.com/JudgeOnline/problem.php?id=1193 大范围贪心,小范围宽搜. 膜拜大神 http://blog.csdn.net/u0129155 ...

  9. [转载]hzwer的bzoj题单

    counter: 664BZOJ1601 BZOJ1003 BZOJ1002 BZOJ1192 BZOJ1303 BZOJ1270 BZOJ3039 BZOJ1191 BZOJ1059 BZOJ120 ...

随机推荐

  1. SRM 620 DIV1 L2

    题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...

  2. struts2与struts1整合,java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    原因:我往项目的WEB-INF/lib中导入了struts2基本的包,还有struts1的core包,以及struts2-strut1-plugin的包,但是没有导入commons-loggin-1. ...

  3. hdu 3177

    题目大意:向体积为v的山洞中搬运n个物品,每个物品具有(a,b) 属性.其中a是停放体积,b是移动体积.输出这个山东是否能放下这n个物品 解题思路: 1)当前物品能否放进山洞取决于当前物品的的移动体积 ...

  4. SQL分组查询group by

    注意:select 后的字段,必须要么包含在group by中,要么包含在having 后的聚合函数里. 1. GROUP BY 是分组查询, 一般 GROUP BY 是和聚合函数配合使用 group ...

  5. Google 镜像站大集合

    没有了google的日子是相当难受,下面推荐一些google的镜像站,感谢原文博主的无私奉献,同时也欢迎大家总结科研上的小技巧,心得等来本平台投稿,好东西当然要拿出来共同分享! 以下镜像站分原版和非原 ...

  6. python类的简单介绍

    类是面向对象编程的核心, 它扮演相关数据及逻辑的容器角色.它们提供了创建“真实”对象(也就是实例)的蓝图.因为Python 并不强求你以面向对象的方式编程(与Java 不同), 此刻你也可以不学习类. ...

  7. ccnu-线段树联系-单点更新2-B

    B - 单点更新2 Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Des ...

  8. ZOJ Problem Set - 3865 Superbot (bfs)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 大牛博客:http://www.cnblogs.com/kylehz/p ...

  9. MFC弹出菜单隐藏解决

    http://social.msdn.microsoft.com/Forums/en-US/5482103e-272b-4c9f-bac4-be15f14782bd/cmfcmenubar-remov ...

  10. ERROR 1442 (HY000):because it is already used by statement which invoked this stored function/tr

    看到mysql的触发器,随手写了一个: mysql> create trigger t_ai_test -> after insert on test -> for each row ...