• Codeforces 670 C


    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 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.

    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 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.

    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
    Copy
    3
    2 3 2
    2
    3 2
    2 3
    output
    Copy
    2
    input
    Copy
    6
    6 3 1 1 3 7
    5
    1 2 3 4 5
    2 3 4 5 1
    output
    Copy
    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 twoscientists will be very pleased and all the others will be not satisfied.

    题意:n个人每个人会一种语言,每个电影有声频有字母,一个人如果能看听懂语言,他会非常开心。能看懂字母,他会比较开心。都不懂,很不开心,请你选择一部电影让这n个人去看,使非常开心的人最多(有多种电影满足则选择比较开心的人多)

    思路:语言nub到1e9次方,vis数组开不了那么大,所以离散化。最多涉及2*m+n种语言(注意没有满足的则随便选择一部)

    #include <iostream>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <map>
    #include <iomanip>
    #include <algorithm>
    #include <queue>
    #include <stack>
    #include <set>
    #include <vector>
    //const int maxn = 1e5+5;
    #define ll long long
    ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    
    #define MAX INT_MAX
    #define FOR(i,a,b) for( int i = a;i <= b;++i)
    #define bug cout<<"--------------"<<endl
    using namespace std;
    int a[210000],b[210000],c[210000];
    int cun[620000],vis[620000];
    int n,tot,m;
    void decin()
    {
        scanf("%d",&n);
        FOR(i,1,n){
            scanf("%d",&a[i]);
            cun[++tot] = a[i];
        }
        scanf("%d",&m);
        FOR(i,1,m){
            scanf("%d",&b[i]);
            cun[++tot] = b[i];
        }
        FOR(i,1,m){
            scanf("%d",&c[i]);
            cun[++tot] = c[i];
        }
        sort(cun+1, cun+1+tot);
         tot = unique(cun+1,cun+1+tot) - cun - 1;
    }
    int main()
    {
    
        decin();
        for(int i=1;i<=n;++i)
        {
            int temp = lower_bound(cun+1,cun+1+tot,a[i]) - cun;
            vis[temp]++;
        }
        int nowx = 0,nowy = 0,nownub = 0;
        for(int i=1;i<=m;++i)
        {
            int x = lower_bound(cun+1,cun+1+tot,b[i]) - cun;
            int y = lower_bound(cun+1,cun+1+tot,c[i]) - cun;
            if(vis[x] > nowx) nowx = vis[x],nowy = vis[y],nownub = i;
            else if(vis[x] == nowx && vis[y] > nowy) nowy = vis[y],nownub = i ;
        }
        if(nownub == 0) printf("1
    ");
        else printf("%d
    ",nownub);
    }
  • 相关阅读:
    DB2 java.lang.NoClassDefFoundError:com/ibm/db2/jcc/SQLJContext
    JavaScript字符串split方法
    使用 WebSphere Application Server Community
    为DB2数据库创建新用户帐户并为其分配特定特权
    Servlet3.0之一:Servlet3.0新特性介绍
    window下jni调用dll和linux下jni调用so库(转)
    分表分库之三:中间件介绍
    jboss5 启动时报HsqlException:length must be specified in type definition:VARBINARY错误
    J2EE Formbased Authentication
    阻塞队列之七:DelayQueue延时队列
  • 原文地址:https://www.cnblogs.com/jrfr/p/11403465.html
Copyright © 2020-2023  润新知