bzoj1193
#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的更多相关文章
- [BZOJ1193][HNOI2006]马步距离(贪心+dfs)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1193 分析: 首先小范围可以直接暴力.(其实只要用上题目中的表就行了) 如果范围比较大 ...
- bzoj1193: [HNOI2006]马步距离
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MB Description 在国际象棋和中国象棋中,马的移动规则相同,都是走&q ...
- bzoj1193 马步距离
Description 求点(xs,ys)走马步到(xp,yp)的最小步数 Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Out ...
- [BZOJ1193][HNOI2006]马步距离 大范围贪心小范围爆搜
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1988 Solved: 905[Submit][Statu ...
- 【bzoj1193】[HNOI2006]马步距离
[HNOI2006]马步距离 Description Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Output 含一个整数,表示从 ...
- BZOJ1193 马步距离 (贪心)
恶心的题目= = #include <cstdio> #include <cmath> #include <algorithm> ][]={{,,,,},{,,,, ...
- bzoj1193: [HNOI2006]马步距离(贪心+bfs)
1193: [HNOI2006]马步距离 题目:传送门 题解: 毒瘤题... 模拟赛时的一道题,刚开始以为是一道大难题...一直在拼命找规律 结果.... 还是说正解吧: 暴力的解法肯定是直接bfs, ...
- bzoj 1193
http://www.lydsy.com/JudgeOnline/problem.php?id=1193 大范围贪心,小范围宽搜. 膜拜大神 http://blog.csdn.net/u0129155 ...
- [转载]hzwer的bzoj题单
counter: 664BZOJ1601 BZOJ1003 BZOJ1002 BZOJ1192 BZOJ1303 BZOJ1270 BZOJ3039 BZOJ1191 BZOJ1059 BZOJ120 ...
随机推荐
- 下载的时候如果文件名是中文就变成zip.zip
struts2 /WEB-INF/web.xml <?xml version="1.0" encoding="UTF-8"?> <web-ap ...
- USACO Section 2.4: Fractions to Decimals
乍看题目感觉有难度,实际分析后其实是道简单题 /* ID: yingzho1 LANG: C++ TASK: fracdec */ #include <iostream> #include ...
- PHP的面向对象编程
面向对象编程的概念: 不同的作者之间说法可能不一样,但是一个OOP语言必须有以下几方面: 抽象数据类型和信息封装 继承 多态 在PHP中是通过类来完成封装的: <?php class Somet ...
- Android init.rc解析【转】
转自:http://www.linuxidc.com/Linux/2014-10/108438.htm 本文主要来自$Android_SOURCE/system/init/readme.txt的翻译. ...
- CF-358D-Dima and Hares【T^T+*^*】
[文章标题打着转载,是因为不是自己想出来的解题,但下面的文字是自己敲的[~捂脸*>_<*~]] 题目就不贴了~~~DP+greedy的题.弱爆了看别人的代码思路过的.T^T但还是自己复述一 ...
- samba linux windows 请联系管理员
在使用Samba进行建立Window与Linux共享时,要是不能访问,出现“您可能没有权限使用网络资源”, 那就是SELinux在作怪了 要是想让共享目录能访问,可以使用命令 #setenforce ...
- 51nod 1117 聪明的木匠 (贪心)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1117 跟挑战程序书上例题一样,将要切割的n断木板,分别对应二叉树树的叶子 ...
- 台湾P2P平台
2014年6月28日下午1:30,“2014两岸三地P2P网贷行业高峰论坛”在上海会展中心友谊会堂如期举行,现场高朋满座,来自全国各地的众多知名P2P网站平台的负责人参与了讨论,并就当前P2P行业的一 ...
- hibernate基础(1)
hibernate基础1.hibernate介绍与动手入门体验 问题:模型不匹配(java对象模型与数据库关系模型不匹配) 解决: 1.使用JDBC手工转换 2.使用ORM(Obje ...
- 【笨嘴拙舌WINDOWS】GDI绘制区域
在默认情况下,Gdi绘画操作的使用白纸(窗口的客户区)黑字(Pen的颜色)!前面我们已经讲过如何改笔,现在来学习改变白纸(GDI的绘制区域) 正常的纸为一个矩形形状!有时候小孩不小心撕掉纸的一角,不小 ...