1.题目链接。找一下规律,其实上下基本上是对称的,所以只需要考虑下半部分最小就好了。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, k;
while (cin >> n >> k)
{
if (n == 1)
{
cout << 1 << endl;
}
else
{
cout << min(k, n - k + 1) * 2 << endl;
}
}
return 0;
}