Codeforces Round #350 (Div. 2)(C)模拟
2016-05-06 15:29
435 查看
C. Cinema
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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 from1 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.
Input
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 thei-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.
Output
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.
Examples
input
output
input
output
Note
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 two scientists will be very pleased and all the others will be not satisfied.
题意:有n个科学家看电影,每个人懂一种语言,电影声音是一种语言,字幕是另一种语言,如果科学家听得懂,那么就很开心,如果懂字幕就基本满意,都不懂就很难过,问现在在m个电影中选择一个电影使得开心的人数最多,在开心的人多的情况下使得满意的人满意
题解:由于数字编号很大,使用map计数,然后一个for找出最多的人数就好了
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
using namespace std;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef long long LL;
enum{ N = int(2e5 + 10) };
int a
, b
, c
;
map<int, int>qq;
int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt", "w", stdout);
int _time_jc = clock();
#endif
int n, m;
while (~scanf("%d", &n))
{
qq.clear();
for (int i = 0; i < n; i++)
{
scanf("%d", a + i);
qq[a[i]]++;
}
scanf("%d", &m);
int sud = -1, lag = -1, ans = -1;
for (int i = 0; i < m; i++)scanf("%d", b + i);
for (int i = 0; i < m; i++)scanf("%d", c + i);
for (int i = 0; i < m; i++)
{
if (sud < qq[b[i]] || sud <= qq[b[i]] && lag<qq[c[i]])
{
sud = qq[b[i]];
lag = qq[c[i]];
ans = i + 1;
}
}
printf("%d\n", ans);
}
return 0;
}
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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 from1 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.
Input
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 thei-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.
Output
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.
Examples
input
3 2 3 2 2 3 2 2 3
output
2
input
6 6 3 1 1 3 7 5 1 2 3 4 5 2 3 4 5 1
output
1
Note
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 two scientists will be very pleased and all the others will be not satisfied.
题意:有n个科学家看电影,每个人懂一种语言,电影声音是一种语言,字幕是另一种语言,如果科学家听得懂,那么就很开心,如果懂字幕就基本满意,都不懂就很难过,问现在在m个电影中选择一个电影使得开心的人数最多,在开心的人多的情况下使得满意的人满意
题解:由于数字编号很大,使用map计数,然后一个for找出最多的人数就好了
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
using namespace std;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef long long LL;
enum{ N = int(2e5 + 10) };
int a
, b
, c
;
map<int, int>qq;
int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt", "w", stdout);
int _time_jc = clock();
#endif
int n, m;
while (~scanf("%d", &n))
{
qq.clear();
for (int i = 0; i < n; i++)
{
scanf("%d", a + i);
qq[a[i]]++;
}
scanf("%d", &m);
int sud = -1, lag = -1, ans = -1;
for (int i = 0; i < m; i++)scanf("%d", b + i);
for (int i = 0; i < m; i++)scanf("%d", c + i);
for (int i = 0; i < m; i++)
{
if (sud < qq[b[i]] || sud <= qq[b[i]] && lag<qq[c[i]])
{
sud = qq[b[i]];
lag = qq[c[i]];
ans = i + 1;
}
}
printf("%d\n", ans);
}
return 0;
}
相关文章推荐
- iOS - 百度推送
- BaseAdapter
- aiohttp
- 不惑JAVA之JAVA基础 - String
- OpenWrt添加内核模块软件包(二)
- Hive
- Zookeeper 学习
- metaq实例
- spring boot 部署 发布
- jquery-uploadify传参方法
- 一致性哈希算法设计
- 数据库设计
- 【SSH】AOP
- simpledrawview加载大图问题
- spring整合xfire出现Document root element "beans", must match DOCTYPE root "null"错误解决方案
- 奋斗吧,程序员——第三十章 多情自古伤离别,更哪堪冷落清秋节
- uva548Tree
- Android事件处理机制
- 在线编程--约瑟夫问题I
- 如何通过Maven的Jetty插件运行Web工程