2015
07-16

Dressing

Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K different combinations of dressing.
One day he wears his pants Nike, shoes Adiwang to go to school happily. When he opens the door, his mom asks him to come back and switch the dressing. Mom thinks that pants-shoes pair is disharmonious because Adiwang is much better than Nike. After being asked to switch again and again Wangpeng figure out all the pairs mom thinks disharmonious. They can be only clothes-pants pairs or pants-shoes pairs.
Please calculate the number of different combinations of dressing under mom’s restriction.

There are multiple test cases.
For each case, the first line contains 3 integers N,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants and shoes.
Second line contains only one integer P(0≤P≤2000000) indicating the number of pairs which mom thinks disharmonious.
Next P lines each line will be one of the two forms“clothes x pants y” or “pants y shoes z”.
The first form indicates pair of x-th clothes and y-th pants is disharmonious(1≤x≤N,1 ≤y≤M), and second form indicates pair of y-th pants and z-th shoes is disharmonious(1≤y≤M,1≤z≤K).
Input ends with “0 0 0”.
It is guaranteed that all the pairs are different.

There are multiple test cases.
For each case, the first line contains 3 integers N,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants and shoes.
Second line contains only one integer P(0≤P≤2000000) indicating the number of pairs which mom thinks disharmonious.
Next P lines each line will be one of the two forms“clothes x pants y” or “pants y shoes z”.
The first form indicates pair of x-th clothes and y-th pants is disharmonious(1≤x≤N,1 ≤y≤M), and second form indicates pair of y-th pants and z-th shoes is disharmonious(1≤y≤M,1≤z≤K).
Input ends with “0 0 0”.
It is guaranteed that all the pairs are different.

2 2 2
0
2 2 2
1
clothes 1 pants 1
2 2 2
2
clothes 1 pants 1
pants 1 shoes 1
0 0 0

8
6
5

/*

水。。。(2012金华现场赛J题)。。。

2012-10-30
*/

#include"stdio.h"
#include"string.h"
int main()
{
int n1,n2,n3;
int ans;
int count1[1111],count2[1111];
int i,l;
int m;
char str1[111],str2[111];
int a,b;
while(scanf("%d%d%d",&n1,&n2,&n3),n1,n2,n3)
{
scanf("%d",&m);
memset(count1,0,sizeof(count1));
memset(count2,0,sizeof(count2));
while(m--)
{
scanf("%s%d%s%d",str1,&a,str2,&b);
if(strcmp(str1,"clothes")==0)   count1[b]++;
else                            count2[a]++;
}
ans=0;
for(i=1;i<=n2;i++)   ans+=(n1-count1[i])*(n3-count2[i]);
printf("%d\n",ans);
}
return 0;
}

1. 我始终坚持一个观点：从五毛的思想、品行、言辞、逻辑等等，都证明他们是一群病入膏肓的恶犬，我们应该同情并可怜它们。