HDOJ 5523 Game
来源:互联网 发布:屏幕视频录制软件 编辑:程序博客网 时间:2024/05/20 09:21
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 748 Accepted Submission(s): 275
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题意:n个柱子,s为起点,t为目标,求s到t的最小耗能思路:如果不止1个柱子而且s和t相同则无解。其他情况下如果s和t分别在两边则是0,如果s在一头或s在中间但是s和t相邻则只需要1,其他情况下为2。刚开始以为s和t相同时为0。。。醉。。。ac代码:#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#define MAXN 100100#define MOD 1000000007#define LL long long#define INF 0xfffffffusing 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;}elseprintf("2\n");} return 0;}
0 0
- HDOJ 5523 Game
- HDOJ 5523 Game
- hdoj 5523 Game 【博弈】
- hdoj Game 5523 (判断)
- hdoj 5523 Game 【细心题】
- BestCoder61(div.2)1002---hdoj 5523 Game
- HDOJ 1846 Brave Game
- HDOJ 1730 Northcott Game
- HDOJ 1729 Stone Game
- HDOJ 2053 Switch Game
- HDOJ 4146 Flip Game
- hdoj 1054 Strategic Game
- hdoj 3622 Bomb Game
- HDOJ 4616: Game
- HDOJ 4621: Life Game
- HDOJ 3484 Matrix Game
- HDOJ 4642 Fliping game
- HDOJ 3622 Bomb Game
- 黑马程序员-----十、java基础反射机制总结
- JDBC基础学习笔记_05_jdbc的程序优化_单立Connection并编写调用配置文件
- 杭电oj-1228-A+B
- 搜索引擎数据源爬取——python scrapy
- pk188 安装方法 最新微信陌陌站街神器 uber 平安易贷
- HDOJ 5523 Game
- SUMO使用教程(一)
- unity3d 文本多语言实现
- ActiveMQ 使用Ajax实现多人聊天室
- 日经春秋 20151103
- cf(思维题,判断两个大数的大小的比较方法)
- object-c之NSdate浅析
- 动态规划_方法总结
- 把所有已学过的代码码一边