HDOJ5523Game

Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 158    Accepted Submission(s): 73


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. (1N10000,1S,TN)
 

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
 

Source
 

Recommend
hujie
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
    int n,s,t;
    while(scanf("%d%d%d",&n,&s,&t)!=EOF){
        if(s==t&&n!=1)printf("-1\n");
        else if(s==t&&n==1)printf("0\n");
        else if((t==n&&s==1)||(t==1&&s==n))printf("0\n");
        else if(abs(t-s)==1)printf("1\n");
        else if(t==n||t==1){
            printf("2\n");
        }
        else if(s==1||s==n){
            printf("1\n");
        }
        else printf("2\n");
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值