hdu 4451 Dressing (计数,思维题)
http://acm.hdu.edu.cn/showproblem.php?pid=4451 题意:N clothes, M pants and K shoes,然后给出p个不合法的搭配,形式是“clothes x pants y” or “pants y shoes z”.” 问有多少种合法的方案。 思路:一开始觉得是容斥。。当然可以。。但是实际上,不合法的搭配的形式比较简单,每种不合法的发配都是两个两个的不合法,以及每种不合法的形式都有pants,那么我们就可以通过先确定pants,对于每种pants,方案数就是能和当前pants搭配的clothes数,乘以能和当前pants搭配的shoes数,然后累加每种pants的答案即可。
/* ***********************************************
Author :111qqz
Created Time :2016年03月03日 星期四 20时09分47秒
File Name :code/hdu/4451.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=2E6+7;
7int n,m,k;
8int p;
9int a[N];
10int clo[N];
11int sho[N];
1int main()
2{
3 #ifndef ONLINE_JUDGE
4 freopen("code/in.txt","r",stdin);
5 #endif
1 while (~scanf("%d %d %d",&n,&m,&k)&&n&&m&&k)
2 {
3 ms(clo,0);
4 ms(sho,0);
5 LL ans = 0LL;
6 scanf("%d",&p);
7 if (p==0)
8 {
9 ans = 1LL*n*1LL*m*1LL*k;
10 printf("%lld\n",ans);
11 continue;
12 }
13 for ( int i = 0 ; i < p ; i++)
14 {
15 char x[15],y[15];
16 int xid,yid;
17 scanf("%s %d %s %d",x,&xid,y,&yid);
18 if (x[0]=='c')
19 {
20 clo[yid]++;
21 }
22 else
23 {
24 sho[xid]++;
25 }
26 }
1 for ( int i = 1; i <= m ; i++)
2 {
3 ans+=1LL*(n-clo[i])*1LL*(k-sho[i]);
4 }
5 printf("%lld\n",ans);
6 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}