hdoj 5523 Game 【博弈】
2015-12-10 21:47
302 查看
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1210 Accepted Submission(s): 419
[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代码:[code]#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<stack> #include<vector> #define mem(x,y) memset(x,y,sizeof(x)) #define SI(x) scanf("%d",&x) using namespace std; int main() { int n,s,t; while(scanf("%d%d%d",&n,&s,&t)!=EOF) { if(n>1&&s==t) { printf("-1\n"); continue; } else if((s==1&&t==n)||(s==n&&t==1)) { printf("0\n"); continue; } else if((s==1&&t!=n)||(t!=1&&s==n)||(s!=1&&s+1==t)||(s!=n&t+1==s)) { printf("1\n"); continue; } else printf("2\n"); } return 0; }
[/code]
相关文章推荐
- 快速提高Android开发调试的使用技巧
- 没有选择Debug构建方式,为文件的某行设置断点可能会失败
- 关于linux文件管理的学习
- JAVA爬取亚马逊的商品信息
- 好用的截图软件、好多实用小功能
- 实时软件控制第二次作业
- mongoDB实践-docker实践-01
- 最小的K个数
- c语言—stdarg宏(函数可变参数实现)
- LVM卷管理及配额设置
- 进程与线程的区别(转)
- Firefox about
- 【日记-C语言】今天看书,吸LFG
- HDU2533 N皇后问题 DFS入门
- 工作三年找工总结
- Firefox about
- 数组中出现次数超过一半的数字
- eclipse 跟 android studio 完全可以用同一套代码,使android studio 的代码结构可以跟eclipse一样
- linux 硬盘分区
- 字符串的排列