codeforces 350 div2 C. Cinema map标记
2 seconds
256 megabytes
standard input
standard output
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
思路:标记教授的语言的人数;遍历一遍电影,找到最多人满意的电影,如果一样取更多能看懂字幕的电影;
注意一下,都看不懂的情况;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
map<int,int>m;
struct is
{
int a,v;
};
is a[];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
for(i=;i<=x;i++)
{
scanf("%d",&z);
m[z]++;
}
scanf("%d",&y);
for(i=;i<=y;i++)
scanf("%d",&a[i].a);
for(i=;i<=y;i++)
scanf("%d",&a[i].v);
int ans,ji=-,lu=-;
for(i=;i<=y;i++)
{
if(m[a[i].a]>ji)
{
ji=m[a[i].a];
lu=m[a[i].v];
ans=i;
}
else if(m[a[i].a]==ji&&m[a[i].v]>lu)
{
ji=m[a[i].a];
lu=m[a[i].v];
ans=i;
}
}
printf("%d\n",ans);
return ;
}
codeforces 350 div2 C. Cinema map标记的更多相关文章
- codeforces 350 div2 D Magic Powder - 2 二分
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Northwestern European Regional Contest 2016 NWERC ,F题Free Weights(优先队列+Map标记+模拟)
传送门: Vjudge:https://vjudge.net/problem/Gym-101170F CF: http://codeforces.com/gym/101170 The city of ...
- POJ 3320 尺取法,Hash,map标记
1.POJ 3320 2.链接:http://poj.org/problem?id=3320 3.总结:尺取法,Hash,map标记 看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- CodeForces -977F(突破定式思维+map应用)
题目链接: https://cn.vjudge.net/problem/CodeForces-977F /* 问题 输入n和n个数的数列 计算并输出最长增量为1的上升子序列 解题思路 用n2的最长上升 ...
随机推荐
- vertx 从Tcp服务端和客户端开始翻译
写TCP 服务器和客户端 vert.x能够使你很容易写出非阻塞的TCP客户端和服务器 创建一个TCP服务 最简单的创建TCP服务的方法是使用默认的配置:如下 NetServer server = ve ...
- Gson的两种解析用法
第一种. 常见的解析,直接将json字符串解析为对应的类. public JavaBean getJsonString(String jsonString) { Gson gson = new Gso ...
- 实习培训——Java基础(2)
实习培训——Java基础(2) 1 Java 变量类型 在Java语言中,所有的变量在使用前必须声明.声明变量的基本格式如下: type identifier [ = value][, identi ...
- jmeter 正则表达式提取器的使用(提取第一个匹配结果)
原文地址https://www.cnblogs.com/xueli/p/7405258.html?utm_source=itdadao&utm_medium=referral 正则表达式的用处 ...
- Chapter 7 Integrity(完整性), Views(视图), Security(安全性), and Catalogs(目录)
from Database Design to Physical Form CREATE TABLE integrity constraints (完整性约束) CREATE VIEW Securit ...
- CSS兼容IE Firefox问题与解决方法
一.双边距问题浮动元素的外边距会加倍,但与第一个浮动元素相邻的其他浮动元素外边距不会加倍.解决方法:在此浮动元素增加样式 display:inline; 二.图片产生的间隙父元素直接包含<im ...
- BootStrap同时显示多个Modal解决方案
使用BootStrap自带的Modal的时候,如果同时调用多个Modal,那么只能看到背景颜色加深但是看不见新的Modal页面. 问题主要是Modal的z-index有问题,重新计算z-index并赋 ...
- Java互联网架构-Mysql分库分表订单生成系统实战分析
概述 分库分表的必要性 首先我们来了解一下为什么要做分库分表.在我们的业务(web应用)中,关系型数据库本身比较容易成为系统性能瓶颈,单机存储容量.连接数.处理能力等都很有限,数据库本身的“有状态性” ...
- java tar.gz文件生成
/** * 压缩文件成Gzip格式,Linux上可使用 * 压缩文件夹生成后缀名为".gz"的文件并下载 * @param folderPath,要压缩的文件夹的路径 * @par ...
- MySQL从删库到跑路_高级(四)——存储过程
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.存储过程简介 1.存储过程简介 存储过程是一组具有特定功能的SQl语句集组成的可编程的函数,经编译创建并保存在数 ...