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. Linux下多线程下载工具 - Axel

    Axel 是 Linux 下一个不错的HTTP/FTP高速下载工具.支持多线程下载.断点续传,且可以从多个地址或者从一个地址的多个连接来下载同一个文件.适合网速不给力时多线程下载提高下载速度.比如在国 ...

  2. Yoshua Bengio 2016年5月11日在Twitter Boston的演讲PPT

    Yoshua Bengio最新演讲:Attention 让深度学习取得巨大成功(46ppt) Yoshua Bengio,电脑科学家,毕业于麦吉尔大学,在MIT和AT&T贝尔实验室做过博士后研 ...

  3. 数字图像处理- 3.4 空间滤波 and 3.5 平滑空间滤波器

    3.4 空间滤波基础 • Images are often corrupted by random variations in intensity, illumination, or have poo ...

  4. ecshop 后台【左侧新增菜单】

    模板文件admin/template/menu.htm admin/includes/inc_menu.php 菜单排序(链接) langagues/zh_cn/admin/common.php  语 ...

  5. Shader

    Shader的学习方法总结 http://www.cnblogs.com/Esfog/p/How_To_Learn_Shader.html [Shader 着色器]学习shader之前必须知道的东西之 ...

  6. WinForm使用皮肤图文步骤

    Winfrom本身样式提供的是Windows经典样式.. 不说多丑也绝称不上好看..有时为了用户体验就不得不需要想办法弄漂亮一点..皮肤包会是一个不错的选择.. 不废话了..开整.. 首先从网上下载免 ...

  7. python递归理解图

    递归:下一级只能return给自己的上一级. import re val="9-2*5/3+7/3*99/4*2998+10*568/14" val="9-2*5/3+7 ...

  8. PHP 学习

    http://www.w3school.com.cn/php/php_sessions.asp public static void chkacc() {Response.Redirect(" ...

  9. WinSCP 连接 Ubuntu 拒绝的问题

    1.打开配置文件 $ sudo vi /etc/ssh/sshd_config 2.修改操作 PermitRootLogin without-password  修改为 PermitRootLogin ...

  10. android自定义控件(2)-拖拽实现开关切换

    在这里,我们的主要工作就是在原有代码的基础上,增加一个重写的onTouchEvent方法,刚添加上来的时候是这个样子的: @Override public boolean onTouchEvent(M ...