Skip to main content
  1. Posts/

hdu 4451 Dressing (计数,思维题)

Note: This article is available in Chinese only. 本文暂无英文版本。 View original

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的答案即可。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年03月03日 星期四 20时09分47秒
 4File Name :code/hdu/4451.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=2E6+7;
34int n,m,k;
35int p;
36int a[N];
37int clo[N];
38int sho[N];
39
40int main()
41{
42	#ifndef  ONLINE_JUDGE
43	freopen("code/in.txt","r",stdin);
44  #endif
45
46	while (~scanf("%d %d %d",&n,&m,&k)&&n&&m&&k)
47	{
48	    ms(clo,0);
49	    ms(sho,0);
50	    LL ans = 0LL;
51	    scanf("%d",&p);
52	    if (p==0)
53	    {
54		ans = 1LL*n*1LL*m*1LL*k;
55		printf("%lld\n",ans);
56		continue;
57	    }
58	    for ( int i = 0 ; i < p ; i++)
59	    {
60		char x[15],y[15];
61		int xid,yid;
62		scanf("%s %d %s %d",x,&xid,y,&yid);
63		if (x[0]=='c')
64		{
65		    clo[yid]++;
66		}
67		else
68		{
69		    sho[xid]++;
70		}
71	    }
72
73	    for ( int i = 1; i <= m ; i++)
74	    {
75		ans+=1LL*(n-clo[i])*1LL*(k-sho[i]);
76	    }
77	    printf("%lld\n",ans);
78	}
79
80  #ifndef ONLINE_JUDGE
81  fclose(stdin);
82  #endif
83    return 0;
84}

Related

hdu 5145 NPY and girls

http://acm.hdu.edu.cn/showproblem.php?pid=5145 题意:有n个女孩,编号1..n,第i个女孩在第a[i]个教室,m次访问,每次访问编号[L,R]的女孩,处于同一个教室的女孩一次只能访问一个,问有多少种访问方案。两个不同的方案当且仅当访问的顺序有所不同。

codeforces #334 div 2 D.Moodular Arithmetic

http://codeforces.com/contest/604/problem/D 题意:一个恒等式 f(kx%p)=kf(x)%p ,k,p为常数,且满足x对于定义域为0..p-1的p的整数,值域也在0..p-1范围(不一定一一对应)。问满足题意的f有多少个。 思路: f(0)=0,对于其他的值,当f(x)确定时,f(kx%p)也随之确定,那么把kx%p看做新的x,f(kkx%p)也随之确定…相当于【1,p-1】被分为r个小环,确定每个环可以任选一个数字,ans=p^r。环的个数可以用dfs跑一遍得到r. 注意当k=1的时候是特殊情况,f(x)恒等于f(x)那么答案应该有p的p次方种。因为对于p个f(0..p-1),每一个都可以任意取p种值。

poj 1322 chocolate (指数型母函数 )

·3 mins
http://poj.org/problem?id=1322 题意: 思路:别看n,m很大。。。但是想一下。。m显然不可能大于c(如果大于c,那么根据抽屉原理,至少存在一种巧克力大于一个,然而大于一个就会被取走…矛盾) 这样概率为0.m也不可能大于n,因为最好的情况就是取出的巧克力都放在了桌子上,如果总共取的还不到n个,又怎么可能剩下m(m>n)个呢。此外,还需要n,m奇偶性相同,否则设n-m=2K+1 ,说明如果要剩余m个,那么就要减少2k+1个,但是巧克力是两个两个减少的,减少的个数一定是偶数,因此矛盾。所以n,m奇偶性相同。