注意二维数组的灵活应用,包含下标与值的关系
将输入的值作为数组的坐标!!!!
#include <bits/stdc++.h>
using namespace std;
int p[11][21];
int main()
{
int k, n;
cin >> k >> n;
for (int i = 1; i <= k; i++)//行
for (int j = 1; j <= n; j++) {//列
int x;
cin >> x;
p[i][x] = j;
}
int res = 0;
for (int i = 1; i <= n; i++)//枚举比较,不用担心超时问题
{
for (int j = 1; j <= n; j++) {
bool flag = 0;
for (int a = 1; a <= k; a++) {
if (p[a][i] >= p[a][j])
flag = 1;
}
if (!flag) res++;
}
}
cout << res << endl;
return 0;
}