HDU 4451 Dressing

先从衣服处理到裤子,在从裤子处理到鞋子

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <string>
using namespace std;

const int maxn=1000+10;
long long A[maxn][maxn];
long long B[maxn][maxn];
long long ans1[maxn],ans2[maxn];
char s1[1000],s2[1000];
int x,y;
int n,m,k,p;

int main()
{
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        if(!n&&!m&&!k) break;
        scanf("%d",&p);

        memset(ans1,0,sizeof ans1);
        memset(ans2,0,sizeof ans2);

        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++) A[i][j]=0;

        for(int i=1;i<=m;i++)
            for(int j=1;j<=k;j++) B[i][j]=0;

        for(int i=1; i<=p; i++)
        {
            scanf("%s",s1); scanf("%d",&x);

            scanf("%s",s2); scanf("%d",&y);

            if(strcmp("clothes",s1)==0) A[x][y]=1;

            else if(strcmp("pants",s1)==0) B[x][y]=1;

        }

        for(int j=1; j<=m; j++)
        {
            long long sum=0;
            for(int i=1; i<=n; i++)
            {
                if(A[i][j]==0)
                    sum=sum+1;
            }
            ans1[j]=sum;
        }

        for(int j=1; j<=k; j++)
        {
            long long sum=0;
            for(int i=1; i<=m; i++)
            {
                if(B[i][j]==0)
                {
                    sum=sum+ans1[i];
                }
            }
            ans2[j]=sum;
        }
        long long ans=0;
        for(int i=1; i<=k; i++) ans=ans+ans2[i];
        printf("%lld\n",ans);
    }
    return 0;
}
时间: 2025-01-02 13:56:20

HDU 4451 Dressing的相关文章

hdu 4451 Dressing 衣服裤子鞋 简单容斥

Dressing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3735    Accepted Submission(s): 1681 Problem Description Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K

【HDU 4451 Dressing】水题,组合数

有衣服.裤子.鞋数量分别为n,m,k,给出p对不和谐的衣-裤或裤-鞋搭配,问一共有多少种和谐的衣裤鞋的搭配. 全部的组合有Cn1Cm1Ck1种. 设p对中有p1对衣-裤,p2对裤-鞋,则不和谐的搭配共有p1*Ck1+p2*Cn1种,但有被重复计算两次的搭配共p3对,它们引用了同一裤.设裤 i 在p1被引用 li 次,在p2被引用 ri 次,则p3=∑(1*Cli1Cri1).所以答案为n*m*k-p1*k-p2*n+p3 1 #include <cstdio> 2 #include <c

HDOJ 4451 Dressing

Dressing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2484    Accepted Submission(s): 1076 Problem Description Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K

hdu 4451 37届金华赛区 J题

题意:给出衣服裤子鞋子的数目,有一些衣服和裤子,裤子和鞋子不能搭配,求最终的搭配方案总数 wa点很多,我写wa了很多次,代码能力需要进一步提升 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using

HDU 4451 容斥原理

题目大意: n件衣服,m条裤子,k双鞋子进行搭配 妈妈指明了哪些衣服和裤子不能搭配,哪些裤子和鞋子不能搭配,问最后有几种搭配方法 先假设都能搭配 n*m*k 每次遇到衣服和裤子不能搭的,就要减一次k,同时记录这个衣服和裤子出现的次数,避免以后重复减去的可以加回来 裤子和鞋子也是同样道理 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const

HDU 4451 水

题目给出 上衣,裤子,鞋子的各种类数,然后给出了不能匹配的关系,求解能匹配的种数. 因为只给出cp组合和ps组合,所有对于每个p,开两个数组标记不能与之匹配的c和s #include "stdio.h" #include "string.h" int main() { __int64 ans,x,y,n,m,k; int p,i,p1[1010],p2[1010]; char ch1[11],ch2[11]; while (scanf("%I64d%I64

HDU 4046 Panda

Panda Time Limit: 4000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 404664-bit integer IO format: %I64d      Java class name: Main When I wrote down this letter, you may have been on the airplane to U.S. We have known for

hdu 4046 Panda 树状数组

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been on the airplane to U.S. We have known for 15 years, which has exceeded one-fifth of my whole life. I still remember the first time we went to the mov

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;