node搜索codeforces 3A - Shortest path of the king
发一下牢骚和主题无关:
搜索,最短路都可以
人生是洁白的画纸,我们每个人就是手握各色笔的画师;人生也是一条看不到尽头的长路,我们每个人则是人生道路的远足者;人生还像是一块神奇的土地,我们每个人则是手握农具的耕耘者;但人生更像一本难懂的书,我们每个人则是孜孜不倦的读书郎。
#include<stdio.h>
#include<string.h>
#include<queue>
#define inf 0x3fffffff
using namespace std;
int map[65][65];
int sx,sy,ex,ey;
int dis[10][10],link[10][10];
char str[8][3]={"D","R","U","L","RD","LU","LD","RU"};
int dir[8][2]={1,0,0,1,-1,0,0,-1,1,1,-1,-1,1,-1,-1,1};
struct node
{
int x,y,w;
friend bool operator < (node a, node b)
{
return a.w>b.w;
}
}cur,next;
int judge(int x,int y)
{
if(x>=1&&x<=8&&y>=1&&y<=8)
return 1;
return 0;
}
void bfs()
{
priority_queue<node> Q;
int x,y,i,w,j;
for(i=0;i<9;i++)
for(j=0;j<9;j++)
dis[i][j]=inf;
cur.x=sx;cur.y=sy;cur.w=0;
dis[sx][sy]=0;
Q.push(cur);
while(!Q.empty())
{
cur=Q.top();
Q.pop();
if(cur.x==ex&&cur.y==ey)return;
for(i=0;i<8;i++)
{
next.x=x=cur.x+dir[i][0];
next.y=y=cur.y+dir[i][1];
if(judge(x,y)==0)continue;
next.w=w=cur.w+1;
if(w<dis[x][y])
{
dis[x][y]=w;
Q.push(next);
link[x][y]=i;
}
} }
}
void prinf(int x,int y)
{
if(x==sx&&y==sy)return ;
int i=link[x][y];
prinf(x-dir[i][0],y-dir[i][1]);
printf("%s\n",str[i]);
}
int main()
{
char s1[5],s2[5];
while(scanf("%s%s",s1,s2)!=-1)
{
sy=s1[0]-'a'+1;
sx=9-(s1[1]-'0');
ey=s2[0]-'a'+1;
ex=9-(s2[1]-'0');
bfs();
printf("%d\n",dis[ex][ey]);
prinf(ex,ey);
}
return 0;
}
文章结束给大家分享下程序员的一些笑话语录: 话剧:程序员过沟
本剧内容纯属虚构,如有雷同……HEHE……俺也没办法了。
话说某市街道改建,某某软件公司门口横七竖八挖了几条大沟。一群程序员(SDK程序员赵某,VB程序员钱某,VC程序员孙某,DELPHI程序员李某)下班从公司里出来,看到门前的几条沟,于是各显神通……门前第一条沟也就半米来宽,SDK程序员赵某二话没说,轻轻一跃跳了过去,看到其它人纷纷把随身携带的公文包(类库)横在沟上踩着过沟,不屑地说,这么小一条沟,犯得着小题大做用那个吗?看我多么轻松多么洒脱多么……多么……(众人皆怒目横视之……)
接着第二条沟有点宽度。SDK程序员赵某还是还是一马当先,飞跃而起……不好,还差一点才到……幸好凭着多年的(跳远?编程?)经验,单手抓住沟沿,颤巍巍地爬了上来,嘴里还念念有词“高手就是高手啊,虽然差一点就……不过毕竟……HEHE……跳远是过沟的基础嘛,有基础(SDK)就有一切的说……”(众人作瞠目结舌状……)看到别人跳过去了,可自己又跳不了那么远,只好再想办法了……VB程序员钱某,DELPHI程序员李某打开手提,连上手机,开始上网找可供过沟的控件……VC程序员孙某却不慌不忙,打开公文包,把几块衬板拆了下来,然后三下五除二拼成一个简易木桥……“虽然这几个板子(类)做得不怎么样,不过先把这个项目应付过去,有时间我自己做一个好了……”于是踩着板子过了沟。
这时钱某和李某也分别找到了合适的东东。钱某找到的是“钢丝绳.ocx”,安装简单,使用方便,拉出一头,对孙某说“大虾,顺手拉兄弟一把……”,于是把绳子系在沟两边的绿化树木上,踩着钢丝就过了沟。刚刚站稳就四方作揖,“小生这里有礼了”。这时一戴着黄袖圈的老太太跳了出来,抓住钱某,“破坏绿化树木,罚款XXXX元,交钱,交钱,交钱!”(老人家作双枪老太婆怒视伪军状
……钱某被逼无奈,只好边掏钱,边对着后台叫道“导演,我这可是因公牺牲,不给个烈士称号也得报销”,后台一个臭鸡蛋飞出,“叫什么叫,我这个月的粮饷还不知哪里去领呢,都什么时代了,你不下岗都不错了……”)
李某看着刚刚好不容易从台湾拖回来的“铝条.ZIP”
---------------------------------
原创文章 By
node和搜索
---------------------------------
node搜索codeforces 3A - Shortest path of the king的更多相关文章
- 3A. Shortest path of the king
给你一个的棋盘, 问:从一个坐标到达另一个坐标需要多少步? 每次移动可以是八个方向. #include <iostream> #include <cmath> #inclu ...
- Codeforces Beta Round #3 A. Shortest path of the king 水题
A. Shortest path of the king 题目连接: http://www.codeforces.com/contest/3/problem/A Description The kin ...
- Codeforces-A. Shortest path of the king(简单bfs记录路径)
A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...
- Codeforces 845G Shortest Path Problem?
http://codeforces.com/problemset/problem/845/G 从顶点1dfs全图,遇到环则增加一种备选方案,环上的环不需要走到前一个环上作为条件,因为走完第二个环可以从 ...
- Codeforces 938G Shortest Path Queries [分治,线性基,并查集]
洛谷 Codeforces 分治的题目,或者说分治的思想,是非常灵活多变的. 所以对我这种智商低的选手特别不友好 脑子不好使怎么办?多做题吧-- 前置知识 线性基是你必须会的,不然这题不可做. 推荐再 ...
- Codeforces Beta Round #3 A. Shortest path of the king
标题效果: 鉴于国际棋盘两点,寻求同意的操作,是什么操作的最小数量,在操作过程中输出. 解题思路: 水题一个,见代码. 以下是代码: #include <set> #include < ...
- A - Shortest path of the king (棋盘)
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...
- Shortest path of the king
必须要抄袭一下这个代码 The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose h ...
- CF3A Shortest path of the king
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...
随机推荐
- Android 调用系统的邮箱app发送邮件
第一种: String[] email = { "3802**92@qq.com" }; // 需要注意,email必须以数组形式传入 Intent intent = new In ...
- Cocos2d提供的字体(图文并茂)
1.AppleGothic CCLabelTTF *myLabel = [CCLabelTTF labelWithString:@"AppleGothic" fontName:@& ...
- solr4.5配置中文分词器mmseg4j
solr4.x虽然提供了分词器,但不太适合对中文的分词,给大家推荐一个中文分词器mmseg4j mmseg4j的下载地址:https://code.google.com/p/mmseg4j/ 通过以下 ...
- 实时通讯库 libre/librem/restund/baresip
http://www.creytiv.com/ 源码下载 libre Toolkit library for asynchronous network IO with protocol stacks ...
- HTTP协议中的长连接和短连接(keep-alive状态)
什么是长连接 HTTP1.1规定了默认保持长连接(HTTP persistent connection ,也有翻译为持久连接),数据传输完成了保持TCP连接不断开(不发RST包.不四次握手),等待在同 ...
- 20、内存溢出(Out of Memory)
内存引用(释放强引用) Object obj=new Object(); obj = null; 内存引用(使用软引用) 软引用是主要用于内存敏感的高速缓存.在jvm报告内存不足之前会清 除所 ...
- HDU 4911 Inversion
http://acm.hdu.edu.cn/showproblem.php?pid=4911 归并排序求逆对数. Inversion Time Limit: 2000/1000 MS (Java/ ...
- 多校1005 HDU5785 Interesting (manacher)
// 多校1005 HDU5785 Interesting // 题意:给你一个串,求相邻两个回文串左边端点*右边端点的和 // 思路:马拉车算出最长回文半径,求一个前缀和,既得到每个点对答案的贡献. ...
- matplotlib绘制三维图
本文参考官方文档:http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html 起步 新建一个matplotlib.figure.Figure对象, ...
- web.py网页模板中使用jquery
由于$是web.py针对模板的保留字符,所以在模板文件内不能直接使用$("#id")的格式. 解决办法: 1.$$("#id")可以避免$被误解析 2.jque ...