标签:输出 \n i++ mes for cstring || c++ scan
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int cmp[305][305], ans[305];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n + 1; i++) {
for (int j = 1, x; j <= n; j++) {
scanf("%d", &x);
cmp[i][x] = j;
}
}
int fir = 0, sec = 0;
memset(ans, 0x3f, sizeof ans);
for (int i = 1; i <= n; i++) {
if (!fir || cmp[n + 1][fir] > cmp[n + 1][i]) sec = fir, fir = i;
else if (!sec || cmp[n + 1][sec] > cmp[n + 1][i]) sec = i;
for (int j = 1; j <= n; j++) {
if (fir && fir != j) {
if (ans[j] > 500 || cmp[j][ans[j]] > cmp[j][fir]) {
ans[j] = fir;
}
} else if (sec && sec != j) {
if (ans[j] > 500 || cmp[j][ans[j]] > cmp[j][sec]) {
ans[j] = sec;
}
}
}
}
for (int i = 1; i <= n; i++)
printf("%d%c", ans[i], " \n"[i == n]);
}
标签:输出 \n i++ mes for cstring || c++ scan
原文地址:https://www.cnblogs.com/AlphaWA/p/10894902.html