HDU_5523Game
2015-11-01 00:02
225 查看
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 159 Accepted Submission(s): 74
Problem Description
XY is playing a game:there are N pillar in a row,which numbered from 1 to n.Each pillar has a jewel.Now XY is standing on the S-th pillar and the exit is in the T-th pillar.XY can leave from the exit only after they get all the jewels.Each time XY can move
to adjacent pillar,or he can jump to boundary ( the first pillar or the N-th pillar) by using his superpower.However,he needs to follow a rule:if he left the pillar,he no can not get here anymore.In order to save his power,XY wants to use the minimum number
of superpower to pass the game.
Input
There are multiple test cases, no more than 1000 cases.
For each case,the line contains three integers:N,S and T.(1≤N≤10000,1≤S,T≤N)
Output
The output of each case will be a single integer on a line: the minimum number of using superpower or output -1 if he can't leave.
Sample Input
4 1 4
4 1 3
Sample Output
0
1
无解的情况只有起点和终点位置一样且N不为1。终点和起点都在边界上答案为0,如果起点在边界上或者起点终点相邻答案为1,其他答案为2.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #include <string> #include <cmath> using namespace std; int main() { int n, s, t; while (cin >> n>>s >> t) { if (n == 1) cout << 0<< endl; else { if (s == t) cout << -1<< endl; else if ((s == 1 && t == n) || (s == n && t == 1)) cout << 0<< endl; else if ((s == 1 || s == n) || abs(s-t) == 1) cout << 1<< endl; else cout << 2<< endl; } } return 0; }
相关文章推荐
- 硬盘分区 5
- HDU_5523Game
- 使用浏览器做编辑器
- 不喜欢 IDE?试试看 grepgitvi
- 如何在 LibreOffice Writer 中创建一个电子书章节模板
- 币市黑箱操作指北
- linux 命令每天必学之tar命令
- 周末总结正则表达式(完整篇)
- SqlServer异常处理常用步骤
- 《JavaScript高级编程》学习笔记之object和array引用类型
- javascript跨域总结之window.name实现的跨域数据传输
- JavaScript调用传递变量参数的相关问题及解决办法
- 基于Jquery实现万圣节快乐特效
- oracle+mybatis 使用动态Sql当插入字段不确定的情况下实现批量insert
- gitcafe博客
- redis连接过多的一个解决方法
- ContentProvider和Uri详解
- public final Cursor query ()参数解析
- linux shell4 判断登陆用户,然后重启关闭系统
- linux shell 编程5 函数获取参数