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 ...
随机推荐
- Eclipse创建ssm项目
1.创建Maven项目 2.勾选上面的 3.打成war包的形式 4.配置webapp.xml Project Facets——Dynamic Wed Module 2.5 ——然后点击下面的提示 5 ...
- Windows查看端口使用状况(转)
转:https://www.cnblogs.com/lixuwu/p/5898354.html 阅读目录 1 查看windows所有端口进程 2 查询指定端口 使用端口是我们在进行远程或者打印机等都会 ...
- business from English bisynes
business from English bisynes Etymology From Middle English bisynes Hyphenation: business Noun busin ...
- Python运算符大全
一. Python的算术运算 Python的算术运算符与C语言类似,略有不同.包括加(+).减(-).乘(*).除(/).取余(%).按位或(|).按位与(&).按位求补(~).左移位(< ...
- 查找单链表中倒数第k个结点
本文转自:程序员面试题6--查找链表中倒数第k个结点 题目:输入一个单向链表,输出该链表中倒数第k个结点.链表的倒数第0个结点为链表的尾指针.链表结点定义如下: struct ListNode { i ...
- 【故障解决】enq: PS - contention
[故障解决]enq: PS - contention 一.1 BLOG文档结构图 一.2 前言部分 一.2.1 导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能, ...
- JS 对象 数组求并集,交集和差集
一.JS数组求并集,交集和差集 需求场景 最近,自己项目中有一些数组操作,涉及到一些数学集的运算,趁着完成后总结一下. 简化问题之后,现有两数组a = [1, 2, 3],b = [2, 4, 5], ...
- jQuery知识梳理20190817
目录 jQuery知识梳理20190817 1. jQuery的特征 2. jQuery的两把利器 2.1 jQuery核心函数 2.2 jQuery核心对象 3. jQuery核心函数详解 4. j ...
- 缓存注解@Cacheable、@CacheEvict、@CachePut使用及注解失效时间
从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该 ...
- 实验3 SQL注入原理-万能密码注入
实验目的 (1)理解[万能密码]的原理 (2)学习[万能密码]的使用 实验原理 一.访问目标网站 1.选择一个存在漏洞的论坛 http://192.168.1.3:8009 进入 2.输入用户名[ad ...