电影

code

#include<iostream>
#include<algorithm>
using namespace std;
int n, m, k, tot = 0;
const int N = 2e5 + 50;
//languige come from scientiet,audio and subtitles.Need to multiple 3
int lang[3 * N], uni[3 * N], a[N], b[N], c[N], ans[3 * N];
int find(int x) {
	return lower_bound(uni + 1, uni + 1 + k, x) - uni;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		lang[++tot] = a[i];
	}
	cin >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> b[i];
		lang[++tot] = b[i];
	}
	for (int i = 1; i <= m; ++i) {
		cin >> c[i];
		lang[++tot] = c[i];
	}
	//deduplicaiton
	sort(lang + 1, lang + 1 + tot);
	int cur = unique(lang + 1, lang + 1 + tot) - lang;
	for (int i = 1; i <= cur; ++i) {
	//array uni is store new dense index 
		uni[++k] = lang[i];
	}

	for (int i = 1; i <= n; ++i) {
		++ans[find(a[i])];
	}
	int ans0, ans1, ans2; //move index,audio index,subtitles index
	ans0 = ans1 = ans2 = 0;
	for (int i = 1; i <= m; ++i) {
		int audio = ans[find(b[i])], subtitles = ans[find(c[i])];
		if (audio > ans1 || (audio == ans1 && subtitles > ans2)) {
			ans0 = i, ans1 = audio, ans2 = subtitles;
		}
	}
	if (ans0 == 0) {
		//no solution .randomly selected
		cout << 1;
	} else {
		cout << ans0;
	}
	return 0;
}

quetion

电影
   题目
   提交记录
   讨论
   题解
   视频讲解

莫斯科正在举办一个大型国际会议,有 n 个来自不同国家的科学家参会。

每个科学家都只懂得一种语言。

为了方便起见,我们把世界上的所有语言用 1 到 109 之间的整数编号。

在会议结束后,所有的科学家决定一起去看场电影放松一下。

他们去的电影院里一共有 m 部电影正在上映,每部电影的语音和字幕都采用不同的语言。

对于观影的科学家来说,如果能听懂电影的语音,他就会很开心;如果能看懂字幕,他就会比较开心;如果全都不懂,他就会不开心。

现在科学家们决定大家看同一场电影。

请你帮忙选择一部电影,可以让观影很开心的人最多。

如果有多部电影满足条件,则在这些电影中挑选观影比较开心的人最多的那一部。

输入格式
第一行输入一个整数 n,代表科学家的数量。

第二行输入 n 个整数 a1,a2…an,其中 ai 表示第 i 个科学家懂得的语言的编号。

第三行输入一个整数 m,代表电影的数量。

第四行输入 m 个整数 b1,b2…bm,其中 bi 表示第 i 部电影的语音采用的语言的编号。

第五行输入 m 个整数 c1,c2…cm,其中 ci 表示第 i 部电影的字幕采用的语言的编号。

请注意对于同一部电影来说,bi≠ci。

同一行内数字用空格隔开。

输出格式
输出一个整数,代表最终选择的电影的编号。电影编号 1∼m。

如果答案不唯一,输出任意一个均可。

数据范围
1≤n,m≤200000,
1≤ai,bi,ci≤109
输入样例:
3
2 3 2
2
3 2
2 3
输出样例:
2
posted @ 2022-03-15 09:25  ethon-wang  阅读(34)  评论(0编辑  收藏  举报