bzoj 1193
http://www.lydsy.com/JudgeOnline/problem.php?id=1193
大范围贪心,小范围宽搜。
膜拜大神
http://blog.csdn.net/u012915516/article/details/47447703
- #include<cstdio>
- #include<cstdlib>
- #include<iostream>
- #include<fstream>
- #include<algorithm>
- #include<cstring>
- #include<string>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<map>
- #include<utility>
- #include<set>
- #include<bitset>
- #include<vector>
- #include<functional>
- #include<deque>
- #include<cctype>
- #include<climits>
- #include<complex>
- //#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj
- using namespace std;
- typedef long long LL;
- typedef double DB;
- typedef pair<int,int> PII;
- typedef complex<DB> CP;
- #define mmst(a,v) memset(a,v,sizeof(a))
- #define mmcy(a,b) memcpy(a,b,sizeof(a))
- #define fill(a,l,r,v) fill(a+l,a+r+1,v)
- #define re(i,a,b) for(i=(a);i<=(b);i++)
- #define red(i,a,b) for(i=(a);i>=(b);i--)
- #define ire(i,x) for(typedef(x.begin()) i=x.begin();i!=x.end();i++)
- #define fi first
- #define se second
- #define m_p(a,b) make_pair(a,b)
- #define SF scanf
- #define PF printf
- #define two(k) (1<<(k))
- template<class T>inline T sqr(T x){return x*x;}
- template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
- template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;}
- const DB EPS=1e-;
- inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
- const DB Pi=acos(-1.0);
- inline int gint()
- {
- int res=;bool neg=;char z;
- for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
- if(z==EOF)return ;
- if(z=='-'){neg=;z=getchar();}
- for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
- return (neg)?-res:res;
- }
- inline LL gll()
- {
- LL res=;bool neg=;char z;
- for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
- if(z==EOF)return ;
- if(z=='-'){neg=;z=getchar();}
- for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
- return (neg)?-res:res;
- }
- const int dx[]={,,,,-,-,-,-};
- const int dy[]={,-,,-,,-,,-};
- int sx,sy,ex,ey,x,y;
- int cnt;
- int vis[][];
- #define vis(i,j) vis[i+1000][j+1000]
- int head,tail;
- PII que[];
- int main()
- {
- freopen("bzoj1193.in","r",stdin);
- freopen("bzoj1193.out","w",stdout);
- int i;
- sx=gint();sy=gint();ex=gint();ey=gint();
- x=ex-sx;y=ey-sy;
- x=abs(x);y=abs(y);
- cnt=;
- while(x+y>=)
- {
- if(x<y)swap(x,y);
- if(x->*y)x-=;else x-=,y-=;
- cnt+=;
- }
- mmst(vis,-);
- que[head=tail=]=PII(,);
- vis(,)=;
- while(vis(x,y)==-)
- {
- int ax=que[head].fi,ay=que[head].se;head++;
- re(i,,)
- {
- int bx=ax+dx[i],by=ay+dy[i];
- if(vis(bx,by)==-)
- {
- que[++tail]=PII(bx,by);
- vis(bx,by)=vis(ax,ay)+;
- if(vis(x,y)!=-)break;
- }
- }
- }
- cnt+=vis(x,y);
- PF("%d\n",cnt);
- return ;
- }
bzoj 1193的更多相关文章
- bzoj 1193 贪心
如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...
- bzoj 1193 贪心+bfs
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2015 Solved: 914[Submit][Statu ...
- BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...
- 【BZOJ 1193】 [HNOI2006]马步距离
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 原问题可以等价为两个点. 然后其中一个点要移动到另外一个点. 那么我们可以把左下角那个点(对称总是可以得到一个点在左下角)放在原点的 ...
- BZOJ 1193 搜索+贪心
预处理出100*100以内的最优解 贪心走日 判断是0*4还是2*4 搞定 //By SiriusRen #include <queue> #include <cstdio> ...
- BZOJ 题解continue
1041 圆上的整点 暴力枚举 会超时 这道题很像之前一次noip模拟题(当时的我还太水了(虽然现在也很水)) x2+y2=R2 考虑变型 x2=(R+y)(R-y) int d=gcd(R,y) i ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
随机推荐
- hadoop 常用命令
hdfs dfs -mkdir -p /usr/input/hot hdfs dfs -ls / hdfs dfs -ls /usr/input hdfd dfs -cat /usr/ouput/ho ...
- 【转】windows下vs2008/2010+opencv2.2开发环境搭建
版权声明:本文为博主原创文章,未经博主允许不得转载. 1.下载安装Cmake 2.用cmake配置opencv2.2,然后编译,安装 3. 在vs2008中配置opencv2.2 4.Demo 1.下 ...
- AngularJs学习笔记5——自定义服务
前面整理了AngularJs双向数据绑定和自定义指令的相关内容,从手册上看也知道,ng部分还包括过滤器和函数,以及服务等. 过滤器:filter,就是对数据进行格式化,注意管道格式,例如: {{表达式 ...
- Jsp详解
1Jsp基础 1.1 Jsp引入 Servlet的作用: 用java语言开发动态资源的技术!!! Jsp的作用:用java语言(+html语言)开发动态资源的技术!!! Jsp就是servlet!!! ...
- 互联网程序设计c++
地址:ftp.sist.stdu.edu.cn用户名:lzh_hlw20133密码:lzhstdftp端口:2014
- jdk-tomcat环境变量设置
1.export命令直接在shell下设置 export JAVA_HOME=/home/yn4a/jdk1.6.0_16export PATH=$JAVA_HOME/bin:$PATHexport ...
- ComboBox( 下拉列表框)
一. 加载方式//class 加载方式<select id="box" class="easyui-combobox" name="box&qu ...
- angularJS环境安装
第一步: 安装node.js,进入node.js官网(http://nodejs.org/)下载安装相应的node.js版本:
- eclipse中安装genymotion
在eclipse中安装genymotion.安装genymotion需要先安装virtualbox.选择Help选项中的install new software 然后点击进去点击ADD,在locati ...
- list类型for遍历
package cn.stat.p9.map.demo; import java.util.ArrayList; public class Listfor { /** * @param args */ ...