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. 公牛与状压dp

    T1 疾病管理 裸得不能再裸的状压dp 不过数据范围骗人 考试时k==0的点没过 我也很无奈呀qwq #include<iostream> #include<cstdio> # ...

  2. 如何减轻ajax定时触发对服务器造成的压力和带宽的压力?ajax-长轮训

    AJAX长轮询的方法来解决频繁对后台的请求,进一步减小压力 在实现过程发现AJAX的多次请求会出现多线程并发的问题又使用线程同步来解决该问题 个人对ajax长轮询的一点愚见 ajax请示后台时,后台程 ...

  3. [编织消息框架][JAVA核心技术]annotation基础

    应用动态代理技术要先掌握annotation技术 注解是JDK1.5之后才有的新特性,JDK1.5之后内部提供的三个注解 @Deprecated 意思是“废弃的,过时的” @Override 意思是“ ...

  4. Java UDP实现聊天功能代码

    我以前经常写的是基于TCP的网络编程,由于TCP建立连接鼻血要经过三次握手连接,服务器端需要阻塞式等待客户端的连接.而UDP则是可以直接向目的地址的目的端口上发送数据包,由于它只负责发送出去就好,不管 ...

  5. Java语言的概述?-什么是Java? (附一张Java工程师的学习路线图)

    什么是Java? Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征.Java语言作为静态面向 ...

  6. js解析xml浏览器兼容性处理

    /****************************************************************************** 说明:xml解析类 ********** ...

  7. C程序设计语言(第二版)--- 习题选

    1. 解: 2. 解: 3. (分析的好有条理啊!) 4. 解:

  8. 第一章 Linux系统概述

    linux是真正的多用户.多任务操作系统,他继承了UNIX系统的主要特征,具有强大的信息处理功能,特别在Internet和Intranet的应用中占有明显优势. 1.1计算机基础知识 计算机分为硬件和 ...

  9. MyEclipse过期后怎么破解

    方法一:写一个程序生成Subscriptioncode import java.io.*; public class MyEclipseGen { private static final Strin ...

  10. VS Code 快捷键(中英文对照版)

    原文地址:https://segmentfault.com/a/1190000007688656 常用 General 按 Press 功能 Function Ctrl + Shift + P,F1 ...