【CCPC】2022威海站 A. Dunai | Map、签到

287 阅读2分钟

本文已参与「新人创作礼」活动, 一起开启掘金创作之路。

【CCPC】2022威海站 A. Dunai | Map、签到

题目链接

Problem - A - Codeforces

题目

Lope the Bear often watches game events. He has a special skill: Dunai, also known as poisoned milk. Every time he predicts the outcome of a game by wishing the team that he believes will win good luck, the outcome often turns out to be the opposite. Recently, a tournament called Daota 2 The International is about to start. It's time for Lope to show his Dunai skill again.

In the game Daota 2, each team has five players corresponding to five positions, numbered from 1 to 5. Daota 2 The International has been held for n editions. To better Dunai, Lope looks up the champion team of each edition, including the names and positions of the five players. In addition, he inquires about the m players involved in the upcoming tournament including their names and positions, without knowing exactly how the teams will be formed. What is known is that for every player who has won a championship, his position in the team never changes.

Lope wants to predict how these mm players will be teamed up in a way that satisfies the following conditions:

  • Each player is assigned to at most one team (possibly not assigned).
  • The team consists of five different positions, with exactly one player for each position.
  • Each team includes at least one player who has won a championship.

Lope wants to know the maximum number of teams that can be formed.

题目大意

每个队伍由 5 个不同位置人组成。

nn 个队伍曾经取得过冠军,分别给出了他们的名字。有 mm 个选手想参加本次比赛,分别给出他们的名字和位置,选手的位置不能改变,没有两个人重名(即如果一个名字在“有 nn 个队伍曾经取得过冠军”中出现且在“参加本次”中出现,是同一个人)。

输出想参加本次比赛的人最多可以组出多少个队伍满足以下条件:

  • 每个队伍由五个人组成,他们的位置互不相同。
  • 一个人只能加入一个队伍。
  • 每个队伍必须有人曾取得过冠军。

思路

首先分别统计本届选手中每个位置的人数,则每个位置的人数即我们只考虑前两条限制能组出的队伍数。

再统计有多少个曾取得过冠军的人参加了本次比赛,这个可以开个 map 给取得过冠军的人打上标记,再对本届选手统计标记数量。

我们肯定会尽量把冠军分配到每个队伍之中,所以答案显然是上面两个部分的答案取最小值。

代码

#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
using namespace std;
using LL=long long;
const int N=500001;
const LL mod=1000000007;
int n,m,k,x,y,z,tot,a[N],b[N];
string name;
map<string,int> win;
LL solve()
{
	scanf("%d",&n);
	for (int i=1;i<=n*5;++i)
	{
		cin>>name;
		win[name]=1;
	}
	scanf("%d",&m);
	int wcnt=0,cnt[6]={0};
	for (int i=1;i<=m;++i)
	{
		cin>>name>>x;
		if (win[name]) wcnt++;
		cnt[x]++;
	}
	int ans=wcnt;
	for (int i=1;i<=5;++i)
		ans=min(cnt[i],ans);
	return ans;
}
int main()
{
	int T=1;
	while (T--) printf("%lld\n",solve());

	return 0;
}