CF670C Cinema 【离散化+map】

题意翻译

莫斯科在举办一场重要的有 nn 个不同国家的珂学家参与的国际会议,每个珂学家都只会一种语言。为了方便起见,我们规定一种语言用 11 到 10^9109 的数来描述。 在会议之后的晚上,珂学家们决定去看电影。他们去的电影院有 mm 场电影,每场有两个不同的数字,分别代表配音的语言和字幕的语言。如果一个珂学家能听懂配音,他会非常愉悦;如果能看懂字幕,他会比较满意。如果既看不懂也听不懂,他会很生气。 珂学家们决定去看同一场电影,你必须帮助他们选择一场电影,让愉悦的人最多的前提下,比较满意的人最多。 输入格式: 第一行一个整数 n(1 \leq n \leq 200000)n(1n200000) 表示珂学家个数。 第二行 nn 个整数 a_1, a_2, ..., a_n(1 \leq a_i \leq 10^9)a1,a2,...,an(1ai109) 表示珂学家们会的语言。 第三行一个整数 1 \leq m \leq 2000001m200000 表示电影的场数。 第四行 mm 个整数 b_1, b_2, ..., b_n(1 \leq b_j \leq 10^9)b1,b2,...,bn(1bj109) 表示电影的配音用的语言。 第五行 mm 个整数 c_1, c_2, ..., c_n(1 \leq c_j \leq 10^9)c1,c2,...,cn(1cj109) 表示电影的字幕用的语言。 输出格式: 一个整数表示安排哪一场电影。 如果有多种情况,选择比较满意的方案输出。

题目描述

Moscow is hosting a major international conference, which is attended by nn scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 11 to 10^{9}109 .

In the evening after the conference, all nn scientists decided to go to the cinema. There are mm movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

输入输出格式

输入格式:

The first line of the input contains a positive integer nn ( 1<=n<=2000001<=n<=200000 ) — the number of scientists.

The second line contains nn positive integers a_{1},a_{2},...,a_{n}a1,a2,...,an ( 1<=a_{i}<=10^{9}1<=ai<=109 ), where a_{i}aiis the index of a language, which the ii -th scientist knows.

The third line contains a positive integer mm ( 1<=m<=2000001<=m<=200000 ) — the number of movies in the cinema.

The fourth line contains mm positive integers b_{1},b_{2},...,b_{m}b1,b2,...,bm ( 1<=b_{j}<=10^{9}1<=bj<=109 ), where b_{j}bjis the index of the audio language of the jj -th movie.

The fifth line contains mm positive integers c_{1},c_{2},...,c_{m}c1,c2,...,cm ( 1<=c_{j}<=10^{9}1<=cj<=109 ), where c_{j}cj is the index of subtitles language of the jj -th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that is b_{j}≠c_{j}bjcj .

输出格式:

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

输入输出样例

输入样例#1: 
3
2 3 2
2
3 2
2 3
输出样例#1: 
2
输入样例#2: 
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
输出样例#2: 
1

冷静分析
显然我们是可以用桶的思想来统计会哪种语言的人数最多。
然而数据非常的不友好,居然刚到了1e9,显然我们不能开这么大的数组。那么可以离散化一下,这里用到了map。

用一个a数组来统计珂学家们会的语言,经map f数组离散后用num统计个数。
需要注意一点,放映的电影语言需要和珂学家们会的语言在同一个“离散系”中(没错,这词是我造的),才能保证正确。


 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<map>
 5 using namespace std;
 6 int n,m;
 7 int a[300000],num[300000];
 8 struct taojun{
 9     int pos,ear,see;
10 }movie[300000];
11 map<int,int>f;
12 bool cmp(taojun a,taojun b)
13 {
14     if(num[a.ear]==num[b.ear]) return num[a.see]>num[b.see];
15     return num[a.ear]>num[b.ear];
16 }
17 int main()
18 {
19     scanf("%d",&n);
20     int cnt=1;
21     for(int i=1;i<=n;i++)
22     {
23         int x=0;
24         scanf("%d",&x);
25         if(!f.count(x))
26         {
27             f[x]=cnt;
28             a[i]=cnt++;
29         }
30         else a[i]=f[x];
31     }
32     for(int i=1;i<=n;i++) num[a[i]]++;
33     scanf("%d",&m);
34     for(int i=1;i<=m;i++)
35     {
36         int x=0;
37         scanf("%d",&x);
38         if(!f.count(x))
39         {
40             f[x]=cnt;
41             movie[i].ear=cnt++;
42         }
43         else movie[i].ear=f[x];
44         movie[i].pos=i;
45     }
46     for(int i=1;i<=m;i++)
47     {
48         int x=0;
49         scanf("%d",&x);
50         if(!f.count(x))
51         {
52             f[x]=cnt;
53             movie[i].see=cnt++;
54         }
55         else movie[i].see=f[x];
56     }    
57     sort(movie+1,movie+1+m,cmp);
58     printf("%d",movie[1].pos);
59     return 0;
60  } 
View Code

大道至简!

 

猜你喜欢

转载自www.cnblogs.com/nopartyfoucaodong/p/9076319.html