算法1
(离散化) $O(nlogn)$
这题还是很容易想的,就是有个细节要注意,电影的使用的语言可能没有科学家会。
C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 200005;
int b[N][2];
int a[N], cp[N], times[N], n, m, tmp;
int main() {
cin.tie(0), ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], cp[i] = a[i];
sort(a+1, a+1+n);
int len = unique(a+1, a+1+n) - a - 1;
//算出每种语言懂的人的数量
for (int i = 1; i <= n; i++) times[lower_bound(a+1, a+1+len, cp[i]) - a]++;
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> tmp;
int p = lower_bound(a+1, a+1+len, tmp) - a;
if (a[p] != tmp) p = 0;//这里是易错点,可能找不到这门语言
b[i][0] = times[p];
}
for (int i = 1; i <= m; i++) {
cin >> tmp;
int p = lower_bound(a+1, a+1+len, tmp)-a;
if (a[p] != tmp) p = 0;
b[i][1] = times[p];
}
int j = 1;
for (int i = 2; i <= m; i++) {
if (b[i][0] > b[j][0]) j = i;
else if (b[i][0] == b[j][0] && b[i][1] > b[j][1]) j = i;
}
cout << j;
return 0;
}