hdu4451 Dressing(容斥原理)

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-8;
const int INF=1000000000;
const int maxp=2000000+10;
int n,m,k,p,p1,p2,ans;
int pants[1010];
struct Dis
{
    char s1[10],s2[10];
    int t1,t2;
} a[maxp];
int main()
{
    //freopen("in10.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(scanf("%d%d%d",&n,&m,&k)==3)
    {
        if(n==0&&m==0&&k==0) break;
        ans=n*m*k;
        p1=p2=0;
        memset(pants,0,sizeof(pants));
        scanf("%d",&p);
        for(int i=0; i<p; i++)
        {
            scanf("%s%d%s%d",a[i].s1,&a[i].t1,a[i].s2,&a[i].t2);
            if(a[i].s1[0]=='c') p1++;
            else
            {
                p2++;
                pants[a[i].t1]++;
            }
        }
        ans-=(p1*k+p2*n);
        for(int i=0;i<p;i++)
        {
            if(a[i].s2[0]=='p')
            {
                ans+=pants[a[i].t2];
            }
        }
        printf("%d\n",ans);
    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

 

posted @ 2014-11-21 17:21  周洋  阅读(151)  评论(0编辑  收藏  举报