P6926 [ICPC 2016 WF] String Theory
Sol
注意到数据范围很小,所以考虑直接枚举答案,暴力 check 即可。
Code
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define desktop "C:\\Users\\incra\\Desktop\\"
#define IOS ios :: sync_with_stdio (false),cin.tie (0),cout.tie (0)
#define debug(x) cerr << #x << ' ' << x << endl
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> PII;
const int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};
template <typename T1,typename T2> bool tomax (T1 &x,T2 y) {
if (y > x) return x = y,true;
return false;
}
template <typename T1,typename T2> bool tomin (T1 &x,T2 y) {
if (y < x) return x = y,true;
return false;
}
LL power (LL a,LL b,LL p) {
if (!a) return 0;
LL ans = 1;
while (b) {
if (b & 1) ans = ans * a % p;
a = a * a % p;
b >>= 1;
}
return ans;
}
int fastio = (IOS,0);
#define endl '\n'
#define puts(s) cout << (s) << endl
const int N = 110;
int n;
int a[N],b[N];
bool check (int x) {
for (int i = 1;i <= n;i++) b[i] = a[i];
int l = 1,r = n;
int i;
for (i = x;i > 1 && l <= r;i--) {
if (b[l] < i) break;
b[l] -= i;
if (!b[l]) l++;
if (b[r] < i) break;
b[r] -= i;
if (!b[r]) r--;
}
return l <= r && i == 1;
}
void mian () {
cin >> n;
int sum = 0;
for (int i = 1;i <= n;i++) cin >> a[i],sum += a[i];
if (sum & 1) {
puts ("no quotation");
return ;
}
for (int i = min (a[1],a[n]);i >= 2;i--) {
if (check (i)) {
cout << i << endl;
return ;
}
}
if (sum == 2) puts ("1");
else puts ("no quotation");
}
int main () {
int T = 1;
// cin >> T;
while (T--) mian ();
return 0;
}

浙公网安备 33010602011771号