2020 CCPC Wannafly Winter Camp Day5 A

給定你每場比賽參加的賬號,判斷最少有多少個人在使用賬號。
一個人一場比賽只用一個賬號,一個賬號只可以屬於一個人。
則對每個賬號分情況:
1.三場全都參加
2.只參加了12/13/23
3.只參加了1/2/3
4.沒參加過
答案ans = 0
則沒參加過的直接忽略掉,三場全參加的肯定確定了一個人 ans+=全參加
之後,只參加12的可以和只參加3的匹配 ans += min(12,3)
同理 13與2,23與1匹配
匹配完後要減去匹配的數目 12 -= min(12,3) 3 -= min(12,3)
13,2,23,1同理
還要考慮到只參加1,只參加2,只參加3的三個可以匹配在一起 ans+=max(1,2,3)
剩下的就無法匹配了 ans+=12+23+13
k=1或2時簡單跳過

#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 50;
int m[4] = {0};
int a[4][maxn] = {0};
int map[3][maxn] = {0};
int main()
{
	int n, k;
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for(int i = 0; i < k; i++)
	{
		cin >> m[i];
		for(int j = 0; j < m[i]; j++)
		{
			cin >> a[i][j];
			map[i][a[i][j]] = 1;
		}
	}
	if(k == 1)
    {
        cout << m[0] << endl;
        return 0;
    }
    if(k == 2)
    {
    	int un = 0;
        for(int i = 0; i < m[1]; i++)
        {
        	if(map[1][a[1][i]] == 1)
        		un++;
		}
        int ans = un + max(m[1] - un, m[0] - un);
        cout << ans << endl;
        return 0;
    }
	int quan = 0;
	int cnt12 = 0, cnt13 = 0, cnt23 = 0;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(int j = 1; j <= n; j++)
	{
		if(map[0][j] && map[1][j] && map[2][j]) quan++;
		if(map[0][j] && map[1][j] && !map[2][j]) cnt12++;
		if(map[0][j] && !map[1][j] && map[2][j]) cnt13++;
		if(!map[0][j] && map[1][j] && map[2][j]) cnt23++;
		if(map[0][j] && !map[1][j] && !map[2][j]) cnt1++;
		if(!map[0][j] && map[1][j] && !map[2][j]) cnt2++;
		if(!map[0][j] && !map[1][j] && map[2][j]) cnt3++;
	}
	int ans = 0;
	ans += quan;
	if(cnt12 >= cnt3)
	{
		ans += cnt3;
		cnt12 -= cnt3;
		cnt3 = 0;
	}
	else
	{
		ans += cnt12;
		cnt3 -= cnt12;
		cnt12 = 0;
		
	}
	
	if(cnt13 >= cnt2)
	{
		ans += cnt2;
		cnt13 -= cnt2;
		cnt2 = 0;
	}
	else
	{
		ans += cnt13;
		cnt2 -= cnt13;
		cnt13 = 0;
		
	}
	
	if(cnt23 >= cnt1)
	{
		ans += cnt1;
		cnt23 -= cnt1;
		cnt1 = 0;
	}
	else
	{
		ans += cnt23;
		cnt1 -= cnt23;
		cnt23 = 0;
		
	}
	ans += cnt12 + cnt23 + cnt13 + max(max(cnt1, cnt2), cnt3);
	cout << ans << endl;
	return 0;
}
發佈了11 篇原創文章 · 獲贊 0 · 訪問量 1738
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章