标签:
搜索。。。

6 7 10 13 10 11
7 -1 12
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define prt(k) cout<<#k" = "<<k<<endl;
const ll inf = 1e18;
ll ans;
void dfs(ll L, ll R)
{
if (R>=ans) return;
if (L < 0) return;
if(L==0) {
ans = R;
return;
}
if (R - L + 1 > L) return;
dfs(2*L - R - 1, R);
dfs(2*L - R - 2, R);
dfs(L, 2*R - L);
dfs(L, 2*R - L + 1);
}
ll L, R;
int main()
{
while (cin>>L>>R)
{
ans = inf;
dfs(L, R);
if (ans == inf) ans = -1;
cout<<ans<<endl;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5323 Solve this interesting problem
标签:
原文地址:http://blog.csdn.net/oilover/article/details/47110227