**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
- **hdu5523
- hdu5523 Game
- BestCoder Round #61 (div.2) HDU5523 Game
- HDU5522【二分】&&HDU5523【。。】&&HDU5524【完全二叉树】
- 【HDU5523 BC61 div1 A】Game 一行n个数从st到ed每点走一次
- BestCoder Round #61 (div.2)(hdu5522,hdu5523,hdu5524,hdu5525(数论:费马小定理))
- leetcode-Invert Binary Tree
- 【安卓】仿淘宝购物车
- log4j.properties配置详解
- Oracle日期周详解以及周开始结束时间计算
- HTTP/1.1协议的curl 返回 HTTP/1.1 100 Continue 加上header 加上body
- **hdu5523
- Markdown嵌入视频
- 【UKIEPC2015 I】【模拟】Nimionese 特殊语言转化 逻辑清晰暴力扫描
- LeetCode--Linked List Cycle
- thread的join和detach
- error C2556: “void main(void)”: 重载函数与“int main(void)”只是在返回类型上不同
- POJ 3687 Labeling Balls (反向拓扑排序)
- 关于 Apple Metal API 的一些想法
- Arc Engien 学习(一)