http://acm.hdu.edu.cn/showproblem.php?pid=5523
情况比较多,要考虑周全,注意n=1时和s,t相邻时
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int s,t,n;
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)||fabs(s-t)==1)
cout<<1<<endl;
else
cout<<2<<endl;
}
}
return 0;
}