**hdu5523

来源:互联网 发布:聊天软件排名 编辑:程序博客网 时间:2024/05/29 19:24

题目:点击打开链接

题解:无解的情况只有起点和终点位置一样且N不为1。终点和起点都在边界上答案为0,如果起点在边界上或者起点终点相邻答案为1,其他答案为2.

代码:

#include<stdio.h>#include<math.h>#include <algorithm>#include <iostream>#include<string.h>#include<stdlib.h>using namespace std;int main(){    int n,s,t;    while(scanf("%d%d%d",&n,&s,&t)!=EOF)    {        if(n>1&&s==t)        {            printf("-1\n");        }        //else if((s>t&&n>s&&n==s)||(s>1&&t>s&&s==1))        else if((s==1&&t!=n)||(t!=1&&s==n)||(s!=1&&s+1==t)||(s!=n&&t+1==s))        {            printf("1\n");        }        else if((s==1&&t==n)||(s==n&&t==1))        {            printf("0\n");        }        else        {            printf("2\n");        }    }    return 0;}

多种情况,我开始考虑到情况为2 的各种情况,后来才发现情况好多。情况为-1,0,1的可以一一列出来,应该多考虑考虑


大哭



0 0
原创粉丝点击