whust #0.2 I Incognito

I
17
Incognito
Spies use attributes to disguise themselves to make sure that
they are not recognized. For example, when putting on sun-
glasses, a spy suddenly looks completely different and cannot
be recognized anymore. Every combination of attributes gives
a different appearance, but not all combinations are possible.
For example, a hat and a turban are both headgear and cannot
be used at the same time. Given the list of available attributes,
compute how many distinct disguises can be made.
Input
On the first line one positive number: the number of test cases,
at most 100. After that per test case:
• one line with an integer n (0 ≤ n ≤ 30): the number of
available attributes.
• n lines with two space-separated strings: the name and
the category of the attribute.
All strings consist of at least 1 and at most 20 lowercase letters. Within a test case all names
are distinct.
Output
Per test case:
• one line with an integer: the number of possible distinct disguises that can be made
with the given attributes, such that at most one attribute from each category is used.
Sample in- and output
Input 
2
3
hat headgear
sunglasses eyewear
turban headgear
3
mask face
sunglasses face
makeup face

Output

5
3

 

数学题.

由于每一种只能最多选一种

那么对于第i类,如果有a[i]个,可能的选择就是a[i]+1 (不选,选1,选2....选a[i]-1,选a[i]),

然后乘法原理,把每一类所有可能的选择数相乘.

但是有一种不满足题意,就是没一类恰好都没选,那么整体就没没选,所以要-1.

 1 /*************************************************************************
 2     > File Name: code/whust/#0.2/II.cpp
 3     > Author: 111qqz
 4     > Email: rkz2013@126.com 
 5     > Created Time: 2015年08月09日 星期日 16时50分17秒
 6  ************************************************************************/
 7 
 8 #include<iostream>
 9 #include<iomanip>
10 #include<cstdio>
11 #include<algorithm>
12 #include<cmath>
13 #include<cstring>
14 #include<string>
15 #include<map>
16 #include<set>
17 #include<queue>
18 #include<vector>
19 #include<stack>
20 #define y0 abc111qqz
21 #define y1 hust111qqz
22 #define yn hez111qqz
23 #define j1 cute111qqz
24 #define tm crazy111qqz
25 #define lr dying111qqz
26 using namespace std;
27 #define REP(i, n) for (int i=0;i<int(n);++i)  
28 typedef long long LL;
29 typedef unsigned long long ULL;
30 const int inf = 0x7fffffff;
31 string st1,st2;
32 map<string,LL>mp;
33 map<string,LL>::iterator it;
34 LL ans;
35 int main()
36 {
37     int T;
38     cin>>T;
39     int n;
40     while (T--)
41     {
42     ans = 1;
43     scanf("%d",&n);
44     mp.clear();
45     for ( int i = 0 ; i < n; i ++)
46     {
47         cin>>st1>>st2;
48         if (mp[st2]!=0)
49         {
50         mp[st2]++;
51         }
52         else
53         {
54         mp[st2]=1;
55         }
56     }
57     for ( it=mp.begin();it!=mp.end();it++)
58     {
59         ans*=(it -> second+1);
60     }
61     cout<<ans-1<<endl;
62 
63     }
64   
65     return 0;
66 }

 

转载于:https://www.cnblogs.com/111qqz/p/4716181.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值