• Dressing HDU 4451简单数学题


    Dressing

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1925    Accepted Submission(s): 831


    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
     
    Recommend
    zhuyuanchen520
    /*
     * Author:  
     * Created Time:  2013/10/17 22:03:17
     * File Name: F.cpp
     * solve: F.cpp
     */
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<stack>
    #include<set>
    #include<iostream>
    #include<vector>
    #include<queue>
    //ios_base::sync_with_stdio(false);
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    #define sz(v) ((int)(v).size())
    #define rep(i, a, b) for (int i = (a); i < (b); ++i)
    #define repf(i, a, b) for (int i = (a); i <= (b); ++i)
    #define repd(i, a, b) for (int i = (a); i >= (b); --i)
    #define clr(x) memset(x,0,sizeof(x))
    #define clrs( x , y ) memset(x,y,sizeof(x))
    #define out(x) printf(#x" %d
    ", x)
    #define sqr(x) ((x) * (x))
    typedef long long LL;
    
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 2000;
    
    int sgn(const double &x) {  return (x > eps) - (x < -eps); }
    
    char cmd[maxn];
    int NOT[maxn][maxn];
    int num[maxn];
    int main() 
    {
        //freopen("in.txt","r",stdin);
        int n,m,k;
        while(scanf("%d%d%d",&n,&m,&k) == 3)
        {
            if(n+m+k == 0)
                break;
            int ans = n*m*k;
            int T;
            cin>>T;
            clr(NOT);
            clr(num);
            repf(i,1,T)
            {
                int a,b;
                scanf("%s",cmd);
                scanf("%d",&a);
                scanf("%s",cmd);
                scanf("%d",&b);
                if(cmd[0] == 'p')
                {
                    ans -= k;
                    NOT[a][b] = 1;
                }else
                {
                    ans -= n;
                    num[a]++;
                }
            }
    
            repf(i,1,n)
                repf(j,1,m)
                    if(NOT[i][j])
                        ans += num[j];
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    大厂Redis高并发场景设计,面试问的都在这!
    POJ1006——中国剩余定理
    HDU3501——欧拉函数裸题
    堆-动态的排序(洛谷1801-黑匣子)
    图中欧拉回路数量
    ip地址
    网络通信概述
    网络通信概述
    软件安装与卸载
    软件安装与卸载
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3375226.html
Copyright © 2020-2023  润新知