题意翻译

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

题目描述

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}ai​is 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}bj​is 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}bj​≠cj​ .

输出格式:

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统计个数。
需要注意一点,放映的电影语言需要和珂学家们会的语言在同一个“离散系”中(没错,这词是我造的),才能保证正确。
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int n,m;
int a[],num[];
struct taojun{
int pos,ear,see;
}movie[];
map<int,int>f;
bool cmp(taojun a,taojun b)
{
if(num[a.ear]==num[b.ear]) return num[a.see]>num[b.see];
return num[a.ear]>num[b.ear];
}
int main()
{
scanf("%d",&n);
int cnt=;
for(int i=;i<=n;i++)
{
int x=;
scanf("%d",&x);
if(!f.count(x))
{
f[x]=cnt;
a[i]=cnt++;
}
else a[i]=f[x];
}
for(int i=;i<=n;i++) num[a[i]]++;
scanf("%d",&m);
for(int i=;i<=m;i++)
{
int x=;
scanf("%d",&x);
if(!f.count(x))
{
f[x]=cnt;
movie[i].ear=cnt++;
}
else movie[i].ear=f[x];
movie[i].pos=i;
}
for(int i=;i<=m;i++)
{
int x=;
scanf("%d",&x);
if(!f.count(x))
{
f[x]=cnt;
movie[i].see=cnt++;
}
else movie[i].see=f[x];
}
sort(movie+,movie++m,cmp);
printf("%d",movie[].pos);
return ;
}

大道至简!

 

CF670C Cinema 【离散化+map】的更多相关文章

  1. CF 19D 线段树+set压缩坐标轴+离散化map

    题意: n个操作,在200000*200000的平面上加删点 find 严格在坐标右上角,x最小,再y最小的点 线段树做,区间为离散化后的 X轴坐标 ,维护区间点数 和 最小的 y 值 ( 维护最小y ...

  2. 1034. Head of a Gang (30) -string离散化 -map应用 -并查集

    题目如下: One way that the police finds the head of a gang is to check people's phone calls. If there is ...

  3. CF670C cinema

    想必是个半水题,div2的C嘛 仔细观察,发现排序可做. 怎么排序呢?排啥呢?拿啥离散化,拿啥结构体呢? 仔细思考热静分析,便可得出结论: 以每个人会的语言离散化,把每个电影建结构体后不排序,而是枚举 ...

  4. 项目安排(离散化+DP)

    题目来源:网易有道2013年校园招聘面试二面试题 题目描述: 小明每天都在开源社区上做项目,假设每天他都有很多项目可以选,其中每个项目都有一个开始时间和截止时间,假设做完每个项目后,拿到报酬都是不同的 ...

  5. CodeForces 19D Points(线段树+map)

    开始想不通,后来看网上说是set,就有一个想法是对每个x建一个set...然后又想直接建立两重的set就好,最后发现不行,自己想多了...  题意是给你三种操作:add (x y) 平面添加(x y) ...

  6. 2017-2018 ACM-ICPC Latin American Regional Programming Contest GYM101889

    挺有意思的一套题,题也没有啥毒瘤了,本来是队切的结果种种原因大家全挂机了. 只补了百人题,一共7个,其他的暂时先不补了,,也不会嘛qwq H:签到 #include <bits/stdc++.h ...

  7. Codeforces 670 - A/B/C/D/E/F - (Done)

    链接:https://codeforces.com/contest/670 A - Holidays - [水] AC代码: #include<bits/stdc++.h> using n ...

  8. CSA Round #84 The Sprawl

    题目 Analysis 曼哈顿距离($L1$ metric)最小生成树. Implementation 下面的代码参考了 gispzjz 在比赛中的提交. #include <bits/stdc ...

  9. CodeForces 670C Cinema(排序,离散化)

    C. Cinema time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

随机推荐

  1. 洛谷——P1265 公路修建

    P1265 公路修建 题目描述 某国有n个城市,它们互相之间没有公路相通,因此交通十分不便.为解决这一“行路难”的问题,政府决定修建公路.修建公路的任务由各城市共同完成. 修建工程分若干轮完成.在每一 ...

  2. P2839 畅通工程

    P2839 畅通工程 题目描述 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连, ...

  3. 重装JDK后Tomcat和Eclipse的配置

    比如JDK之前是1.8.0_31的,升级之后变成了1.8.0_131之后,Tomcat需要做如下配置: 对于Eclipse中之前配置的Tomcat需要删除后重新添加一个.

  4. 使用Guava适配不同的callback

    Cache<Key,Value> cache =CacheBuilder.newBuilder() .maximumSize(1000) .build();// look Ma, no C ...

  5. influxDB系列(一)

    这个是github上面一个人总结的influxDB的操作手册,还不错:https://xtutu.gitbooks.io/influxdb-handbook/content/zeng.html 1. ...

  6. vi和vim上查找字符串

    方法/步骤 1 我们以samba的配置文件为例,搜索一个user的字符串. vim /etc/samba/smb.conf 打开smb.conf 2 命令模式下,输入/user "/&quo ...

  7. 《Spring设计思想》AOP设计基本原理

    0.前言 Spring 提供了AOP(Aspect Oriented Programming) 的支持, 那么,什么是AOP呢?本文将通过一个另外一个角度来诠释AOP的概念,帮助你更好地理解和使用Sp ...

  8. spring 学习资料

    spring 官方教程 1.3.1 http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/index.html ...

  9. 树莓派的PWM脉宽调制功能介绍

    近期想用树莓派控制航模的电调,于是研究了下PWM.貌似控制电调比較麻烦,由于电调须要发送几个特定的信号启动,然后才干进入控制模式.今天先弄明确PWM,慢慢折腾.以下的程序亲測可用,我用的树莓派mode ...

  10. 使用OnScrollListener回调处理自己主动载入很多其它

    首先来分析下OnScrollListener的回调. new OnScrollListener() { boolean isLastRow = false; @Override public void ...