跳到正文

题解

题解 CF670C 【Cinema】

用户 82001约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
CF670C

版本

  1. v1当前

先用map统计每种语言有多少科学家会,然后遍历每场电影,找到愉悦人数最多前提下,满足人数最多的电影。

C++
#include <cstdio>
#include <map>
using namespace std;

int N,M,mova[200005],movs[200005];
map<int,int> lang;

int read()
{
	int r=0;
	char ch=getchar();
	while(ch<'0' || ch>'9')ch=getchar();
	while(ch>='0' && ch<='9')r=r*10+ch-'0',ch=getchar();
	return r;
}

int main()
{
	N=read();
	for(int i=1;i<=N;i++)lang[read()]+=1;
	M=read();
	for(int i=1;i<=M;i++)mova[i]=read();
	for(int i=1;i<=M;i++)movs[i]=read();

	//bestI-目前最佳电影(要初始化为1)
	//bestP-目前最多几人愉悦
	//bestS-目前最多几人满意
	int bestI=1,bestP=0,bestS=0;
	for(int i=1;i<=M;i++)
	{
		int a=lang[mova[i]],s=lang[movs[i]];
		if(a==bestP && s>bestS)bestI=i,bestS=s;
		else if(a>bestP)bestI=i,bestP=a,bestS=s;
	}
	printf("%d",bestI);
}
原文