• 微信公众号：美女很有趣。 工作之余，放松一下，关注即送10G+美女照片！

# CF1291B 题解

1周前 (05-02) 8次浏览

#### 题目分析

[0,1,2,…,M-1,M,M-1,…,2,1,0
]

(n) 为奇数时，上方叙述成立。但是当 (n) 为偶数时，我们需要构造这样两个 (b) 数列：

[0,1,2,…,M-1,M,M-1,M-2,…,2,1,0
]

[0,1,2,…,M-2,M-1,M,M-1,…,2,1,0
]

#### 代码

``````#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll T, n;
ll a[300005], b[300005];

void C(){ //不能初始化整个数组，否则会 TLE
memset(a, 0, sizeof(long long) * (n + 1));
memset(b, 0, sizeof(long long) * (n + 1));
}

int main()
{
while (T--){
C();
if (n % 2 == 1) { //n为奇数
for (int i = 1; i <= n; ++i)
ll h = 1, t = n, cnt = -1;
while (1) { //构造 b 数列
if (h == t){
b[h] = ++cnt;
break;
}
b[h] = b[t] = ++cnt;
h++, t--;
}
bool ok = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] < b[i]) {
puts("No");
ok = 1;
break;
}
}
if (ok == 0)
puts("Yes");
}
else { //n为偶数
int sb;
for (int i = 1; i <= n; ++i)

ll h = 1, t = n, cnt = -1;
while (1) { //构造 b 数列
if (h + 1 == t) {
b[h] = b[t] = ++cnt;
sb = h;
b[h]++;
break;
}

b[h] = b[t] = ++cnt;
h++, t--;
}
bool ok = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] < b[i]) {
ok = 1;
break;
}
}
if (ok == 0) {
puts("Yes");
continue;
}

b[sb]--; //换成第二个 b 数列
b[sb + 1]++;

ok = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] < b[i]) {
puts("No");
ok = 1;
break;
}
}
if (ok == 0)
puts("Yes");
}
}
return 0;
}
``````