zoukankan      html  css  js  c++  java
  • BestCoder Round #61 1002 Game

    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)(1leq Nleq10000,1leq S,Tleq N )(1N10000,1S,TN)

    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!=1) cout<<"-1"<<endl;
            else if(abs(S-T)+1==N) cout<<"0"<<endl;
            else if((T==N || T==1) && abs(S-T)!=1) cout<<"2"<<endl;
            else if(S==1 || S==N || abs(S-T)==1) cout<<"1"<<endl;
            else cout<<"2"<<endl;
        }
        return 0;
    }
    View Code
    #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==1){cout<<"0
    ";goto k;}
            if(s==1&&t==n){cout<<"0
    ";goto k;}
            if(n==1&&t==s){cout<<"0
    ";goto k;}
            if(s==t){cout<<"-1
    ";goto k;}
            if(n==3){cout<<"0
    ";goto k;}
            if(t+1==s){cout<<"1
    ";goto k;}
            if(s+1==t){cout<<"1
    ";goto k;}
            if(t==1||t==n){cout<<"2
    ";goto k;}
            if(s==1||s==n){cout<<"1
    ";goto k;}
            else cout<<"2
    ";
            k: n=s=t=0;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    jqueryeasyui 使用笔记
    怎么查看端口占用情况?
    Ie6 Ie7 双倍padding
    Javascript获取URL
    fckeditor,用p替代div标签设置对齐方式
    ZenCart安全建站的几个措施和步骤
    复选框二选一 javascript
    dedecms从php设置里面去掉index.html
    ajax调用webservice返回DataTable "序列化类型为“System.Reflection.Module”的对象时检测到循环引用
    无题
  • 原文地址:https://www.cnblogs.com/dzzy/p/4926353.html
Copyright © 2011-2022 走看看