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 ...
随机推荐
- .net core webapi 使用ValidationAttribute对比同一对象的多个参数
众所周知,在使用DataAnnotations数据验证的时候,特别是针对同一个InputDto的多个属性进行对比的时候,例如起始日期不能大于结束日期,我们需要在Attribute中知道当前InputD ...
- centos7初上手3-安装apache服务
前两篇学习安装了mysql服务器,tomcat服务,这篇文章学习安装apache服务 1.执行yum install httpd,安装完成后查看httpd rpm -qa|grep httpd 2.新 ...
- [git]入门-创建版本库
转载整理自:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743256 ...
- mysql建表时
问题:Incorrect column specifier for column 'id' 答案:原来自动增长列用int数据类型,不用varchar
- Django中Model-Form验证
Django中Model-Form验证 class UserType(models.Model): caption=models.CharField(max_length=32) class User ...
- xss处理
今天学习了xss,主要记载如下: https://blog.csdn.net/sdauzyh/article/details/74942737
- C#获取常用的路径
常用的这两个足够了,其他需要的自行百度 //获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名). string str = System.Diagnost ...
- 将 Range 对象赋给变量
有多种方法将现有的 Range 对象赋给变量.本主题对两种不同的方法进行了阐述.在下列示例中,将 Range 对象赋给变量 Range1 和 Range2.例如,下列指令将活动文档中的第一个和第二个单 ...
- Java中String类型的数据比较
在Java中如果想比较两个字符串是否相等,可以使用string1==string2 或string1.equal(string2)来比较. 但是,第一种方法过于局限.例如, String string ...
- MYSQL ini 配置文件详解及性能优化方案
my.ini分为两块:Client Section和Server Section. Client Section用来配置MySQL客户端参数. 要查看配置参数可以用下面的命令: show va ...