hdu4451

题目给出 上衣,裤子,鞋子的各种类数,然后给出了不能匹配的关系,求解能匹配的种数。

一开始没有看见题目中明确说明只会有clothes pants 和 pants shoes 这两种情况,所以yy各种容斥,后来扫了一眼,了解了水题的本质。

只需要以pants为中心,开两个数组标记各种裤子中不能与之匹配的clothes和shoes种数,然后用总的减去就可以了。

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn=1200;
int clothes[maxn];
int shoes[maxn];
int N,M,K;

int main()
{
while(~scanf("%d%d%d",&N,&M,&K))
{
	if(N==0&&M==0&&K==0)
	break;
	int num;
	scanf("%d",&num);
	char inc1[10];
	char inc2[10];
	memset(clothes,0,sizeof(clothes));
	memset(shoes,0,sizeof(shoes));
	for(int i=1;i<=num;i++)
	{
	//clothes x pants y 
	//pants y shoes z
		int a,b;
		scanf("%s",inc1);
		scanf("%d",&a);
		scanf("%s",inc2);
		scanf("%d",&b);
		if(inc1[0]=='c')
		{
		clothes[b]++;
		}
		if(inc1[0]=='p')
		{
		shoes[a]++;
		}
	}
	int tmp=0;
	for(int i=1;i<=M;i++)
	{
		tmp+=(N-clothes[i])*(K-shoes[i]);
	}
	
	cout<<tmp<<endl;
}


return 0;
}



版权声明:本文为xinge008原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。