3730. 寻找序列
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;
const int N = 120;
int t;
int n;
int cnt;
int p[N];
int a[3][N];
int main() {
cin >> t;
while (t--) {
scanf("%d", &n);
for (int i = 0; i < 3; ++i) {
for (int j = 1; j <= n; ++j) {
scanf("%d", &a[i][j]);
}
}
p[1] = a[0][1];
for (int i = 2; i <= n; ++i) {
for (int j = 0; j < 3; ++j) {
if (a[j][i] != p[i - 1]) {
if (i != n) {
p[i] = a[j][i];
break;
} else if (i == n && a[j][i] != p[1]) {
p[i] = a[j][i];
break;
}
}
}
}
for (int i = 1; i <= n; ++i) {
cout << p[i] << " ";
}
cout << endl;
}
return 0;
}
题解:题目要求得是每次从三个数组的相同下标选出一个元素构成新的序列,这个序列要求前一个数字和后一个数字不相等,第一个数字和最后一个数字不相等。所以直接构造就行。