洛谷 CF670C Cinema
Description
- 莫斯科在举办一场重要的有n 个不同国家的珂学家参与的国际会议,每个珂学家都只会一种语言。为了方便起见,我们规定一种语言用1 到10^9 的数来描述。
在会议之后的晚上,珂学家们决定去看电影。他们去的电影院有m 场电影,每场有两个不同的数字,分别代表配音的语言和字幕的语言。如果一个珂学家能听懂配音,他会非常愉悦;如果能看懂字幕,他会比较满意。如果既看不懂也听不懂,他会很生气。
珂学家们决定去看同一场电影,你必须帮助他们选择一场电影,让愉悦的人最多的前提下,比较满意的人最多。
Input
- 输入格式: 第一行一个整数n(1≤n≤200000)表示珂学家个数。
第二行n 个整数a1,a2,...,an(1≤ai≤109)表示珂学家们会的语言。
第三行一个整数1≤m≤200000表示电影的场数。
第四行m 个整数b1,b2,...,bn(1≤bj≤109)表示电影的配音用的语言。
第五行m 个整数c1,c2,...,cn(1≤cj≤109)表示电影的字幕用的语言。
Output
- 输出格式: 一个整数表示安排哪一场电影。 如果有多种情况,选择比较满意的方案输出。
Sample Input
3 2 3 2 2 3 2 2 3
Sample Output
2
题解:
- 离散化。
- 虽说电影可以用int范围内的数字表达出来,但数组不可能开INT_MAX大。所以继续观察题目,发现数据中最多只会出现m * 2 + n种语言,也就是最大60w种,数组可以开。然后就离散化,直接用桶来统计每种语言人的数量,再选择满足题意要求的电影。
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 400005
using namespace std;
struct Obj {int x, y, z;} obj[N];
int n, m, cnt;
int a[N], b[N * 3], c[N * 3], d[N * 3];
int read()
{
int x = 0; char c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
return x;
}
int find(int x) {
return lower_bound(b + 1, b + 1 + cnt, x) - b;
}
bool cmp(Obj u, Obj v)
{
if(u.x == v.x)
{
if(u.y == v.y) return u.z < v.z;
else return u.y > v.y;
}
else return u.x > v.x;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++) a[i] = read(), b[++cnt] = a[i];
cin >> m;
for(int i = 1; i <= m; i++) obj[i].x = read(), b[++cnt] = obj[i].x, obj[i].z = i;
for(int i = 1; i <= m; i++) obj[i].y = read(), b[++cnt] = obj[i].y;
sort(b + 1, b + 1 + cnt);
cnt = unique(b + 1, b + 1 + cnt) - b - 1;
for(int i = 1; i <= n; i++)
c[find(a[i])]++, d[find(a[i])]++;
for(int i = 1; i <= m; i++) obj[i].x = c[find(obj[i].x)], obj[i].y = d[find(obj[i].y)];
sort(obj + 1, obj + 1 + m, cmp);
cout << obj[1].z;
return 0;
}