预处理出100*100以内的最优解

贪心走日

判断是0*4还是2*4

搞定

//By SiriusRen
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
int sx,sy,ex,ey,vis[105][105],ans;
char xx[]={2,2,1,1,-1,-1,-2,-2},yy[]={1,-1,2,-2,2,-2,1,-1};
bool check(int x,int y){
return x>=1&&x<=100&&y>=1&&y<=100;
}
void BFS(){
queue<pair<int,int> >q;
q.push(make_pair(50,50));
vis[50][50]=1;
while(!q.empty()){
int dx=q.front().first,dy=q.front().second;q.pop();
for(int i=0;i<8;i++){
int tx=dx+xx[i],ty=dy+yy[i];
if(check(tx,ty)&&!vis[tx][ty]){
vis[tx][ty]=vis[dx][dy]+1;
q.push(make_pair(tx,ty));
}
}
}
}
int main(){
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
BFS();
int rx=abs(sx-ex),ry=abs(sy-ey);
while(rx+ry>50){
if(rx<ry)swap(rx,ry);
if(ry>2)rx-=4,ry-=2;
else rx-=4;
ans+=2;
}
ans+=vis[rx+50][ry+50];
printf("%d\n",ans-1);
}

BZOJ 1193 搜索+贪心的更多相关文章

  1. [CQOI2012]模拟工厂 题解(搜索+贪心)

    [CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P26 ...

  2. bzoj 1193 贪心

    如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...

  3. BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...

  4. bzoj 1193 贪心+bfs

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

  5. bzoj 1193

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

  6. HDU 6034---Balala Power!(搜索+贪心)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  7. [NOIP 2010]饮水入城 搜索+贪心

    考试的时候写了个dfs找出来了,最后处理的时候想到了贪心,但是正确性没有想通.然后想了想动规,也没想通.最后没办法,用状态的话用了个状压,弄了40分. 正解是bfs+贪心.Dfs也有过的. 下面题解引 ...

  8. 洛谷 2668&2540 斗地主——搜索+贪心+dp

    题目:https://www.luogu.org/problemnew/show/P2540 发现如果没有顺子,剩下的可以贪心.所以搜索顺子怎么出,然后贪心. 这样只能过不加强版.原因是贪心的时候难以 ...

  9. SPOJ:Strange Waca(不错的搜索&贪心&剪枝)

    Waca loves maths,.. a lot. He always think that 1 is an unique number. After playing in hours, Waca ...

随机推荐

  1. python登录注册改良版

    #在执行本脚本的时候,需要先注册,否则会报字符串不匹配sum=3while True: #如果条件为真,则一直循环 print("先注册,在登录") print("1.注 ...

  2. centos部署nginx服务

    1.准备安装程序 pcrl-8.43.tar.gz  zlib-1.2.11.tar.gz  openssl-1.0.1j.tar.gznginx-1.9.9.tar.gz 2.将下载的包拷贝到/us ...

  3. Fastlane基础介绍

    Fastlane是什么 Git地址: Fastlane 文档地址:Fastlane Document Fastlane是一整套的客户端CICD工具集合.Fastlane可以非常快速简单的搭建一个自动化 ...

  4. CAD二次开发(02)-添加对象到模型空间

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. linux的一页是多大

    命令 getconf PAGESIZE 结果为4096,即一页=4096字节=4KB(注意是Byte,1B=8bit) 在使用mmap映射函数时,它的实际映射单位也是以页为单位的,即不过我们把MAP_ ...

  6. wipefs进程是啥,占用了百分之90多的cpu

    http://www.cnblogs.com/liuchuyu/p/7490338.html

  7. 洛谷——P1428 小鱼比可爱

    https://www.luogu.org/problem/show?pid=1428 题目描述 人比人,气死人:鱼比鱼,难死鱼.小鱼最近参加了一个“比可爱”比赛,比的是每只鱼的可爱程度.参赛的鱼被从 ...

  8. chrome默认打开隐身模式

    chrome图标右键属性,在“目标”后添加参数“ --incognito”(注意是双短划线,不包括双引号,双短划线前加一空格)就可以直接以隐身模式启动chrome了

  9. android将String转化为MD5的方法+一些String经常使用的方法

    public class StringUtils { public static String MD5Encode(String origin) { String resultString = nul ...

  10. 3、Python字典集合

    2.3字典 字典是键值对的无序可变序列.键值之间用冒号隔开,相邻元素之间用逗号隔开,所有元素放在大括号之间{},键可以是Python中所有不可变的数据,不能用列表.元组.字典作为字典的键,键不可重复, ...