题目链接:Gym - 101492H

自己的纯暴力做法:

 /* */
# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <cmath>
# include <ctime>
# include <climits>
# include <memory>
# include <functional>
# include <algorithm>
# include <bitset>
# include <set>
# include <map>
# include <stack>
# include <vector>
# include <deque>
# include <queue>
# include <iomanip>
# include <utility>
using namespace std; # define lson l,m,rt<<
# define rson r,m+,rt<<|
# define lowbit(x) (x&(-x))
# define lcm(a,b) (a*b/__gcd(a,b))
typedef long long ll;
const ll mod=1e9+;
const int maxn=;
const double pi=acos(-1.0);
const int eps=1e-; int main()
{
char c;
ll x0, y0, xd, yd;
int flag1=-, flag2=-;
scanf("%lld %lld %c", &x0, &y0, &c);
scanf("%lld %lld", &xd, &yd); ll x=xd-x0;
ll y=yd-y0;
if( x== && y== )//在原位
{
printf("0\n");
} else if( x== && y> )//在上方
{
if( c=='N' )
{
//printf("%lld\n", y);
printf("1\n");
printf("A %lld\n", y);
}
else if( c=='E' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", y);
} else if( c=='S' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", y);
} else if( c=='O')
{
printf("%d\n", +);
printf("D\n");
printf("A %lld\n", y);
}
} else if( x== && y< )//在下方
{
y = -y;
if( c=='S')
{
printf("1\n");
printf("A %lld\n", y);
} else if( c=='E' )
{
printf("%d\n", +);
printf("D\n");
printf("A %lld\n", y);
} else if( c=='N' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", y);
} else if( c=='O' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", y);
}
} else if( x> && y== )//在右边
{
if( c=='E' )
{
printf("1\n");
printf("A %lld\n", x);
} else if( c=='S' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", x);
} else if( c=='O' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", x);
} else if( c=='N' )
{
printf("%d\n", +);
printf("D\n");
printf("A %lld\n", x);
}
} else if(x< && y== )//在左边
{
x=-x;
if( c=='O' )
{
printf("1\n");
printf("A %lld\n", x);
} else if( c=='N' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", x);
} else if( c=='E' )
{
printf("%d\n", +);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", x);
} else if( c=='S' )
{
printf("%d\n", +);
printf("D\n");
printf("A %lld\n", x);
}
} else if( x> && y> )//在右上方
{
if( c=='N' )
{
printf("%d\n", ++);
printf("A %lld\n", y);
printf("D\n");
printf("A %lld\n", x);
} else if( c=='E' )
{
printf("%d\n", ++);
printf("A %lld\n", x);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", y);
} else if( c=='S' )
{
printf("%d\n", +++);
printf("D\n");
printf("D\n");
printf("A %lld\n", y);
printf("D\n");
printf("A %lld\n", x);
} else if( c=='O')
{
printf("%d\n", +++);
printf("D\n");
printf("A %lld\n", y);
printf("D\n");
printf("A %lld\n", x);
}
} else if( x> && y< )//在右下
{
y=-y;
if( c=='S' )
{
printf("%d\n", ++);
printf("A %lld\n", y);
for(int i=; i<; i++ )
{
printf("D\n");
}
printf("A %lld\n", x);
} if( c=='O')
{
printf("%d\n", +++);
printf("D\nD\n");
printf("A %lld\n", x);
printf("D\n");
printf("A %lld\n", y);
} if( c=='N' )
{
printf("%d\n", +++);
printf("D\n");
printf("A %lld\n", x);
printf("D\n");
printf("A %lld\n", y);
} if( c=='E' )
{
printf("%d\n", ++);
printf("A %lld\n", x);
printf("D\n");
printf("A %lld\n", y);
}
} else if( x< && y< )
{
x = -x;
y = -y;
if( c=='S' )
{
printf("%d\n", ++);
printf("A %lld\n", y);
printf("D\n");
printf("A %lld\n", x);
} if( c=='O' )
{
printf("%d\n", ++);
printf("A %lld\n", x);
printf("D\nD\nD\n");
printf("A %lld\n", y);
} if( c=='N' )
{
printf("%d\n", +++);
printf("D\nD\n");
printf("A %lld\n", y);
printf("D\n");
printf("A %lld\n", x);
} if( c=='E' )
{
printf("%d\n", +++);
printf("D\n");
printf("A %lld\n", y);
printf("D\n");
printf("A %lld\n", x);
}
} else if( x< && y> )//在左上
{
x=-x;
if( c=='N' )
{
printf("%d\n", ++);
printf("A %lld\n", y);
printf("D\nD\nD\n");
printf("A %lld\n", x);
} if( c=='E' )
{
printf("%d\n", +++);
printf("D\nD\n");
printf("A %lld\n", x);
printf("D\n");
printf("A %lld\n", y);
} if( c=='S' )
{
printf("%d\n", +++);
printf("D\n");
printf("A %lld\n", x);
printf("D\n");
printf("A %lld\n", y);
} if( c=='O' )
{
printf("%d\n", ++);
printf("A %lld\n", x);
printf("D\n");
printf("A %lld\n", y);
}
}
return ;
}

后来看别人的代码才知道“模拟”

 /* */
# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <cmath>
# include <ctime>
# include <climits>
# include <memory>
# include <functional>
# include <algorithm>
# include <bitset>
# include <set>
# include <map>
# include <stack>
# include <vector>
# include <deque>
# include <queue>
# include <iomanip>
# include <utility>
using namespace std; # define lson l,m,rt<<
# define rson r,m+,rt<<|
# define lowbit(x) (x&(-x))
# define lcm(a,b) (a*b/__gcd(a,b))
typedef long long ll;
const ll mod=1e9+;
const int maxn=;
const double pi=acos(-1.0);
const int eps=1e-; char s[]={'N', 'E', 'S', 'O', 'N', 'E', 'S'}; int _find(char c, int k)
{
for(int i=; 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, ), k2, k3; if( a==x )
k2=;
if( b==y )
k3=; 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)+<<endl;//max(k2,k3)是求一定要转够的书,2是两次直走步骤
int px=fabs(x-a);
int py=fabs(y-b); if( k2>k3 )
{
for(int i=; 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=; 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<<<<endl; else if( x==a )
{
if( b>y )//正上方
n='N';
else//正下方
n='S'; k2=_find(n, k1)-k1;
cout<<k2+<<endl;
for(int i=; 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+<<endl;
for(int i=; i<k3; i++ )
cout<<"D"<<endl;
cout<<"A "<<fabs(a-x)<<endl;
}
}
}
return ;
}

Programming a robot的更多相关文章

  1. Robot Framework 快速入门_英文版

    Copyright © Nokia Siemens Networks 2008 Licensed under the Apache License, Version 2.0 Table of Cont ...

  2. (一)ROS系统入门 Getting Started with ROS 以Kinetic为主更新 附课件PPT

    ROS机器人程序设计(原书第2版)补充资料 教案1 ROS Kinetic系统入门 ROS Kinetic在Ubuntu 16.04.01 安装可参考:http://blog.csdn.net/zha ...

  3. MRPT - Mobile Robot Programming Toolkit

    1. https://www.mrpt.org/Building_and_Installing_Instructions#1_Prerequisites P1. error C2371: “int32 ...

  4. Mujin Programming Challenge 2017A - Robot Racing【思维题】

    题意: 给你n个人的位置,每个人能往后跳一格或两格到无人的位置,跳到0位置,这个人消失,n个人消失组成一个排列,问有多少种排列. 思路: 额,搞了一整场这个A...代码也巨挫了. 处理成1,3,5,7 ...

  5. Learning ROS for Robotics Programming - Second Edition(《学习ROS机器人编程-第二版》)

    Learning ROS for Robotics Programming - Second Edition <学习ROS机器人编程-第二版> ----Your one-stop guid ...

  6. CSUFT 1002 Robot Navigation

    1002: Robot Navigation Time Limit: 1 Sec      Memory Limit: 128 MB Submit: 4      Solved: 2 Descript ...

  7. [LeetCode] 63. Unique Paths II_ Medium tag: Dynamic Programming

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  8. Robot Framework - 一些练习

    01 - 安装Robot Framework TA环境 根据系统请选择对应的版本包来安装,下面是以Win7-64bit系统为例,来说明如何搭建一个可以运行练习三test case的RF TA环境. 1 ...

  9. [LeetCode] 62. Unique Paths_ Medium tag: Dynamic Programming

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

随机推荐

  1. C# 获取系统字体方法

    //需要引用命名空间 using System.Drawing; using System.Drawing.Text; //获取系统字体方法 public dynamic GetFontNames() ...

  2. 静态工具类注入service的方法

    http://blog.sina.com.cn/s/blog_6e2d53050102wl3x.html

  3. 利用nfs-client-provisioner动态提供Kubernetes后端存储卷

    原文:https://www.kubernetes.org.cn/3894.html 利用NFS client provisioner动态提供Kubernetes后端存储卷 本文翻译自nfs-clie ...

  4. js-Date对象(九)

    一.Date对象的创建1.new Date()[创建当前时间对象]eg: var date = new Date(); console.log(date); //Thu Jul 18 2019 18: ...

  5. 纯css实现省略号,兼容火狐,IE9,chrome

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. SOFABoot&SOFATracer

    SOFABoot快速开始 SOFABoot介绍 SOFABoot 是蚂蚁金服开源的基于 Spring Boot 的研发框架,它在 Spring Boot 的基础上,提供了诸如 Readiness Ch ...

  7. java实现在线预览--poi实现word、excel、ppt转html

    java实现在线预览 - -之poi实现word.excel.ppt转html 简介 java实现在线预览功能是一个大家在工作中也许会遇到的需求,如果公司有钱,直接使用付费的第三方软件或者云在线预览服 ...

  8. 前端动态效果小结(jQuery)

    1.easyUI(jQuery) http://www.jeasyui.net/demo/954.html

  9. 第一个 macOS 64位 kbmmw 服务器

    前几天,Delphi 10.3.2 正式发布,这个小版本升级却增加了一个非常大的平台支持,增加了 macos 64位的支持,今天做一个macOS 64位的kbmmw应用,让kbmmw 服务器的应用更广 ...

  10. Java开发环境之MySql

    查看更多Java开发环境配置,请点击<Java开发环境配置大全> 叁章:MySql安装教程 1)去官网下载MySql安装包 https://www.mysql.com/downloads/ ...