#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. Android 时间格式的正则表达式

    //日期格式yyyy  PatternsDict.date_y= /^(\d{4})$/; //日期格式yyyy-mm  PatternsDict.date_ym= /^(\d{4})-(0\d{1} ...

  2. JSP的设计模式

    1.JSP模型1(JSP+JavaBean) JSP页面负责处理请求,并将响应发送给客户端.JSP页面文件包括:login.html.loginchk.jsp.welcome.jsp.JavaBean ...

  3. mencoder mencoder 安装使用及常用参数

    mencoder 安装及使用 1.安装:            参考:http://hi.baidu.com/putword/item/e5910a187d2aed14e2f9867f 2.合并视频: ...

  4. 【Cocosd2d实例教程二】地图编辑器Tiled的安装使用

    (转载请注明出处:http://blog.csdn.net/buptgshengod) 我们知道cocos2d是一个基于2d效果的游戏引擎,那么如果制作一个2d手机游戏我们需要创建相应的游戏画面,而c ...

  5. PowerDesigner导出表到word

    一.模版修改 在导出表时,powerdesigner默认为我们提供了很多的模版,在工具栏中选择[Report--->Report Template]//// [被翻译成报告(Report)--- ...

  6. enable c++11 in autoconf in fucking gnu auto tools

    configure.ac => CXXFLAGS="$CXXFLAGS -std=c++14" set CXXFLAGS  => std=c++14 well done ...

  7. AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...

  8. selenium支付高版本的FireFox

    http://blog.csdn.net/pw_windgod/article/details/6537409 15:22:12.031 WARN - GET /selenium-server/dri ...

  9. Simple Factory vs. Factory Method vs. Abstract Factory【简单工厂,工厂方法以及抽象工厂的比较】

    I ran into a question on stackoverflow the other day that sort of shocked me. It was a piece of code ...

  10. pl/sql programming 02 创建并运行plsql代码

    /* * chap 02 * ------------------------------------------------- */ create or replace function wordc ...