hdoj 5523 Game 【细心题】
来源:互联网 发布:ps合成照片软件下载 编辑:程序博客网 时间:2024/05/09 05:18
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 458 Accepted Submission(s): 182
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根排成一行的柱子,每个柱子上都有一个宝石。你拿走所有宝石才可以从出口离开,且每根柱子只能走一次。你可以选择用超能力跳的编号为1或者编号为n的柱子,现在给你入口和出口,问你离开需要使用超能力的最少次数,若不能离开输出-1。
思路:细心点就好了,注意1 1 1 结果是 0。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#define MAXN 110using namespace std;int main(){ int N, S, T; while(scanf("%d%d%d", &N, &S, &T) != EOF) { if(S == T) { if(N == 1) printf("0\n"); else printf("-1\n"); } else if(S == 1 && T == N || S == N && T == 1) printf("0\n"); else if(S == 1 || S == N) printf("1\n"); else if(abs(S-T) == 1) printf("1\n"); else printf("2\n"); } return 0;}
0 0
- hdoj 5523 Game 【细心题】
- HDOJ 3622 - Bomb Game 2-sat+二分....细心...
- HDOJ 5523 Game
- HDOJ 5523 Game
- hdoj 5523 Game 【博弈】
- HDOJ - 4504 简单DP...细心...
- hdoj Game 5523 (判断)
- HDOJ-2296 AC自动机+DP..一定要细心..
- 细心
- BestCoder61(div.2)1002---hdoj 5523 Game
- HDOJ 2053 Switch Game【规律题】
- hdoj Card Game 5494 ()简单题
- HDOJ 1317 - XYZZY dp(SPFA)+dfs判联通..细心..
- 拱猪计分问题(细心题)
- ural2073 Log Files【细心题】
- 细心细心再细心!!
- HDOJ 1846 Brave Game
- HDOJ 1730 Northcott Game
- hdoj 5522 Numbers 【水题】
- EMC,EMI和EMS 有什么区别和联系?
- HDU_4780_Candy Factory(最小费用流)
- 2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)HDU 5532 Almost Sorted Array
- 组合数取模
- hdoj 5523 Game 【细心题】
- HDOJ 1495 非常可乐(bfs)
- 【Little_things】事件驱动的带界面的Client/Server聊天小程序(java socket)
- 番茄工作法流程
- Activity的启动模式
- leetcode系列(57)Trapping Rain Water
- iOS--- 如何获得UIView的父控制器
- c3p0,Druid,Tomcat Jdbc Pool,dbcp2,proxoo数据源性能比较
- 欢迎使用CSDN-markdown编辑器