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)(1\leq N\leq10000,1\leq S,T\leq N )(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 各种情况想到就好,好多人哭晕在厕所23333
无解的情况只有起点和终点位置一样且N不为1。终点和起点都在边界上答案为0,如果起点在边界上或者起点终点相邻答案为1,其他答案为2.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int N,S,T;
while(cin>>N>>S>>T){
if(S==T && N!=) cout<<"-1"<<endl;
else if(abs(S-T)+==N) cout<<""<<endl;
else if((T==N || T==) && abs(S-T)!=) cout<<""<<endl;
else if(S== || S==N || abs(S-T)==) cout<<""<<endl;
else cout<<""<<endl;
}
return ;
}
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
int n,s,t;
while(~scanf("%d%d%d",&n,&s,&t))
{
if(n==){cout<<"0\n";goto k;}
if(s==&&t==n){cout<<"0\n";goto k;}
if(n==&&t==s){cout<<"0\n";goto k;}
if(s==t){cout<<"-1\n";goto k;}
if(n==){cout<<"0\n";goto k;}
if(t+==s){cout<<"1\n";goto k;}
if(s+==t){cout<<"1\n";goto k;}
if(t==||t==n){cout<<"2\n";goto k;}
if(s==||s==n){cout<<"1\n";goto k;}
else cout<<"2\n";
k: n=s=t=;
}
return ;
}

BestCoder Round #61 1002 Game的更多相关文章

  1. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  2. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [f(n ...

  3. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  4. Manacher BestCoder Round #49 ($) 1002 Three Palindromes

    题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...

  5. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

  6. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  7. BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)

    今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...

  8. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

  9. BestCoder Round #80 1002

    HDU 5666 Segment 题意:给你条斜率为-1,常数项为q(q为质数)的直线,连接原点与直线上整数格点,问你在有多少个格点在形成的无数个三角形内,而不在线段上,结果对P取模. 思路:best ...

随机推荐

  1. MySQL增加列,修改列名、列属性,删除列

    mysql修改表名,列名,列类型,添加表列,删除表列 alter table test rename test1; --修改表名 alter table test add  column name v ...

  2. Zookeeper集群的安装和使用

    Apache Zookeeper 由 Apache Hadoop 的 Zookeeper 子项目发展而来,现已经成为 Apache 的顶级项目,它是一个开放源码的分布式应用程序协调服务,是Google ...

  3. Hosts知多少?

    Hosts知多少?   老D hosts 定期更新地址: http://laod.cn/hosts/2016-google-hosts.html   老Dhosts 页面长期更新最新Google.谷歌 ...

  4. 注入问题0x00

    1.sqlmap遇到MySQL注入可以成功getshell,但是,遇到sqlserver注入未成功getshell. 2.xp_cmdshell 如何 getshell(1433未对外开放). 解决方 ...

  5. 浅谈JavaScript中的正则表达式

    引言 对于正则表达式我想作为程序员肯定使用过它,那天书般的表达方式,我用一次就记住它了.这篇博客先介绍一些正则表达式的内容,然后介绍JavaScript中对正则表达式特有的改进.下面开始介绍正则表达式 ...

  6. Oracle的DBMS_OUTPUT.PUT_LINE用法及脚本批处理方法

    打印至控制台(无显示): BEGIN DBMS_OUTPUT.PUT_LINE('Hey look, ma!'); END; / 打印至控制台(有显示): SET SERVEROUTPUT ON BE ...

  7. JCarouselLite--帮助文档

    jcarousellite是一款jquery插件,可以控制文档元素滚动,丰富的参数设置可以控制滚动的更多细节,是一款不可多得的滚动插件. ------------------ 官网地址:http:// ...

  8. 【MongoDB】MongoDb的“not master and slaveok=false”错误及解决方法

    链接mongodb报错如下 2016-03-14T16:26:00.912+0800 E QUERY [thread1] Error: listDatabases failed:{ "ok& ...

  9. github及其他记录

    http://mvnrepository.com/artifact/org.jdom/jdom/1.1.3 https://github.com/open-power-workgroup/Hospit ...

  10. git 初始化

    Git global setup git config --global user.name "杨清1" git config --global user.email " ...