Programming a robot
题目链接: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的更多相关文章
- Robot Framework 快速入门_英文版
Copyright © Nokia Siemens Networks 2008 Licensed under the Apache License, Version 2.0 Table of Cont ...
- (一)ROS系统入门 Getting Started with ROS 以Kinetic为主更新 附课件PPT
ROS机器人程序设计(原书第2版)补充资料 教案1 ROS Kinetic系统入门 ROS Kinetic在Ubuntu 16.04.01 安装可参考:http://blog.csdn.net/zha ...
- MRPT - Mobile Robot Programming Toolkit
1. https://www.mrpt.org/Building_and_Installing_Instructions#1_Prerequisites P1. error C2371: “int32 ...
- Mujin Programming Challenge 2017A - Robot Racing【思维题】
题意: 给你n个人的位置,每个人能往后跳一格或两格到无人的位置,跳到0位置,这个人消失,n个人消失组成一个排列,问有多少种排列. 思路: 额,搞了一整场这个A...代码也巨挫了. 处理成1,3,5,7 ...
- Learning ROS for Robotics Programming - Second Edition(《学习ROS机器人编程-第二版》)
Learning ROS for Robotics Programming - Second Edition <学习ROS机器人编程-第二版> ----Your one-stop guid ...
- CSUFT 1002 Robot Navigation
1002: Robot Navigation Time Limit: 1 Sec Memory Limit: 128 MB Submit: 4 Solved: 2 Descript ...
- [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 ...
- Robot Framework - 一些练习
01 - 安装Robot Framework TA环境 根据系统请选择对应的版本包来安装,下面是以Win7-64bit系统为例,来说明如何搭建一个可以运行练习三test case的RF TA环境. 1 ...
- [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 ...
随机推荐
- Spring-Boot之Admin服务监控-9
一.Spring Boot Admin用于管理和监控一个或者多个Spring Boot程序.Spring Boot Admin分为Server端和Client 端,Client端可以通过向Http S ...
- 表单提交学习笔记(一)—利用jquery.form提交表单(后台.net MVC)
起因:一开始想用MVC本身的Form提交方法,但是提交完之后想进行一些提示,MVC就稍显不足了,最后用jquery插件---jquery.form.js,完美解决了问题~~ 使用方法 一.下载jque ...
- 使用Filezilla Server配置FTP服务器
一.下载Filezilla Server 官网网址:https://filezilla-project.org 二.安装Filezilla Server Filezilla Server的安 ...
- 局域网电脑禁止ping通的解决方法
方法1:命令行模式进入服务器后 点击 开始——运行 输入命令:netsh firewall set icmpsetting 8这样就可以在外部ping到服务器了 非常简单实用!同样道理,如果想禁止Pi ...
- x.append()增加不同维度的区别
b=np.array([[7,2],[2,4],[3,6],[7,8],[9,10]])print(b)print(type(b)) # 结果显示为nunmpy 数组a=[]for i in rang ...
- 冠捷显示成功的信息化建设(MES应用案例)
企业介绍 冠捷科技集团是驰誉全球的大型高科技跨国企业,产品包括彩色显示器( CRT monitor ).液晶显示器( LCD monitor ).液晶电视( LCD-TV )与等离子电视( PDP ) ...
- 个人项目 wc(java实现)
一.Github网址: https://github.com/Clarazhangbw/Wc.exe 二.PSP表 PSP2.1 Personal Software Process Stages 预估 ...
- ffmpeg音频视频转格式工具使用
ffmpeg是音频视频编解码工具,是一个开源项目,可以改变视频格式,比如mp4格式转ogg格式(有格式工厂,多这个东西纯属自己娱乐一下) 官方网址:www.ffmpeg.org 下载后找到ffmpeg ...
- 《大象 Thinking in UML》读书笔记:软件开发——从现实世界到对象世界
参考:Process-oriented vs. Object-oriented 前言 软件行业在采用OO的思想后,从一开始只对编码使用OO,到现在“分析-设计-编码”全部环节使用OO,形成了OOA.O ...
- Python的包管理工具
Python的包管理工具 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.为什么使用包管理 Python的模块或者源文件直接可以复制到目标项目目录中,就可以导入使用了. 但是为了 ...