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)
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,s,t,要求经过所有n个点且每个点只能经过一次,每次可以跳到1或N点,问最少要跳几次思路:推理。直接考虑答案,跳0次和跳1次的情况都容易想,剩下的就是跳2次的情况。有坑111为0.不要swap。code:#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <sstream> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int INF=0x3fffffff; const int inf=-INF; const int N=1000000; const int M=2005; const int mod=1000000007; const double pi=acos(-1.0); #define cls(x,c) memset(x,c,sizeof(x)) #define cpy(x,a) memcpy(x,a,sizeof(a)) #define fr(i,s,n) for (int i=s;i<=n;i++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define lowbit(x) (x&-x) #define pii pair<int,int> #define mk make_pair #define IN freopen("in.txt","r",stdin); #define OUT freopen("out.txt","w",stdout); int n,s,t; int sol() { if ((s==1&&t==n)||(s==n&&t==1)) return 0; else if (s==1||abs(t-s)==1||s==n) return 1; else return 2; } int main() { while (~scanf("%d %d %d",&n,&s,&t)) { if (s==t) {if (n!=1) puts("-1");else puts("0");continue;} else printf("%d\n",sol()); } }