Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 159    Accepted Submission(s): 74

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)
 
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 4
4 1 3
 
Sample Output
0
1
无解的情况只有起点和终点位置一样且N不为1。终点和起点都在边界上答案为0,如果起点在边界上或者起点终点相邻答案为1,其他答案为2.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std; int main() {
int n, s, t;
while (cin >> n>>s >> t) {
if (n == 1)
cout << 0<< endl;
else {
if (s == t)
cout << -1<< endl;
else if ((s == 1 && t == n) || (s == n && t == 1))
cout << 0<< endl;
else if ((s == 1 || s == n) || abs(s-t) == 1)
cout << 1<< endl;
else
cout << 2<< endl;
}
}
return 0;
}

HDU_5523Game的更多相关文章

随机推荐

  1. [HDU - 5170GTY's math problem 数的精度类

    题目链接:HDU - 5170GTY's math problem 题目描述 Description GTY is a GodBull who will get an Au in NOI . To h ...

  2. vs发布项目webconfig替换语法

    关于vs发布项目时webconfig替换语法也是最近才学到的东西,写这篇文章就当是作个备忘录吧,如果能帮助别人能够学习到webconfig如何替换那就再好不过了. 1.认识一下web项目下的web.D ...

  3. jest for elasticsearch

    *elasticsearch(后面简称es) 背景: 目前项目应用中对es的操作用的是http(自己封装)的一套方法:有些数据处理起来还是需要定制开发处理,不是很方便.正好需要对本项目重新进行改造,于 ...

  4. lesson - 11 正则表达式

    正则就是有一定规律的字符串,有几个特殊符号很关键(. * + ? | ),我们平时不仅可以用命令行工具grep/sed/awk去引用正则,而且还可以把正则嵌入在nginx.apache.甚至php.p ...

  5. cat/tac/more/less 命令详解

    cat:(http://www.cnblogs.com/peida/archive/2012/10/30/2746968.html) *cat主要有三大功能:1.一次显示整个文件:cat filena ...

  6. php示例的错误记录

    最近几天在测试php的mvc,从网上找到几个示例. 先学习这一篇,http://www.cnblogs.com/q1ng/p/4529496.html 标题是  PHP的MVC框架 深入解析,其实是最 ...

  7. ActiveMQ (三) 讯息传送机制以及ACK机制

    详析请看如下博客: http://blog.csdn.net/lulongzhou_llz/article/details/42270113 后续再做整理.

  8. The Hungarian Abhorrence Principle

    原文:http://www.butunclebob.com/ArticleS.UncleBob.TheHungarianAbhorrencePrinciple    The Hungarian Abh ...

  9. java基础->循环

    while循环 格式:   while(条件表达式) { // 条件表达式其实就是一个结果为boolean类型的代码 循环体; } 执行流程: 先判断条件表达式的值, 如果为true就执行循环体,执行 ...

  10. 字符串匹配KMP算法的C语言实现

    字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD" ...