Gym
来源:互联网 发布:类似iebook的软件 编辑:程序博客网 时间:2024/06/08 03:18
http://codeforces.com/gym/101492/problem/H
题目大意:
给出起点和终点,起点方向给出,问如何走才能最快走到终点?
解题思路:
想当然的吧西方看成’w’结果导致一直wa,最后改一下就过了。考察模拟能力。
#include<iostream>#include<cmath>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char s[]={'N','E','S','O','N','E','S'};int find(char c,int k){ for(int i=0;s[i]!='\0';i++) if(s[i]==c&&i>=k) return i;}int main(){ int a,b,x,y; char m,n,c; while(cin>>x>>y>>c>>a>>b) { int k1=find(c,0),k2,k3; if(a==x) k2=0; if(b==y) k3=0; if(a!=x&&b!=y) { if(a>x) { m='E'; if(b>y) n='N'; else if(b<y) n='S'; } else if(a<x) { m='O'; if(b>y) n='N'; else if(b<y) n='S'; } k2=find(n,k1)-k1; k3=find(m,k1)-k1; cout<<max(k2,k3)+2<<endl; int px=fabs(x-a),py=fabs(y-b); if(k2>k3) { for(int i=0;i<k3;i++) cout<<"D"<<endl; cout<<"A "<<px<<endl; for(int i=k3;i<k2;i++) cout<<"D"<<endl; cout<<"A "<<py<<endl; } else { for(int i=0;i<k2;i++) cout<<"D"<<endl; cout<<"A "<<py<<endl; for(int i=k2;i<k3;i++) cout<<"D"<<endl; cout<<"A "<<px<<endl; } } else { if(x==a&&y==b) cout<<0<<endl; else if(x==a) { if(b>y) n='N'; else n='S'; k2=find(n,k1)-k1; cout<<k2+1<<endl; for(int i=0;i<k2;i++) cout<<"D"<<endl; cout<<"A "<<fabs(b-y)<<endl; } else if(y==b) { if(a>x) m='E'; else m='O'; k3=find(m,k1)-k1; cout<<k3+1<<endl; for(int i=0;i<k3;i++) cout<<"D"<<endl; cout<<"A "<<fabs(a-x)<<endl; } } } return 0;}
阅读全文
0 0
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Fir cmd 命令行 (Ruby)发布应用
- Android短信验证(手机号注册,绑定手机号获取验证码)实例
- Android Studio 通过 gradle 构建 jar
- 拖拽最简单的实现方式[JQuery实现]
- 图像处理控件Graphics Mill for .NET更新至v9.1.28,支持PSD
- Gym
- reason: 'Cannot modify constraints for UITabBar managed by a controller'
- android Html.fromHtml font 标签支持设置字体大小和颜色
- (数学水题)Codeforces A. Kirill And The Game
- 第十三章 多种I/O复用
- .NET Core 2将Visual Basic带到了Linux和macOS平台
- string转char*
- Kafka 安装与配置
- SQL语言第一节:SQL语言分类