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 ...
随机推荐
- git add.后回退 代码丢失
记录一次操作git丢失代码的过程: 写完代码后:git staus git add. git status 发现有一堆.class 文件不想提交,想着代码回退到add 之前,使用了 git log 开 ...
- qr-mili Tekniskt stöd
qr-mili Är ett QR-kodverktyg Identifiera enkelt QR-koder Generera QR-kod Skapa en QR-kod med logotyp ...
- layui从子iframe打开父iframe的tab选项卡
数据表格字段: {field: 'novelId', title: '小说ID',width:100,templet: '<div><a href="javascript: ...
- SecureCRT标签显示标题
- 开发工具IntelliJ IDEA的安装与操作
开发工具IntelliJ IDEA的安装与操作 1.1 开发工具概述 IDEA是一个专门针对Java的集成开发工具(IDE),它可以极大地提升我们的开发效率.可以自动编译,检查错误.在公司中,使用的就 ...
- Mysql 存储过程查询结果赋值到变量的方法
drop table if exists test_tbl; create table test_tbl (name varchar(20), status int(2)); insert into ...
- PAT A1059
PAT A1059 标签(空格分隔): PAT 解题思路 :先打印出素数表.利用结构体数组来存贮质因子的值和个数 strcut factor{ int x; //值 int cnt; //个数 }fa ...
- FINS/TCP_OMRON(1)
使用FINS/ TCP与欧姆龙PLC沟通 可参考下列教学 using System.Net; using System.Net.Sockets; 上面必须使用; IPAddress ipAddr = ...
- Django中Model-Form验证
Django中Model-Form验证 class UserType(models.Model): caption=models.CharField(max_length=32) class User ...
- 小程序wx.chooseImage的坑
选择图片后可能重新执行onshow()和onhide(),可以在页面中添加锁变量,选择图片前获取,选择完释放,onshow中利用锁来中断执行