Codefoeces round #697 div3 c Ball in Berland

main idea

The combination of boys and girls is now given the number of combinations and the content of the combination. If two teams are required to play at the same time (that is, the candidates for each play cannot be the same, such as (1,1) and (1,2) do not satisfy the question Meaning, unless student number 1 splits), find the number of all possible combinations.

Ideas

Since the total number of combinations is k, we can traverse the entire combination. For the i-th combination, the number of pairs that can be paired with other combinations is k-(the number of dances of the boy and girl in the i-th combination)-( The number of dances between the girl and the boy in the i-th combination) +1, (the number of dances of boys and girls needs to be counted separately by map, and map must be used). Add them to get ans, and finally output ans/2.

#include<bits/stdc++.h>
using namespace std;	
int numa,numb,k;
int a[200010],b[200010];
int maxx=0;

int main()
{
    
    
	int t;
	scanf("%d",&t);
	while(t--)
	{
    
    
		map<int ,int>man,women;
		scanf("%d%d%d",&numa,&numb,&k);
		for(int i=1;i<=k;i++)
		{
    
    
			a[i]=0;
			b[i]=0;
			man[i]=0;
			women[i]=0;
		}
		for(int i=1;i<=k;i++)
		{
    
    
			scanf("%d",&a[i]);
			man[a[i]]++;
		}
		for(int i=1;i<=k;i++)
		{
    
    
			scanf("%d",&b[i]);
			women[b[i]]++;
		}
		long long ans=0;
		for(int i=1;i<=k;i++)
		{
    
    
			ans+=k-man[a[i]]-women[b[i]]+1;
		}
		printf("%lld\n",ans/2);
	}
}

Guess you like

Origin blog.csdn.net/p15008340649/article/details/113250614