AcWing 103. 电影(unordered_map)

题目链接:点击这里
在这里插入图片描述
在这里插入图片描述
1 a i , b i , c i 1 0 9 1≤a_i,b_i,c_i≤10^9 不能用数组hash,可以借助unorder_map实现O(1)映射

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>

using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 200010;

unordered_map<int,int> mmp; 

int a[maxn];

struct node {
	int bn, cn;
	int id;
}movie[maxn];

bool cmp(node x, node y)
{
	if(x.bn==y.bn)	return x.cn > y.cn;
	else	return x.bn > y.bn;
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		mmp[a[i]]++;
	}
		
	int m;
	scanf("%d", &m);
	
	for(int i = 1; i <= m; ++i)
	{
		int b;
		scanf("%d", &b);
		movie[i].bn = mmp[b];
		movie[i].id = i;
	}
		
	for(int i = 1; i <= m; ++i)
	{
		int c;
		scanf("%d", &c);
		movie[i].cn = mmp[c];
	}
	
	sort(movie+1, movie+1+n, cmp);
	
	printf("%d\n", movie[1].id);
	return 0;
}
发布了727 篇原创文章 · 获赞 111 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/qq_42815188/article/details/104274062