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. 最简单的基于FFMPEG的转码程序

    本文介绍一个简单的基于FFmpeg的转码器.它可以将一种视频格式(包括封转格式和编码格式)转换为另一种视频格式.转码器在视音频编解码处理的程序中,属于一个比较复杂的东西.因为它结合了视频的解码和编码. ...

  2. 在stm32上移植wpa_supplicant(二)

    第一层调用的移植和裁剪. wpa_supplicant_init 照论文的指示,删除wpa_params和wpa_global相关的东西.初始化流程也相当简单,driver初始化,eap_regist ...

  3. ZOJ3865:Superbot(BFS) The 15th Zhejiang University Programming Contest

    一个有几个小坑的bfs 题目很长,但并不复杂,大概总结起来有这么点. 有t组输入 每组输入n, m, p.表示一个n*m的地图,每p秒按键会右移一次(这个等会儿再讲). 然后是地图的输入.其中'@'为 ...

  4. java web 学习二(Tomcat服务器学习和使用1)

    一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...

  5. 我们究竟什么时候可以使用Ehcache缓存

    一.Ehcache是什么 EhCache是Hibernate的二级缓存技术之一,可以把查询出来的数据存储在内存或者磁盘,节省下次同样查询语句再次查询数据库,大幅减轻数据库压力. 二.Ehcache的使 ...

  6. ORACLE临时表总结[转]

    临时表概念 临时表就是用来暂时保存临时数据(亦或叫中间数据)的一个数据库对象,它和普通表有些类似,然而又有很大区别.它只能存储在临时表空间,而非用户的表空间.ORACLE临时表是会话或事务级别的,只对 ...

  7. 从windows转向mac

    键盘问题: 按键对应表 Windows Mac ctrl command alt option 由此可推断,windows下的ctrl+c/v 变成了mac下的 command+c/v 功能对应表 删 ...

  8. Dubbo服务重载方法在JDK1.8上调用出错的问题(待解决)

    据说是javassist版本太低不支持JDK1.8,但是测试升级了还是调用出错.预留,待解决.

  9. ASP.NET MVC之Html.RenderAction

    WEB窗体模式开发惯了,切入MVC模式,好多东西都不懂,每一步都要查资料. 初步得来的一些知识点体会是: _Layout.cshtml就相当于母版页 然后partical视图(部分视图)就是用户控件. ...

  10. 【跟我一起学Python吧】Python的包管理工具

    刚开始学习Python时,在看文档和别人的blog介绍安装包有的用easy_install, setuptools, 有的使用pip,distribute,那麽这几个工具有什么关系呢,看一下下面这个图 ...