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 ...
随机推荐
- Linux RedHat 7 配置本地 YUM源
尽管RPM安装方法能够帮助用户查询软件相关的依赖关系,但是还是需要安装人员自己来解决,而且有些大型软件可能与数十个程序都有依赖关系,在这种情况下安装软件事件非常痛苦和耗费事件的事情,而Yum软件仓库可 ...
- Spring概述学习笔记
1.Spring概述 Spring致力于J2EE应用的各种解决方案,而不仅仅专注于某一层的方案. 可以说,Spring是企业应用开发的一站式选择,他贯穿于表现层.业务层.持久层. Spring并不想取 ...
- 采用__call__ 实现装饰器模式
装饰器模式在实现中也是很常见的:比如手机贴膜,手机壳 都是为了给手机增加一些额外功能 增加耐操 装饰器模式的本质就是对对象二次包装,赋额外功能 __call__ __call__是python魔术方法 ...
- springCloud学习6(Spring Cloud Sleuth 分布式跟踪)
springcloud 总集:https://www.tapme.top/blog/detail/2019-02-28-11-33 前言 在第四篇和第五篇中提到一个叫关联 id的东西,用这个东西来 ...
- Git管理修正(取消跟踪、合并commit)
本文总结了最近使用Git时候遇到的两个问题: 1. 当将不必要跟踪的文件加入到仓库后如何处理? 2. 提交了多个功能相同的commit后如何处理? 总结经验 在创建仓库的一开始,就要设置号.gitig ...
- python SqlServer操作
python连接微软的sql server数据库用的第三方模块叫做pymssql(document:http://www.pymssql.org/en/stable/index.html).在官方文档 ...
- c# 将两个表的有效数据合到一个表中
<asp:DropDownList ID="ddlSpecialty" runat="server" > </asp:DropDownList ...
- 总结一下NDK crash排查步骤
总结一下NDK crash排查步骤: 先在PC上跑通算法 用Visual Studio写算法的testbed,确保算法能跑通 抓log adb logcat -c; adb logcat > 1 ...
- wget详解
wget命令用来从指定的URL下载文件.wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕.如果是服务器打断下 ...
- [AI] 论文笔记 - U-Net 简单而又接近本质的分割网络
越简单越接近本质. 参考资料 U-Net: Convolutional Networks for Biomedical Image Segmentation Abstract & Introd ...