BestCoder Round #61 1002 Game
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.
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)(1\leq N\leq10000,1\leq S,T\leq N )(1≤N≤10000,1≤S,T≤N)
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.
4 1 4
4 1 3
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!=) cout<<"-1"<<endl;
else if(abs(S-T)+==N) cout<<""<<endl;
else if((T==N || T==) && abs(S-T)!=) cout<<""<<endl;
else if(S== || S==N || abs(S-T)==) cout<<""<<endl;
else cout<<""<<endl;
}
return ;
}
#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==){cout<<"0\n";goto k;}
if(s==&&t==n){cout<<"0\n";goto k;}
if(n==&&t==s){cout<<"0\n";goto k;}
if(s==t){cout<<"-1\n";goto k;}
if(n==){cout<<"0\n";goto k;}
if(t+==s){cout<<"1\n";goto k;}
if(s+==t){cout<<"1\n";goto k;}
if(t==||t==n){cout<<"2\n";goto k;}
if(s==||s==n){cout<<"1\n";goto k;}
else cout<<"2\n";
k: n=s=t=;
}
return ;
}
BestCoder Round #61 1002 Game的更多相关文章
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [f(n ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- Manacher BestCoder Round #49 ($) 1002 Three Palindromes
题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...
- 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil
题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...
- hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]
传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131 ...
- BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)
今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...
- BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...
- BestCoder Round #80 1002
HDU 5666 Segment 题意:给你条斜率为-1,常数项为q(q为质数)的直线,连接原点与直线上整数格点,问你在有多少个格点在形成的无数个三角形内,而不在线段上,结果对P取模. 思路:best ...
随机推荐
- UINT数相减
UINT32 i = ; UINT32 j = ; i - j > //这个将永远为真,因为他是将将结果按照无符号解析 int = i -j; //这个是-1,是按照有符号解析 今天发现代码里面 ...
- centos搭建 nginx一直报错 file not found.
百度了半天找到别人的解决办法 记录下 摘要: file not found. nginx php 这个问题是你配置文件的问题: 查看就是了不要管 nginx 如何开启解析 PHP 的功能? # 成功安 ...
- WinForm使用皮肤图文步骤
Winfrom本身样式提供的是Windows经典样式.. 不说多丑也绝称不上好看..有时为了用户体验就不得不需要想办法弄漂亮一点..皮肤包会是一个不错的选择.. 不废话了..开整.. 首先从网上下载免 ...
- F5负载均衡的初识和基本配置
目前全球范围内应用比较广泛的负载均衡设备为美国的F5.F5于2000年底进驻中国,在国内业界,F5负载均衡产品已经成为了主流负载均衡技术的代名词.下面我们对F5负载均衡设备做一个基本介绍,方便大家去认 ...
- checkstyle配置文件说明
属性说明 basedir代码所在的位置 AbstractClassNameformat: 定义抽象类的命名规则 PackageNameformat: 定义包名的命名规则 TypeNameformat: ...
- [CentOS]添加删除用户
摘要 在安装CentOS的时候,我们只设置了root,类似windows的超级管理员.当然我们在工作的时候,为了安全考虑,不可能对外开发root,一方面是从安全的角度,另一方面也是方便管理. 添加删除 ...
- angular-ngSanitize模块-$sanitize服务详解
本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一个指令: ng-bing-html. 顾名思义,ng-bind-html和 ...
- border边框的宽度/样式/颜色 全部值
border 用emmet写border的时候, 缩写是:bd. 不是b, 也不是bdr: b会扩展成bottom, bdr 会扩展成 border-right, border的宽度: 1px 基本上 ...
- unslider的用法详解
unslider本身下载后只需要dist文件夹就好了, 其中只包含dist/js/unslider-min.js, jquery的js要自己提供; dist/css/unslider.css是主要的c ...
- virtualBox切换到无缝模式后,如何调出菜单
host+c host就是指右边的那个ctrl键