A. Stone Game
思路:总共3种情况,都从最左端被拿走,都从最右端被拿走,左侧的从最左端被拿走且右侧的从最右端被拿走,取最小值即可
代码:
//CF-725.A
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
#define INF 0x3f3f3f3f
const double EPS = 1e-18;
const int MOD = 1e9 + 7;
const int maxn = 8e4 + 1;
int T;
int N, A[maxn];
void solve()
{
int maxi = -1, mini = -1, maxa = -1, mina = INF;
for (int i = 0; i < N; i++)
{
if (A[i] < mina)
{
mina = A[i];
mini = i;
}
if (A[i] > maxa)
{
maxa = A[i];
maxi = i;
}
}
if (mini < maxi)
{
int ans[3];
ans[0] = mini + 1 + N - maxi;
ans[1] = max(mini, maxi) + 1;
ans[2] = N - min(mini, maxi);
int res = INF;
for (int i = 0; i < 3; i++)
res = min(res, ans[i]);
cout << res << endl;
return;
}
else
{
int ans[3];
ans[0] = maxi + 1 + N - mini;
ans[1] = max(mini, maxi) + 1;
ans[2] = N - min(mini, maxi);
int res = INF;
for (int i = 0; i < 3; i++)
res = min(res, ans[i]);
cout << res << endl;
return;
}
}
int main()
{
IOS;
cin >> T;
while (T--)
{
cin >>