Codeforces Gym 100637B B. Lunch finding Patterns

Source: Internet
Author: User

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

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 Sitti Ng 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's is on to has lunch. It can jump-to-the bordering leaf or jump it up to the next one in any direction. When landing it eats a fly. Kvait is already quite a big toad and the leaves were unstable so when it jumps away the leaf starts sinking.

In order to has lunch kvait needs to eat all of the flies. It starts his journey from the leaf with number s and have 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 n, s, F (2≤ n ≤10, 1≤ s, fn)-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 has lunch. If there is no-it-eat up, output a single number -1.

Sample Input

4 1 2

Sample Output

1

HINT

Test instructions

There are n points, each time a frog can jump one or two steps, ask to traverse all points from the S point and finally fall at the F point, the number of steps that require a minimum step to jump

Exercises

I was writing DFS and then the violence against the PAT

We jump 3 steps, you can just pick one step, all other times need to skip ...

Code

#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************intMain () {intN=read (), F=read (), s=read (); intans=0; if(f<s) swap (f,s); if(s==f) {cout<<"-1"<<Endl; return 0; }    if(s!=1) {ans+=1; S=s+1; if(s==f) {if(f==N) cout<<ans<<Endl; Elsecout<<"-1"<<Endl; return 0; }    }    if(f!=N) {ans+=1; F-=1; if(s==f) {cout<<ans<<Endl; return 0; }} ans+ = ((f-s)/3) + (f-s)%3; cout<<ans<<Endl;}

Codeforces Gym 100637B B. Lunch finding Patterns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.