Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1486 Accepted Submission(s): 516
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
Source
Recommend
题意:
XY是玩游戏:有N个支柱在一行,编号从1到N。每个支柱的珠宝。现在XY站在S-th支柱和出口T-th支柱。XY只能得到所有的珠宝后离开。每次XY可以移动到相邻的支柱,或者他可以跳转到边界(第一个支柱或第n个支柱)通过使用他的超级大国。然而,他需要遵循一条规则:如果他离开了支柱他不能再通过它。为了拯救他的权力,XY想用最小数量的超级大国通过游戏。求出这个最小数量。
思路:需要把各种情况都考虑一下,情况考虑完了,就能 很容易AC了。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int n,s,t;
while(scanf("%d%d%d",&n,&s,&t)!=EOF)
{
if(n==1)
{
printf("0\n");
}
else
{
if(abs(s-t)==n-1)
printf("0\n");
else if(s==t)
printf("-1\n");
else if(abs(s-t)==1)
printf("1\n");
else if((s==1||s==n)&&(t!=1||t!=n))
printf("1\n");
else
printf("2\n");
}
}
return 0;
}