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

      

  • 相关阅读:
    python中的一些小知识
    软件工程第一次作业(2)
    CountDownLatch的理解和使用
    架构设计:系统间通信(1)概述从“聊天”开始上篇
    Asp默认的上传文件大小限制是200K
    当多个sqlserver服务存在时,需要完全限定的serverName 方可登陆
    关于Entity Framework 版本的疑惑
    mvc scaffolding
    sql 语句中的 NULL值
    如何从数据库生成 EF Code First model
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4655770.html
Copyright © 2011-2022 走看看