zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    南京的第一场雪 沧海
    再一则笑话家里闹鬼了 沧海
    简单需求描述(自己备用) 沧海
    为什么IIS无法启动,以前是可以了.而且WWW服务也启动不了提示:错误127,找不到指定程序. 沧海
    生活中有着太多的感动 沧海
    Enhancements 沧海
    ABAP SysteTransactions, Tables and Programs 沧海
    SAP ABAP OK Code Values 沧海
    Conversion of SAPSCRIPT to SMARTFORMS 沧海
    别人的面试记实转摘 沧海
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3375226.html
Copyright © 2011-2022 走看看