• AcWing103 电影 (排序 + 离散化)


    题目链接:https://www.acwing.com/problem/content/105/

    首先对所有涉及到的语言离散化一下,统计会每种语言的人的个数
    然后扫一遍电影,找到知道电影语言最多的人的那个电影

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    using namespace std;
    const int maxn = 600010;
    typedef long long ll;
    
    int n, m, cnt, q;
    int L[maxn], a[maxn], b[maxn], c[maxn], lan[maxn], con[maxn], id[maxn];
    
    ll read(){ ll s = 0, f = 1ll; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1ll; ch = getchar(); } while(ch >= '0' && ch <= '9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }
    
    int main(){
    	n = read();
    	for(int i=1;i<=n;++i) a[i] = read(), L[++cnt] = a[i];
    	m = read();
    	for(int i=1;i<=m;++i) b[i] = read(), L[++cnt] = b[i]; 
    	for(int i=1;i<=m;++i) c[i] = read(), L[++cnt] = c[i]; 
    	
    	sort(L+1,L+1+cnt);
    	
    	for(int i=1;i<=cnt;++i){
    		if(i == 1 || L[i] != L[i-1]){
    			lan[++q] = L[i];
    		}
    	}
    	
    	for(int i=1;i<=m;++i){
    		int pos = lower_bound(lan + 1,lan + 1 + q, b[i]) - lan; 
    		id[pos] = i;
    	}
    	
    	for(int i=1;i<=n;++i){
    		int pos = lower_bound(lan + 1, lan + 1 + q, a[i]) - lan;
    		++con[pos];
    	} 
    	
    	int ans = 0, mxb = 0, mxc = 0;	
    
    	for(int i=1;i<=m;++i){
    		int posb = lower_bound(lan + 1, lan + 1 + q, b[i]) - lan;
    		int posc = lower_bound(lan + 1, lan + 1 + q, c[i]) - lan;
    		if(mxb < con[posb]){
    			ans = i;
    			mxb = con[posb];
    			mxc = con[posc];
    		}else if(mxb == con[posb]){
    			if(mxc < con[posc]){
    				ans = i;
    				mxc = con[posc];
    			}
    		}
    	} 
    	printf("%d
    ",ans);
    	
    	return 0;
    }
    
  • 相关阅读:
    磁盘调度算法
    Maven 的 学习笔记
    文档结构
    变量
    进入SQL*Plus环境 (常用命令)
    PAT甲级 1050 String Subtraction (20分)(当读一行时(gets用不了))
    PAT甲级 1095 Cars on Campus (30分)(map + 排序)
    图书管理系统
    学生成绩管理系统
    磁盘调度算法
  • 原文地址:https://www.cnblogs.com/tuchen/p/13919383.html
Copyright © 2020-2023  润新知