Codeforces 670C Cinema

题目链接:https://codeforces.com/problemset/problem/670/C

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 200010;

// n个科学家,数组a存储每个科学家使用的语言
int n, a[N];

// m场电影,数组b和数组c分别存储每场电影的配音语言和字幕语言
int m, b[N], c[N];

// tot和数组lang存储涉及到的所有语言,len存储去重后的语言种数
int lang[N * 3], tot, len;

// 数组p存储每种语言被多少个科学家使用
int p[N * 3];

int get(int x)
{
    return lower_bound(lang + 1, lang + len + 1, x) - lang;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        lang[++tot] = a[i];
	}
	
	scanf("%d", &m);
	for (int i = 1; i <= m; i++)
	{
	    scanf("%d", &b[i]);
	    lang[++tot] = b[i];
	}
	for (int i = 1; i <= m; i++)
	{
	    scanf("%d", &c[i]);
	    lang[++tot] = c[i];
	}
	
	// 离散化
	sort(lang + 1, lang + tot + 1);
	len = unique(lang + 1, lang + tot + 1) - (lang + 1);
	
	for (int i = 1; i <= n; i++)
	{
	    p[get(a[i])]++;
	}
	
	int ans = -1, maxb = -1, maxc = -1;
	for (int i = 1; i <= m; i++)
	{
	    int bn = p[get(b[i])]; // 能听懂该场电影配音(愉悦)的科学家个数
	    int cn = p[get(c[i])]; // 能看懂该场电影字幕(满意)的科学家个数
	    if(bn > maxb || (bn == maxb && cn > maxc))
	    {
	        ans = i;
	        maxb = bn;
	        maxc = cn;
	    }
	}
	
	printf("%d\n", ans);
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值