HDOJ 5523 Game
2015-11-01 14:07
274 查看
Total Submission(s): 387 Accepted Submission(s): 150
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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)
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
4 1 4
4 1 3
[align=left]Sample Output[/align]
0
1
题意: 有n根柱子排成一排,起始位置是第S根柱子,出口位置是第T根柱子。要求把所有的柱子都走一遍,且走过的不能再走。走法有两种:1,走到与当前相邻的柱子上; 2,直接跳到第一根或者最后一根柱子上,并消耗能量。
问最少消耗多少能量把柱子走完,若不能把柱子走完就输出-1
题解:很容易就知道能把柱子走完的情况下,最多消耗2个能量。 当n不等于1时,S==T时就无法从T根柱子结束(走过的柱子不能再走),所以此种情况下是不能完成的。仅有此一种情况输出-1。 其他各种情况分别讨论即可。
代码如下:
BestCoder上的题目算法考察不多,不过挺锻炼思维能力的。以后常玩
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 387 Accepted Submission(s): 150
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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)
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
4 1 4
4 1 3
[align=left]Sample Output[/align]
0
1
题意: 有n根柱子排成一排,起始位置是第S根柱子,出口位置是第T根柱子。要求把所有的柱子都走一遍,且走过的不能再走。走法有两种:1,走到与当前相邻的柱子上; 2,直接跳到第一根或者最后一根柱子上,并消耗能量。
问最少消耗多少能量把柱子走完,若不能把柱子走完就输出-1
题解:很容易就知道能把柱子走完的情况下,最多消耗2个能量。 当n不等于1时,S==T时就无法从T根柱子结束(走过的柱子不能再走),所以此种情况下是不能完成的。仅有此一种情况输出-1。 其他各种情况分别讨论即可。
代码如下:
#include<cstdio> #include<cstring> int main() { int n,s,t; while(scanf("%d%d%d",&n,&s,&t)!=EOF) { if(n==1) { printf("0\n"); continue; } if(s==t&&n!=1) { printf("-1\n"); continue; } if((s==1&&t==n)||(s==n&&t==1)) { printf("0\n"); continue; } if(s==1||s==n) { printf("1\n"); continue; } if(s==t+1||s==t-1) { printf("1\n"); continue; } printf("2\n"); } return 0; }
BestCoder上的题目算法考察不多,不过挺锻炼思维能力的。以后常玩
相关文章推荐
- 各种接口API
- TortoiseGit配合msysGit在Git@OSC代码托管的傻瓜教程
- JAVA学习笔记之继承
- NGUI简单的UI功能操作
- Cannot load php5apache2_4.dll into server解决办法;
- 怎么修改Win10登录名称 修改Win10登录名称图文教程
- NSUserDefaults
- mysql 基本操作
- 大屏幕自适应
- HDU 2048 标准错排
- 杭电1266--数的倒叙
- .sortEntities()is called this array is sorted by the entities.zIndex.
- 数据库设计三大范式
- 4.nodejs权威指南--TCP和UDP
- localstorage sessionstorage cookie的区别
- 逐渐变暗
- 位、字节和字
- 在Eclipse中反编译Class文件
- hdu2544最短路
- ||1