CodeForces_670C Cinema ( 模拟 )

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_44510468/article/details/102711700

文章目录

题目连接 vj or cf

题意

n 个科学家每个科学家对应一门语言,
m 个电影, 从角标 1 开始到m,
接下来的第一行是对应角标电影的 主字幕语言, 第二行是对应角标的 副字幕语言,
如果主字幕出现科学家的语言, 他会非常满意; 如果副字幕出现, 他会几乎满意; 如果不出现, 会不满意.
输出达到最大满意人数的电影编号

题解

画下图, 很清晰的思路
统计最大满意人数, 再在最大满意人数中统计几乎满意人数, 维护最大人数的同时记录电影编号
在这里插入图片描述

代码

#include <bits/stdc++.h> 
using namespace std; 
#define rg register 
#define sc scanf 
#define pf printf 
typedef long long ll; 

const int RANGE = 2e5+10;

int n;
	map<int,int> tot;
int	m,
	a[RANGE], b[RANGE],
	tmp;

int main ( ) {  // freopen( "F:\\in\\.txt" , "r" , stdin ); 

	sc( "%d", &n );
	for ( int i = 0; i < n; ++i ) {
		sc( "%d", &tmp );
		tot[tmp]++;
	}

	sc( "%d", &m );

	int maxTot = -0x3f3f3f3f,
		maxMovie = 1;
	for ( int i = 0; i < m; ++i ) {
		sc( "%d", &a[i] );
		if ( tot[a[i]] > maxTot ) {
			maxTot = tot[a[i]];
			maxMovie = i+1;
		}
	}

	int _maxTot = -0x3f3f3f3f;
	for ( int i = 0; i < m; ++i ) {
		sc( "%d", &b[i] ); // 其实这里是没有必要存的, 也懒得来改了
        if ( tot[a[i]]==maxTot ) {
            if ( tot[b[i]]>_maxTot ) {
                _maxTot = tot[b[i]];
                maxMovie = i+1;
            }
        }
	}

	pf( "%d\n", maxMovie );

	return 0 ; 
} 

猜你喜欢

转载自blog.csdn.net/weixin_44510468/article/details/102711700
今日推荐