HDU-4451-Dressing (2012年金华赛区J题)

Dressing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2674    Accepted Submission(s): 1179

Problem 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

Source

2012 Asia JinHua Regional Contest

今天上午陪队友一起做的题目之一,我之前没看这题,后来才看的;

思路:先记录好不和谐的衣服和裤子与裤子和鞋子,再枚举衣服和裤子,如果衣服和裤子可以搭配就看鞋子,然后累加可以搭配的就ok了

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;

int a[1010][1010], b[1010][1010], c[1010];

int main()
{
	int N, M, K, P;
	char str1[10], str2[10];
	int t1, t2;
	while(scanf("%d %d %d", &N, &M, &K)==3, N || M || K)
	{
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		memset(c, 0, sizeof(c));
		scanf("%d", &P);
		while(P--)
        {
            scanf("%s %d %s %d", &str1, &t1, &str2, &t2);
            if(strcmp(str1,"clothes")==0)
            {
                a[t1][t2]=1;
            }
            else
            {
                b[t1][t2]=1;
                c[t1]++;
            }
        }
        int ans=0;
        for(int i=1;i<=N;i++)
          for(int j=1;j<=M;j++)
            if(a[i][j]==0)
              ans+=(K-c[j]);
        printf("%d\n",ans);
	}
	return 0;
} 
时间: 2024-11-19 20:17:53

HDU-4451-Dressing (2012年金华赛区J题)的相关文章

hdu 4451 37届金华赛区 J题

题意:给出衣服裤子鞋子的数目,有一些衣服和裤子,裤子和鞋子不能搭配,求最终的搭配方案总数 wa点很多,我写wa了很多次,代码能力需要进一步提升 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using

HDU-4450-Draw Something (2012年金华赛区I题)

Draw Something Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2591    Accepted Submission(s): 2179 Problem Description Wangpeng is good at drawing. Now he wants to say numbers like "521"

HDU - 4813 Hard Code (长春赛区水题)

Description Some strange code is sent to Da Shan High School. It's said to be the prophet's note. The note is extremely hard to understand. However, Professor Meng is so smart that he successfully found the pattern of the code. That is, the length of

[hdu5136]Yue Fei&#39;s Battle 2014 亚洲区域赛广州赛区J题(dp)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 现场赛的时候由于有个地方有点小问题,没有成功AC,导致与金牌失之交臂. 由于今天下午有点事情,无法打重现,所以下午只是花了十分钟做了一道J题,抢了个FB,2333333333 Yue Fei's Battle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)T

浙江2012年省赛J题 Modular Inverse

Modular Inverse Time Limit: 2000MS   Memory Limit: 65535KB   64bit IO Format: Submit Status Description The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x (mod m). This is equivalent to ax≡1 (mod m). I

hdu 4451 Dressing 衣服裤子鞋 简单容斥

Dressing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3735    Accepted Submission(s): 1681 Problem Description Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K

HDU-4442-Physical Examination (2012年金华赛区现场赛A题)

Physical Examination Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5915    Accepted Submission(s): 1656 Problem Description WANGPENG is a freshman. He is requested to have a physical examinat

HDU 4451 Dressing

先从衣服处理到裤子,在从裤子处理到鞋子 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <cmath> #include <map> #include <stri

【HDU 4451 Dressing】水题,组合数

有衣服.裤子.鞋数量分别为n,m,k,给出p对不和谐的衣-裤或裤-鞋搭配,问一共有多少种和谐的衣裤鞋的搭配. 全部的组合有Cn1Cm1Ck1种. 设p对中有p1对衣-裤,p2对裤-鞋,则不和谐的搭配共有p1*Ck1+p2*Cn1种,但有被重复计算两次的搭配共p3对,它们引用了同一裤.设裤 i 在p1被引用 li 次,在p2被引用 ri 次,则p3=∑(1*Cli1Cri1).所以答案为n*m*k-p1*k-p2*n+p3 1 #include <cstdio> 2 #include <c