HDU 5523 Game(就是情况比较多,讨论全了就可以了)——BestCoder Round #61(div.1 div.2)
来源:互联网 发布:开源视频网站 php 编辑:程序博客网 时间:2024/06/04 20:06
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
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)
/************************************************************************/
附上该题对应的中文题
Game
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
问题描述
XY在玩一个游戏:有N根柱子排成一排,编号为1到N,每个柱子上面有一块宝石,现在XY站在第S根柱子上,出口在第T跟柱子上,XY需要拿到所有宝石后从出口离开。每次XY可以走到相邻的柱子上,也可以使用超能力跳到第一根柱子或者第N根柱子上,如果离开了柱子之后再也不能到达这里。为了节省能量,XY想用最少次数超能力通关。
输入描述
输入有多组数据,不超过1000组.每组数据输入一行包含3个整数,N,S和T.(1≤N≤10000,1≤S,T≤N)
输出描述
对于每组数据输出一行,表示使用超能力的最少次数,如果不可能离开,输出-1.
输入样例
4 1 44 1 3
输出样例
01
/****************************************************/
出题人的解题思路:
Game
无解的情况只有起点和终点位置一样且N不为1。终点和起点都在边界上答案为0,如果起点在边界上或者起点终点相邻答案为1,其他答案为2.
这题真的可以说是说多了都是泪啊,在坚持不懈地拿了7个WA之后,终于是AC了,在此分享一下所有可能的例子INPUT
8 2 5
OUTPUT
2
2
INPUT
8 1 4
8 1 4
OUTPUT
1
1
INPUT
8 4 1
8 4 1
OUTPUT
2
2
INPUT
8 8 4
8 8 4
OUTPUT
1
1
INPUT
8 4 8
8 4 8
OUTPUT
2
2
INPUT
8 1 8
8 1 8
OUTPUT
0
0
INPUT
8 8 1
8 8 1
OUTPUT
0
0
INPUT
8 5 5
-1
8 5 5
-1
INPUT
8 2 1
8 2 1
OUTPUT
1
1
INPUT
8 4 3
8 4 3
OUTPUT
1
1
INPUT
1 1 1
1 1 1
OUTPUT
0
0
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<cmath>#include<string>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 105;const int M = 100005;const int inf = 100000000;const int mod = 2009;int main(){ int n,s,t; while(~scanf("%d%d%d",&n,&s,&t)) if(s==t) { if(n==1) puts("0"); else puts("-1"); } else if(s==1&&t==n||s==n&&t==1) puts("0"); else if(s==1&&t!=n||s==n&&t!=1||abs(s-t)==1) puts("1"); else puts("2"); return 0;}菜鸟成长记
0 0
- HDU 5523 Game(就是情况比较多,讨论全了就可以了)——BestCoder Round #61(div.1 div.2)
- HDU 5494 Card Game(排个序就可以了)——BestCoder Round #58(div.2)
- HDU 5500 Reorder the Books(O(n)的复杂度就够了)——BestCoder Round #59(div.1 div.2)
- HDU 5495 LCS(其实就是找环)——BestCoder Round #58(div.1 div.2)
- hdu 5523 Game 【BestCoder Round #61 (div.2)】
- HDU 5480 Conturbatio(傻傻的我用了线段树)——BestCoder Round #57(div.1 div.2)
- BestCoder Round #61 (div.2) HDU5523 Game
- BestCoder Round #61 (div.2) Game
- HDU 5366 The mook jong——BestCoder Round #50(div.1 div.2)
- HDU 5365 Run ——BestCoder Round #50(div.1 div.2)
- HDU 5428 The Factor——BestCoder Round #54(div.1 div.2)
- HDU 5429 Geometric Progression(大数模板)——BestCoder Round #54(div.1 div.2)
- HDU 5569 matrix(DP)——BestCoder Round #63(div.1 div.2)
- HDU 5587 Array(位运算)——BestCoder Round #64(div.1 div.2)
- HDU 5596 GTW likes gt(巧用multiset)——BestCoder Round #66(div.1 div.2)
- HDU 5671 Matrix——BestCoder Round #81(div.1 div.2)
- HDU 5672 String(尺取法)——BestCoder Round #81(div.1 div.2)
- HDU 5670 Machine——BestCoder Round #81(div.2)
- Oracle实战——表的创建与约束
- 发斯蒂芬撒的撒的撒的发
- A - Secrete Master Plan【ccpc】
- 深入解读缓存(三)——Memcache缓存
- BestCoder Round #61 (div.2) 1002
- HDU 5523 Game(就是情况比较多,讨论全了就可以了)——BestCoder Round #61(div.1 div.2)
- linux常用基本命令
- Spring notes 1
- 继续让脑细胞嗨起来
- LightOJ - 1122 Digit Count(DP)
- UDK BaseTools
- ADO
- 方法的重载
- L - Huatuo's Medicine【ccpc】