标签:语言 wing std max com amp print iostream names
首先对所有涉及到的语言离散化一下,统计会每种语言的人的个数
然后扫一遍电影,找到知道电影语言最多的人的那个电影
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
const int maxn = 600010;
typedef long long ll;
int n, m, cnt, q;
int L[maxn], a[maxn], b[maxn], c[maxn], lan[maxn], con[maxn], id[maxn];
ll read(){ ll s = 0, f = 1ll; char ch = getchar(); while(ch < ‘0‘ || ch > ‘9‘){ if(ch == ‘-‘) f = -1ll; ch = getchar(); } while(ch >= ‘0‘ && ch <= ‘9‘){ s = s * 10 + ch - ‘0‘; ch = getchar(); } return s * f; }
int main(){
n = read();
for(int i=1;i<=n;++i) a[i] = read(), L[++cnt] = a[i];
m = read();
for(int i=1;i<=m;++i) b[i] = read(), L[++cnt] = b[i];
for(int i=1;i<=m;++i) c[i] = read(), L[++cnt] = c[i];
sort(L+1,L+1+cnt);
for(int i=1;i<=cnt;++i){
if(i == 1 || L[i] != L[i-1]){
lan[++q] = L[i];
}
}
for(int i=1;i<=m;++i){
int pos = lower_bound(lan + 1,lan + 1 + q, b[i]) - lan;
id[pos] = i;
}
for(int i=1;i<=n;++i){
int pos = lower_bound(lan + 1, lan + 1 + q, a[i]) - lan;
++con[pos];
}
int ans = 0, mxb = 0, mxc = 0;
for(int i=1;i<=m;++i){
int posb = lower_bound(lan + 1, lan + 1 + q, b[i]) - lan;
int posc = lower_bound(lan + 1, lan + 1 + q, c[i]) - lan;
if(mxb < con[posb]){
ans = i;
mxb = con[posb];
mxc = con[posc];
}else if(mxb == con[posb]){
if(mxc < con[posc]){
ans = i;
mxc = con[posc];
}
}
}
printf("%d\n",ans);
return 0;
}
标签:语言 wing std max com amp print iostream names
原文地址:https://www.cnblogs.com/tuchen/p/13919383.html