• 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 }
  • 相关阅读:
    SQL Server AUTO_FIX_Login_Users
    SQL Server Always On 切换主机Login和User无法匹配解决方案
    SQL Server 目标主体名称不正确,无法生成 SSPI 上下文
    SQL Server Rebuild Index
    jqery和js如何判断checkbox是否选中 (转)
    jxl
    jxl 管理excel
    Bootstrap库之Modals
    jquery attr()
    js 验证数字(验证字符串是否是数字)
  • 原文地址:https://www.cnblogs.com/111qqz/p/4716181.html
Copyright © 2020-2023  润新知