main
黄海 2 years ago
parent 8c90a04a94
commit 9f9f121a05

@ -1,4 +1,4 @@
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
@ -6,47 +6,47 @@ const int N = 1010;
int n;
int a[N];
int left[N][N], right[N][N];
int l[N][N], r[N][N]; // left,right 在 iostream库中用过了不能用
int main() {
int T;
scanf("%d", &T);
cin >> T;
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int len = 1; len <= n; len++)
for (int i = 1; i + len - 1 <= n; i++) {
int j = i + len - 1;
if (len == 1)
left[i][j] = right[i][j] = a[i];
l[i][j] = r[i][j] = a[i];
else {
int L = left[i][j - 1], R = right[i][j - 1], X = a[j];
int L = l[i][j - 1], R = r[i][j - 1], X = a[j];
if (R == X)
left[i][j] = 0;
l[i][j] = 0;
else if (X < L && X < R || X > L && X > R)
left[i][j] = X;
l[i][j] = X;
else if (L > R)
left[i][j] = X - 1;
l[i][j] = X - 1;
else
left[i][j] = X + 1;
l[i][j] = X + 1;
L = left[i + 1][j], R = right[i + 1][j], X = a[i];
L = l[i + 1][j], R = r[i + 1][j], X = a[i];
if (L == X)
right[i][j] = 0;
r[i][j] = 0;
else if (X < L && X < R || X > L && X > R)
right[i][j] = X;
r[i][j] = X;
else if (R > L)
right[i][j] = X - 1;
r[i][j] = X - 1;
else
right[i][j] = X + 1;
r[i][j] = X + 1;
}
}
if (n == 1)
puts("1");
else
printf("%d\n", left[2][n] != a[1]);
printf("%d\n", l[2][n] != a[1]);
}
return 0;

@ -207,7 +207,7 @@ $$
### 六、实现代码
```cpp {.line-numbers}
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
@ -215,50 +215,49 @@ const int N = 1010;
int n;
int a[N];
int left[N][N], right[N][N];
int l[N][N], r[N][N]; // left,right 在 iostream库中用过了不能用
int main() {
int T;
scanf("%d", &T);
cin >> T;
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int len = 1; len <= n; len++)
for (int i = 1; i + len - 1 <= n; i++) {
int j = i + len - 1;
if (len == 1)
left[i][j] = right[i][j] = a[i];
l[i][j] = r[i][j] = a[i];
else {
int L = left[i][j - 1], R = right[i][j - 1], X = a[j];
int L = l[i][j - 1], R = r[i][j - 1], X = a[j];
if (R == X)
left[i][j] = 0;
l[i][j] = 0;
else if (X < L && X < R || X > L && X > R)
left[i][j] = X;
l[i][j] = X;
else if (L > R)
left[i][j] = X - 1;
l[i][j] = X - 1;
else
left[i][j] = X + 1;
l[i][j] = X + 1;
L = left[i + 1][j], R = right[i + 1][j], X = a[i];
L = l[i + 1][j], R = r[i + 1][j], X = a[i];
if (L == X)
right[i][j] = 0;
r[i][j] = 0;
else if (X < L && X < R || X > L && X > R)
right[i][j] = X;
r[i][j] = X;
else if (R > L)
right[i][j] = X - 1;
r[i][j] = X - 1;
else
right[i][j] = X + 1;
r[i][j] = X + 1;
}
}
if (n == 1)
puts("1");
else
printf("%d\n", left[2][n] != a[1]);
printf("%d\n", l[2][n] != a[1]);
}
return 0;
}
```
Loading…
Cancel
Save