# 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

#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;
}

```

## 随机推荐

1. Yii2的深入学习--事件Event

我们先来看下事件在 Yii2 中的使用,如下内容摘自 Yii2中文文档 事件可以将自定义代码“注入”到现有代码中的特定执行点.附加自定义代码到某个事件,当这个事件被触发时,这些代码就会自动执行.例如, ...

2. Snmp协议应用-扫描局域网内打印机

.h2cls { background: #6fa833 none repeat scroll 0 0 !important; color: #fff; font-family: "微软雅黑 ...

3. 2016.09.14,英语,《Using English at Work》全书笔记

半个月时间,听完了ESLPod出品的<Using English at Work>,笔记和自己听的时候的备注列在下面.准备把每个语音里的快速阅读部分截取出来,放在手机里反复听. 下一阶段把 ...

4. Oracle 11g安装步骤详谈

又是十月南京阴雨天气 图书馆花了一个多小左右把11g安装折腾好了.其中折腾SQL Developer 花了好长时间,总算搞定了.好了,先总结下安装步骤,希望给后面的童鞋提高安装效率. 相互方便  共同 ...

5. poj 2417 Discrete Logging(A^x=B(mod c),普通baby_step)

http://poj.org/problem?id=2417 A^x = B(mod C),已知A,B.C.求x. 这里C是素数,能够用普通的baby_step. 在寻找最小的x的过程中,将x设为i* ...

6. WPF:验证登录后关闭登录窗口，显示主窗口的解决方法

http://www.27ba.com/post/145.html WPF:验证登录后关闭登录窗口,显示主窗口的解决方法 最近想做一个基于Socket的通讯工具,想模仿QQ那样,需要先登录,登录成功后 ...

7. 梯度、散度、旋度、Jacobian、Hessian、Laplacian 的关系图

转自松鼠的窝 一.入门

8. iOS webview加载时序和缓存问题总结

iOS webView的加载时序 UIWebView加载顺序: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSU ...

9. BZOJ1222 [HNOI2001]产品加工 - 动态规划- 背包

题解 怎么看都不像是个背包,直到我看了题解→_→, 第一次碰到这么奇怪的背包= = 定一个滚动数组\$F_i\$, \$i\$表示机器\$a\$用了\$i\$的时间, \$F_i\$表示机器\$b\$用了\$F_i\$的时间, ...

10. Windows Server环境下消息队列之ActiveMQ实战

环境准备 1.安装jdk1.7+ 2.下载新版ActiveMQ http://activemq.apache.org/ 3.启动activemq服务 4.启动成功后的界面是  5.启动成功后 浏览器访 ...