#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. Java:Object类

    objcet类中涉及的多态的扩展性,由于Object是所有类的根类,所以它可以接收任意类型的数据,包括基本数据类型.因为这一特点,它可以对多态性进行扩展. 1.创建一个Demo类来判断类类型 clas ...

  2. linux内核编程笔记【原创】

    以下为本人学习笔记,如有转载请注明出处,谢谢 DEFINE_MUTEX(buzzer_mutex); mutex_lock(&buzzer_mutex); mutex_unlock(& ...

  3. js中indexOF和lastIndexOf

    indexOFindexOf() 方法返回某个指定的字符串值在字符串中首次出现的位置(从左向右).没有匹配的则返回-1,否则返回首次出现位置的字符串的下标值. var src="images ...

  4. MYSQL语句中SELECT语句及其子句的执行顺序

    SELECT语句的执行的逻辑查询处理步骤:(8)SELECT (9)DISTINCT(11)<TOP_specification> <select_list>(1)FROM & ...

  5. js动态判断密码强度&&实用的 jQuery 代码片段

    // 网上拷贝的代码,效果不太好需要自己调整<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...

  6. 可辨别iPhone真假的网址

    在如下的网址中输入iPhone的序列号,可知道该iPhone的型号,生产日期,激活状态等. 1.http://www.app111.org/ 2.http://act.weiphone.com/wet ...

  7. Mtk Android 打包解包*.img

    打包/解包 boot.img, system.img, userdata.img, or recovery.img [DESCRIPTION] MTK codebase编译出来的image必须使用MT ...

  8. 《OD学hadoop》第四周0716

    7.16 一.回顾 二.HDFS Federation(联盟) Hadoop 2.2.0发布新特性 很多的大公司都在使用:BAT HDFS Federation + HDFS HA架构 互相隔开,但是 ...

  9. CodeForces Round #297 Div.2 E (中途相遇法)

    当时打比赛的时候卡在D题了,没有看E.现在看来E还是不难的. 将n个数排序后,其实不排序也是可以的,只是排序能快一半的时间. 枚举前一半能得到多少种和,放到map里面: 然后在后一半数中枚举,然后在m ...

  10. fixed兼容IE6

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...