Codeforces #3 A Shortest path of the king
来源:互联网 发布:高中生很敏感知乎 编辑:程序博客网 时间:2024/05/30 23:25
题目链接 http://codeforces.com/problemset/problem/3/A
走过的格的值相乘后后缀的0最少,统计路径中中 2和5最少的数就行,有值0的话看另外判断,可能有路径后缀的0没有。
下面ac代码
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <string>#include <map>using namespace std;typedef long long lld;/*方向 R U L D RU RD LU LD 0 1 2 3 4 5 6 7*/int main(){ char x1,x2; int y1,y2; int dir[8]={0}; while(cin>>x1>>y1>>x2>>y2) { memset(dir,0,sizeof(0)); int xcha=x2-x1; int ycha=y2-y1; if(xcha==0&&ycha==0) cout<<0; else if(xcha>=0&&ycha>=0) { int flag=0; while(xcha>0&&ycha>0) { ycha--; xcha--; dir[4]++; flag++; } while(xcha>0) { xcha--; dir[0]++; flag++; } while(ycha>0) { ycha--; dir[1]++; flag++; } cout<<flag<<endl; } else if(xcha<=0&&ycha<=0) { int flag=0; while(xcha<0&&ycha<0) { ycha++; xcha++; dir[7]++; flag++; } while(xcha<0) { xcha++; dir[2]++; flag++; } while(ycha<0) { ycha++; dir[3]++; flag++; } cout<<flag<<endl; } else if(xcha<=0&&ycha>=0) { int flag=0; while(xcha<0&&ycha>0) { ycha--; xcha++; dir[6]++; flag++; } while(xcha<0) { xcha++; dir[2]++; flag++; } while(ycha>0) { ycha--; dir[1]++; flag++; } cout<<flag<<endl; } else if(xcha>=0&&ycha<=0) { int flag=0; while(xcha>0&&ycha<0) { ycha++; xcha--; dir[5]++; flag++; } while(xcha>0) { xcha--; dir[0]++; flag++; } while(ycha<0) { ycha++; dir[3]++; flag++; } cout<<flag<<endl; } while(dir[0]--) cout<<"R"<<endl; while(dir[1]--) cout<<"U"<<endl; while(dir[2]--) cout<<"L"<<endl;; while(dir[3]--) cout<<"D"<<endl;; while(dir[4]--) cout<<"RU"<<endl;; while(dir[5]--) cout<<"RD"<<endl;; while(dir[6]--) cout<<"LU"<<endl;; while(dir[7]--) cout<<"LD"<<endl;; cout<<endl;/*方向 R U L D RU RD LU LD 0 1 2 3 4 5 6 7*/ } 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
- mysql limit 优化
- CodeForces 659 C. Tanya and Toys
- POJ 1273 Drainage Ditches (最大流)
- studio快捷键
- 最短路径问题的相关算法
- Codeforces #3 A Shortest path of the king
- 指数函数方法
- JSP标签实现分页功能(ORM-mybatis)
- 复制构造函数的不同调用
- js中关于IE与DOM对浏览器的兼容性
- redigo的redis.Pool 配置参数调优
- 新浪云服务器端安装微擎
- 二维数组传递参数问题
- tomcat热部署实现文件下载