HDU 4451 Dressing

HDU 4451 Dressing

题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4451

Description

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.

Input

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.

Output

For each case, output the answer in one line.

Sample Input

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

Sample Output

8
6
5

题意:

给你n件衣服,m条裤子,k双鞋子。然后给你p个冲突。求有多少种搭配方式。

题解:

先是对于每条裤子统计能搭配的鞋子数量,然后暴力扫一遍衣服和裤子的搭配,累加起来即可。

代码:

#include <bits/stdc++.h>
using namespace std;
int n,m,k,p;
const int maxn = 1100;
int C[maxn],P[maxn],S[maxn];
bool rec[maxn][maxn];
int main()
{
    while (scanf("%d %d %d",&n,&m,&k)){
        if (n == 0 && m == 0 && k == 0)
            break;    
        memset(rec,0,sizeof rec);
        for (int i = 1; i <= m; i++)
            P[i] = k;
        scanf("%d",&p);
        char in1[10],in2[10];
        int x1,x2;
        while (p--){
            scanf("%s %d %s %d",in1,&x1,in2,&x2);
            if (in1[0] == 'c'){
                rec[x1][x2] = true;
            }else {
                P[x1]--;
            }
        }
        long long ans = 0;
        for (int i = 1; i <= n;i++){
            for (int j = 1; j <= m; j++){
                if (rec[i][j])
                    continue;
                ans += P[j]; 
            }    
        }
        printf("%lld\n",ans);
    }
}
posted @ 2016-08-20 12:51  Thecoollight  阅读(180)  评论(0编辑  收藏  举报