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 ...
随机推荐
- Java调用Http/Https接口(6)--RestTemplate调用Http/Https接口
RestTemplate是Spring提供的用于访问Http接口的客户端,提供同步的API:在将来的Spring版本中可能会过时,将逐渐被WebClient替代.文中所使用到的软件版本:Java 1. ...
- 2019 斗鱼java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.斗鱼等公司offer,岗位是Java后端开发,因为发展原因最终选择去了斗鱼,入职一年时间了,之前面试了很多家公 ...
- Java自学-控制流程 continue
Java的 continue语句 继续下一次循环 示例 1 : continue 如果是双数,后面的代码不执行,直接进行下一次循环 public class HelloWorld { public s ...
- sql分页优化
索引优化 注意查询的数据占总数据达到一定量的时候可能导致索引失效.可以用limit或者指定列缩小数据区域可以解决. 以时间orderby排序的limit分页优化 前提用order by分页 limit ...
- Spring AOP 原理的理解
>AOP基本概念 1)通知(Advice):织入到目标类连接点上的一段程序代码.通知分为五种类型: - Before:在方法被调用之前调用 - After:在方法完成后调用通知,无论方法是否执行 ...
- Oracle SQL函数-NLSSORT
Syntax 用途: NLSSORT返回字符值char的排序规则键和显式或隐式指定的排序规则.排序规则键是一个用于根据指定的排序规则对char进行排序的字节字符串.排序规则键的属性是:按二进制比较由给 ...
- null在mysql中的不同表现
在mysql中count(*)和count(id)具有不同的表现,其最大的影响是在我们进行联表的时候,如,我们现在要查询一个文章的评论数量,使用左连接查询,具体的sql语句如下: SELECT a.* ...
- hash表的理解
哈希表 先从数组说起 任何一个程序员,基本上对数组都不会陌生,这个最常用的数据结构,说到它的优点,最明显的就是两点: 简单易用,数组的简易操作甚至让大多数程序员依赖上了它,在资源富足的情况下,我们甚至 ...
- 用session防止网站页面被频繁刷新
session防止网站页面频繁被刷新 <?php //公司网站老是受到攻击,这是之前在网上看到的一个用session防止IP频繁访问的方法,我们公司用的是Memcache,都差不多,就是存储方式 ...
- beta版本——第六次冲刺
第六次冲刺 (1)SCRUM部分☁️ 成员描述: 姓名 李星晨 完成了哪个任务 修改注册时时候弹窗提醒不正确的问题 花了多少时间 0.5h 还剩余多少时间 1.5h 遇到什么困难 没有 这两天解决的进 ...