zoukankan      html  css  js  c++  java
  • HDU4451——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.
     

    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
     
    /*
    像容斥原理,总和减去分别再加上重复减去的
    */
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int MAX = 1005;
    int p1[MAX], p2[MAX];
    int main()
    {
        int n, m , k, p;
        int t1, t2;
        char s1[10], s2[10];
        while(~scanf("%d%d%d", &n, &m, &k)){
            memset(p1, 0, sizeof(p1));
            memset(p2, 0, sizeof(p2));
            if(n == 0 && m == 0 && k == 0) break;
            scanf("%d", &p);
            int sum = m * k * n;
            for(int i = 1; i <= p ; i++){
                scanf("%s%d%s%d", s1, &t1, s2, &t2);
                if(s1[0] == 'c'){
                     p1[t2] ++;
                    sum -= k;
                }
                else if(s1[0] == 'p' ){
                    p2[t1] ++; 
                    sum -= n;
                }
            }
            int sum1 = 0;
            for(int i = 1; i <= m; i++){
                  sum1 += p1[i] * p2[i];
            }
            sum += sum1;
            printf("%d
    ",sum);
        }
        return 0;
    }
    

      

  • 相关阅读:
    LeetCode Trapping Rain Water
    [Elasticsearch] 部分匹配 (四)
    SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)
    SICP 习题 (1.35)解题总结
    光流(optical flow)和openCV中实现
    LZMA C# SDK 结合 UPK 打包压缩 多目录 Unity3d实例
    tabhost实现android菜单切换
    12306火车票订票失败!您的身份信息未经核验,一般人是不能订票的,我订了,可是没成功。。。
    WebService学习之旅(四)Apache Axis2的安装
    WebService学习之旅(三)JAX-WS与Spring整合发布WebService
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4655770.html
Copyright © 2011-2022 走看看