Codeforces 3A Shortest Path of the King
来源:互联网 发布:中国为什么封闭网络 编辑:程序博客网 时间:2024/04/28 17:04
有人说用BFS,但我认为这大可不必。计算从S点到T点需横走多少步,纵走多少步,再把横纵最大限度合并成为斜走,如有剩下再横/纵走即可。
#include "stdio.h"int min(int a,int b){return a<b?a:b;}int abs(int x){return x>=0?x:(-x);}int main(){char X1,Y1,X2,Y2,dirheng,dirshu;int heng,shu,ans,i;scanf("%c%c\n%c%c\n",&X1,&Y1,&X2,&Y2);heng=X2-X1;shu=Y2-Y1;if(heng>=0)dirheng='L';else dirheng='R';if(shu>=0)dirshu='D';else dirshu='U';ans=min(heng,shu)+abs(abs(heng)-abs(shu));for(i=1;i<=min(heng,shu);i++)printf("%c%c\n",dirheng,dirshu);for(i=1;i<=abs(abs(heng)-abs(shu));i++){if(abs(heng)>abs(shu))printf("%c\n",dirheng);else printf("%c\n",dirshu);}return 0;}
0 0
- codeforces 3A - Shortest path of the king
- Codeforces 3A Shortest path of the king BFS
- codeforces 3A Shortest path of the king
- Codeforces 3A Shortest Path of the King
- Codeforces Round #3A. Shortest path of the king
- Codeforces Beta Round #3 A. Shortest path of the king
- Codeforces 3A. Shortest path of the king(贪心:暴力)
- CodeForces 3A - Shortest path of the king
- 【codeforces#3A】Shortest path of the king
- CodeForces #3A. Shortest path of the king
- CodeForces 3A Shortest path of the king(水题)
- Codeforces 3A Shortest path of the king(BFS???NO!!)
- Codeforces #3 A Shortest path of the king
- [Codeforces]3A. Shortest path of the king
- Codeforces 3A Shortest path of the king
- codeforces 3-A. Shortest path of the king(暴力)
- 3A - Shortest path of the king
- CodeForces 3A Shortest path of the king(贪心)——Codeforces Beta Round #3
- 控件
- ARM体系中存储系统
- HDU 1051: Wooden Sticks(贪心)
- hdu 4613 Points( KMP 图形学)
- 关于DSP C6727外部中断的用法
- Codeforces 3A Shortest Path of the King
- Windows 下正则表达式库 re2 在 C++ 和 Python 中的编译和使用
- swift菜鸟入门视频教程-11-方法
- Lua学习笔记(三)——协同程序
- POJ2377 Bad Cowtractors 最小生成树
- unity3D游戏开发实战原创视频讲座系列12之U3D的2D开发新方法实战
- 学习笔记 Android.mk 自动搜索
- Codeforces 5A
- Solr4.7.2启动时的Index locked for write for core问题分析