zoukankan      html  css  js  c++  java
  • HDU 4451 Dressing

    Dressing

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 4451
    64-bit integer IO format: %I64d      Java class name: Main
     
    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

     
    解题:由于只有三种,衣服,裤子,鞋子,两层循环枚举即可。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 const int maxn = 1010;
    18 bool a[maxn][maxn],b[maxn][maxn];
    19 int c[maxn];
    20 int main() {
    21     int n,m,k,t,u,v,ans;
    22     char sa[10],sb[10];
    23     while(scanf("%d %d %d",&n,&m,&k),n||m||k){
    24         memset(a,false,sizeof(a));
    25         memset(b,false,sizeof(b));
    26         memset(c,0,sizeof(c));
    27         scanf("%d",&t);
    28         for(int i = ans = 0; i < t; i++){
    29             scanf("%s %d %s %d",sa,&u,sb,&v);
    30             if(sa[0] == 'c') a[u][v] = true;
    31             else{b[u][v] = true;c[u]++;}
    32         }
    33         for(int i = 1; i <= n; i++){
    34             for(int j = 1; j <= m; j++)
    35                 if(!a[i][j]) ans += k-c[j];
    36         }
    37         printf("%d
    ",ans);
    38     }
    39     return 0;
    40 }
    View Code
  • 相关阅读:
    array_unshift() 、
    readfile() 函数
    Java的异常处理
    Java 接口
    Java 抽象类
    final关键字
    statice关键字
    dom查询
    JS 正则表达式
    JS对象
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3963213.html
Copyright © 2011-2022 走看看