CF670C Cinema

难度:4
离散化的例题,里面需要我们处理的数据是语言,范围是10的9次方,但是实际的语言的种类不超过6乘10的5次方,我们不在意语言的绝对值,只需要语言的想对大小,来表明,这两个不是一种语言就行了,所以输入所有的语言,同时存到总的数组里面,进行离散化,离散化之后就可以遍历科学家,用散列来记录科学家每种语言的个数,然后遍历电影院,用之前的离散化获得影院两种语言对应的数,来更新答案

离散化的步骤,
储存数据并排序,
去重,
利用二分来查询原来的数据映射为了什么

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;

const int N = 2e5 + 5;

int a[N], b[N], c[N], rec[N * 3], d[N * 3], Hash[N * 3];

int main() {
    int n;
    cin >> n;
    int cur = 0;
    for (int i = 0; i < n; i++) { cin >> a[i]; rec[cur++] = a[i]; }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) { cin >> b[i]; rec[cur++] = b[i]; }
    for (int i = 0; i < m; i++) { cin >> c[i]; rec[cur++] = c[i]; }
    int cnt = 0;
    sort(rec, rec + cur);
    for (int i = 0; i < cur; i++) {
        if (!i || i && rec[i] != rec[i - 1]) d[cnt++] = rec[i];
    }
    for (int i = 0; i < n; i++) {
        int x = lower_bound(d, d + cnt, a[i]) - d;
        Hash[x]++;
    }
    int ans, max1 = -1, max2 = -1;
    for (int i = 0; i < m; i++) {
        int x = lower_bound(d, d + cnt, b[i]) - d;
        int y = lower_bound(d, d + cnt, c[i]) - d;
        if (Hash[x] > max1) {
            max1 = Hash[x];
            max2 = Hash[y];
            ans = i;
        } else if (Hash[x] == max1 && Hash[y] > max2) {
            max2 = Hash[y];
            ans = i;
        }
    }
    cout << ans + 1;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值