首页 > ACM题库 > HDU-杭电 > HDU 4451-Dressing[解题报告]HOJ
2015
07-16

HDU 4451-Dressing[解题报告]HOJ

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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/ice_crazy/article/details/8127462