Codeforces Round #350 (Div. 2) C. Cinema
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m 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 n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is 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.
3
2 3 2
2
3 2
2 3
2
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
1
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly twoscientists will be very pleased and all the others will be not satisfied.
排序加二分。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m;
int pe[];
int au[],sub[];
int spe[],c = ;
int index,aun,subn;
int get(int x) {
int l = ,r = c - ;
while(l <= r) {
int mid = (l + r) / ;
if(pe[spe[mid]] < x) l = mid + ;
else if(pe[spe[mid]] > x) r = mid - ;
else return spe[mid + ] - spe[mid];
}
return ;
}
int main() {
scanf("%d",&n);
for(int i = ;i < n;i ++) {
scanf("%d",&pe[i]);
}
sort(pe,pe + n);
for(int i = ;i < n;i ++) {
if(pe[i] == pe[i - ]) continue;
spe[c ++] = i;
}
spe[c] = n;
scanf("%d",&m);
for(int i = ;i < m;i ++) {
scanf("%d",&au[i]);
}
for(int i = ;i < m;i ++) {
scanf("%d",&sub[i]);
}
for(int i = ;i < m;i ++) {
int a = get(au[i]),b = get(sub[i]);
if(aun < a) {
index = i;
aun = a;
subn = b;
}
else if(aun == a && subn < b) {
index = i;
subn = b;
}
}
printf("%d",index + );
}
Codeforces Round #350 (Div. 2) C. Cinema的更多相关文章
- Codeforces Round #350 (Div. 2) C. Cinema 水题
C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...
- Codeforces Round #350 (Div. 2)A,B,C,D1
A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表
E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- Codeforces Round #350 (Div. 2) B. Game of Robots 水题
B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...
随机推荐
- Java 访问限制符 在同一包中或在不同包中:使用类创建对象的权限 & 对象访问成员变量与方法的权限 & 继承的权限 & 深入理解protected权限
一.实例成员与类成员 1. 当类的字节码被加载到内存, 类中类变量.类方法即被分配了相应内存空间.入口地址(所有对象共享). 2. 当该类创建对象后,类中实例变量被分配内存(不同对象的实例变量互不相同 ...
- 数组的常用方法concat,join,slice和splice的区别,map,foreach,reduce
1.concat()和join() concat()是连对两个或两个数组的方法,直接可以将数组以参数的形式放入 join()是将数组中的所有元素放入一个字符串中,通俗点讲就是可以将数组转换成字符串 2 ...
- position三种属性的区别
1.static(静态定位):默认值.没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明). 2.relative(相对定位):生成相对 ...
- Oracle数据库表的一些宏处理
比如现在,有个数据库表,我想要知道这个数据库已经建了多少张表?每个表有多少条数据?每个表都有哪些字段?以及字段的说明? 下面就用SQL一一解决上面的问题: --所有已存在的表名和说明 select t ...
- win10下运行cmd闪退时检查方法
在cmd下运行 exe加空格加斜杠加问号
- vue跳坑笔记
序号 报错截图 关键词 解决办法 1 - code EPERM errno 4048 syscall scandir operation not permitted 清除npm缓存,命令: npm c ...
- 通过Mybatis原始Dao来实现curd操作
环境的配置见我上一篇博客. 首先,在上一篇博客中,我们知道,SqlSession中封装了对数据库的curd操作,通过sqlSessionFactory可以创建SqlSession,而SqlSessio ...
- c/c++ include 头文件的方式
在编写c/c++代码时,#include 头文件有两种方式:一个是#include “文件名”,一个是#include <文件名>.区别在于: 前者在程序编译时系统首先在源程序所在的目录( ...
- json&pickle模块
序列化:我们把对象(变量)从内存中变成可存储或传输的过程称之为序列化 反序列化:把变量内容从序列化的对象重新读到内存中,这一过程称为反序列化 为什么要序列化? 1.持久保存状态 一个软件的执行就是在处 ...
- ssm登录与退出
ssm整合比较好的实例 http://how2j.cn/k/ssm/ssm-tutorial/1137.html?tid=77#nowhere ssm登录后台用户检测(此实例注销有问题):http:/ ...