B. Lunch

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100637/problem/B

Description

The swamp looks like a narrow lane with length n covered by floating leaves sized 1, numbered from 1 to n with a fly sitting on the top of each. A little toad is sitting on one of the leaves instead of a fly. Its name is Kvait and it is about to have lunch. It can jump to the bordering leaf or jump it over to the next one in any direction. When landing it eats a fly. Kvait is already quite a big toad and the leaves are unstable so when it jumps away the leaf starts sinking.

In order to have lunch Kvait needs to eat all of the flies. It starts his journey from the leaf with number s and has to finish on the leaf with number f. Yet jumping to the bordering leaf takes more Kvait’s energy than skipping a leaf over. It is necessary to plan the toad’s movements to get lunch with minimal energy spent.

Input

Single line contains three integers nsf (2 ≤ n ≤ 10 000, 1 ≤ s, f ≤ n) — the number of leaves, number of a starting leaf and the number of the finish leaf respectively.

Output

Output the minimal number of jumps to the bordering leaves required for the toad to have lunch. If there is no way to eat up, output a single number  - 1.

Sample Input

4 1 2

Sample Output

1

HINT

题意

有n个点,每次青蛙可以跳一步或者两步,要求从s点遍历全部点并且最后落在f点,要求最少跳一步的步数是多少

题解:

我是写DFS,然后暴力对拍调的

我们跳3步的话,可以只需要挑一步,其他时候都需要跳完……

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* int main()
{
int n=read(),f=read(),s=read();
int ans=;
if(f<s)
swap(f,s);
if(s==f)
{
cout<<"-1"<<endl;
return ;
}
if(s!=)
{
ans+=;
s=s+;
if(s==f)
{
if(f==n)
cout<<ans<<endl;
else
cout<<"-1"<<endl;
return ;
}
}
if(f!=n)
{
ans+=;
f-=;
if(s==f)
{
cout<<ans<<endl;
return ;
}
}
ans+=((f-s)/)+(f-s)%;
cout<<ans<<endl;
}

Codeforces Gym 100637B B. Lunch 找规律的更多相关文章

  1. Codeforces Gym 100015B Ball Painting 找规律

    Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white ball ...

  2. codeforces B. A and B 找规律

    Educational Codeforces Round 78 (Rated for Div. 2) 1278B - 6 B. A and B  time limit per test 1 secon ...

  3. Codeforces 870C Maximum splitting (贪心+找规律)

    <题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...

  4. Gym - 101775L SOS 博弈 找规律

    题目:https://cn.vjudge.net/problem/Gym-101775L PS:训练赛中被这道题折磨的不轻,和队友反复推必胜态与必败态试图推导出公式或者规律,然后推的心态逐渐失控,,, ...

  5. Codeforces 474D Flowers (线性dp 找规律)

    D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...

  6. Codeforces 603A - Alternative Thinking - [字符串找规律]

    题目链接:http://codeforces.com/problemset/problem/603/A 题意: 给定一个 $01$ 串,我们“交替子序列”为这个串的一个不连续子序列,它满足任意的两个相 ...

  7. Gym 100962G Green Day (找规律)

    题意:你用k 个生成树构成一个完全图. 析:n 个点的完全图有n(n-1)/2个边,一个生成树有n-1个边,你有k 个生成树 即边数等于 K(n-1) ,即  n(n-1)/2 == k(n-1)   ...

  8. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  9. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

随机推荐

  1. C#判断用户是否使用微信浏览器,并据此来显示真实内容或二维码

    平时我们看一些网页的时候会发现这样的功能:有的页面只能在微信里访问,如果在电脑上访问就只显示当前地址的二维码.这个用C#怎么实现呢?我们结合代码来看看. 首先,我们需要先判断用户使用的是什么浏览器,这 ...

  2. ios实现类似魔兽小地图功能 在

    写了一个类似魔兽小地图功能的控件. 比如你有一个可以放大缩小的scrollView.会在里面进行一些放大缩小,点击里面的按钮呀,等操作. 这个小地图控件.就会和你的大scrollView同步.并有缩略 ...

  3. redis学习笔记之pipeline

    redis是一个cs模式的tcp server,使用和http类似的请求响应协议.一个client可以通过一个socket连接发起多个请求命令.每个请求命令发出后client通常 会阻塞并等待redi ...

  4. Android UI开发详解之Fragment

    Fragment是Android自从3.0之后新加入的一个组件,我相信很多人都已经听说过这个组件了,但这个组件到底是个什么,如何去使用他呢,且听我讲来. 以下部分资料来自官网(官网才是王道,其他都是浮 ...

  5. Tour

    题意: 给n个点的坐标,求形成的最短的闭合回路. 分析: 经典问题,dp[i][j]表示有1-i点再由j回到1点的最短距离,i点有两种情况,在去的路径上 dp[i][j]=min(dp[i][j],d ...

  6. 使用七牛云存储----大家自己的图床[python]

    ##写博客什么的总得贴图吧,图床选来选去还是七牛吧.嗯,就是你了 [OSchaina 源码] 结合FastStone Capture 简直爽歪歪. FastStone Capture 自动保存图片到文 ...

  7. 今天工作遇到要发短信(ios)的功能,于是随手记录了一下

    ios中发送短信有两种 1.程序外调用系统短信 2.程序内调用系统发短信 第一种比较简单,直接调用url就可以了 oc下的代码为 [[UIApplication sharedApplication] ...

  8. XAMPP:访问phpmyadmin出错的解决方案

    来源:http://www.ido321.com/1246.html XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建 XAMPP 软件站集成软件包,轻巧,用起来很方便.它提 ...

  9. 基于GPL329xx linux平台电容屏gsl1680的驱动调试分析

    因客户有用到了gsl1680 7寸电容屏,所以拿了一块过来,便在329xx的平台上面开始调试了. 大概浏览了一下所提供的资料,只有介绍模组的资料跟一份中文版的datasheet,datasheet只是 ...

  10. mybatis系列-06-输入映射

    通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型 6.1     传递pojo的包装对象 6.1.1     需求 完成用户信息的综合查询,需要 ...