杭电5523 Game
来源:互联网 发布:科技绘图及数据分析 编辑:程序博客网 时间:2024/05/21 09:20
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1202 Accepted Submission(s): 414
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.
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 44 1 3
Sample Output
01
Source
BestCoder Round #61 (div.2)
Recommend
hujie | We have carefully selected several similar problems for you: 5589 5588 5587 5584 5583
思维题,如果够缜密,肯定能1A,为什么没有1 A呢,因为翻译不给你,注意,在n>1的情况下起点==终点就不可能完成了输出-1:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int n,start,eend;int ffabs(int a,int b)//求差值绝对值 {if(a-b>0)return a-b;return b-a;}int main(){while(scanf("%d%d%d",&n,&start,&eend)!=EOF){if(n==1)//就一个点输出0 {printf("0\n");continue;}else if(ffabs(start,eend)==(n-1))//起点跟终点恰好在两端 {printf("0\n");continue; }else if(start==eend)//如果起点==终点则不可能 printf("-1\n");else if(ffabs(start,eend)==1||start==1||start==n)//如果起点在两端 {//或者起点在终点旁边则只需要用超能力跳一下 printf("1\n");//比如5 2 3 只需要按如下走2 1 5 4 3,跳了一下 continue;}else//否则就是跳两下 printf("2\n");}}
0 0
- 杭电5523 Game
- 杭电 2053 Switch Game
- Brave Game(杭电1846)
- Game(杭电5011)
- 杭电---2053 Switch Game
- 杭电2053 Switch Game
- 杭电 1034:Candy Sharing Game
- 杭电hdu 1730 Northcott Game 博弈
- 杭电hdu 1846 Brave Game 巴什博奕
- 杭电ACM 2053 Switch Game
- 杭电1505 City Game-DP问题
- 杭电ACM2147——kiki' game
- 杭电1517-A Multiplication Game
- 杭电 HDU 1034 Candy Sharing Game
- hdu杭电 2147 kiki's game
- 杭电 2147 kiki‘s game
- 杭电1517 A Multiplication Game
- 杭电1564 Play a game
- QtPropertyBrowser简介
- Html5基础笔记
- Android中Socket通信之TCP与UDP传输原理
- PHP filter_input() 函数
- Go语言分析
- 杭电5523 Game
- android TabHost各选项卡显示的对应内容错乱
- php 的定界符 <<<eof 的问题
- O(1) Check Power of 2
- jquery过滤性选择器
- Sqoop修改sqoop元信息实现job的增量导入
- Code Forces 496 A. Minimum Difficulty(水~)
- android的面试题
- Activity的onSaveInstanceState和onRestoreInstanceState调用的时机