AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

AcWing 103. 电影(离散化)    原题链接    简单

作者: 作者的头像   pqp ,  2025-06-06 22:21:41 · 天津 ,  所有人可见 ,  阅读 2


0


import java.util.*;

public class Main
{
    static final int N = 200010;
    static ArrayList<Integer> t = new ArrayList<>();
    static Set<Integer> set = new HashSet<>();
    static int[] ans = new int[3 * N];
    static int[] a = new int[N];
    static int[] b = new int[N];
    static int[] c = new int[N];


    static int n,m;

    static int find(int x)
    {
        int l = 0, r = t.size() - 1;
        while(l < r)
        {
            int mid = (l + r) >> 1;
            if(t.get(mid) >= x) r = mid;
            else l = mid + 1;
        }
        return l;
    }

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();

        for(int i = 0; i < n; i++)
        {
            a[i] = sc.nextInt();
            set.add(a[i]);
        }

        m = sc.nextInt();

        for(int i = 1; i <= m; i++)
        {
            b[i] = sc.nextInt();
            set.add(b[i]);
        }
        for(int i = 1; i <= m; i++)
        {
            c[i] = sc.nextInt();
            set.add(c[i]);
        }

        //去重+排序
        for(int x : set) t.add(x);
        Collections.sort(t);

        //get ans[],,,,在a[] 里面的数据会作用于ans,不在默认为0
        for(int i = 0; i < n; i++)
        {
            int index = find(a[i]);
            ans[index]++;
        }

        //-----------------------------------------------------
        // for(int i = 0; i < t.size(); i++)
        // {
        //     System.out.println(t.get(i) + " " + ans[i]);
        // }
        //-----------------------------------------------------

        int max_b = -1;
        for(int i = 1; i <= m; i++)
        {
            max_b = Math.max(ans[find(b[i])], max_b);
        }


        int num_b = 0;
        int index_b = 0;
        ArrayList<int[]> c_i = new ArrayList<>();
        for(int i = 1; i <= m; i++)
        {
            if(ans[find(b[i])] == max_b)
            {
                num_b++;
                index_b = i;
                c_i.add(new int[]{ans[find(c[i])], i});
            }
        }

        Collections.sort(c_i, (o1,o2) -> Integer.compare(o2[0], o1[0]));

        int index_c = c_i.get(0)[1];
        System.out.println( num_b == 1 ? index_b : index_c);
    }
}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息