比赛时50分.
当时的想法就是
对于最小: 类似于二分,分成两半,取小的那一半继续分,记录次数
对于最大: 直接输出大的那一边
−
1
-1
−1
有一个特判就是
如果
x
+
1
=
=
y
x+1==y
x+1==y就直接在
y
−
z
y-z
y−z处理。
如果
y
+
1
=
=
z
y+1==z
y+1==z就直接在
x
−
y
x-y
x−y处理。
事实证明,我想的太复杂了(对于最小)
除去
0
,
1
0,1
0,1的情况,其实我们只需要输出
2
2
2就行了
Why?
因为可以我们直接将结尾端点放到开头端点+2的地方,这样就演变成了
1
1
1的情况,
1
+
1
=
2
1+1=2
1+1=2
A
C
C
o
d
e
AC~Code
AC Code
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int x,y,z,xy,yz;
int main()
{
freopen("herding.in","r",stdin);
freopen("herding.out","w",stdout);
cin>>x>>y>>z;
if(x+1==y&&y+1==z) //0的情况
cout<<0<<endl;
else if(x+2==y||y+2==z) //1的情况
cout<<1<<endl;
else //2的情况
cout<<2<<endl;
xy=y-x,yz=z-y; //求最大,一位一位挪,所以是最大区间-1
if(xy>yz)
cout<<xy-1;
else
cout<<yz-1;
return 0;
}