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

      

  • 相关阅读:
    数据库 concat 与 ||
    mysql时间戳详解及运用
    mysql数据库事务的操作与理解
    数据分析实战——03丨Python基础语法:开始你的Python之旅
    数据分析实战——02丨学习数据挖掘的最佳路径是什么?
    数据分析实战——01丨数据分析全景图及修炼指南
    数据分析实战——开篇词 | 你为什么需要数据分析能力?
    从0开始学大数据学习笔记——37.如何对数据进行分类和预测?
    坚毅(GRIT)阅读笔记
    Make over monday – 每周动手实践的Tableau社区网站
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4655770.html
Copyright © 2011-2022 走看看