AtCoder Beginner Contest 089 C - March 题解

C - March


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

There are N people. The name of the i-th person is Si.

We would like to choose three people so that the following conditions are met:

  • The name of every chosen person begins with M, A, R, C or H.
  • There are no multiple people whose names begin with the same letter.

How many such ways are there to choose three people, disregarding order?

Note that the answer may not fit into a 32-bit integer type.

Constraints

  • 1≤N≤105
  • Si consists of uppercase English letters.
  • 1≤|Si|≤10
  • SiSj(ij)

Input

Input is given from Standard Input in the following format:

N
S1
:
SN

Output

If there are x ways to choose three people so that the given conditions are met, print x.


Sample Input 1

Copy
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

Copy
2

We can choose three people with the following names:

  • MASHIKE, RUMOI, HABORO

  • MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.


Sample Input 2

Copy
4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

Copy
0

Note that there may be no ways to choose three people so that the given conditions are met.


Sample Input 3

Copy
5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

Copy
7

题意:名字开头字母为'M','A','R','C','H'中的一个,且不能相同所组成的三人组合有多少个?
分析:根据名字分为5类,M、A、R、C、H。统计出每类人数,计算乘积后再求和即可。注意,会超int,需要开long long,第一次WA在了只把ans开long long了,未考虑中间情况的可能性。
代码:
 1     #include<cstdio>
 2     #include<cstring>
 3     #include<algorithm>
 4     #include<iostream>
 5     #include<string>
 6     #include<vector>
 7     #include<stack>
 8     #include<bitset>
 9     #include<cstdlib>
10     #include<cmath>
11     #include<set>
12     #include<list>
13     #include<deque>
14     #include<map>
15     #include<queue>
16     using namespace std;
17     typedef long long ll;
18     const double PI = acos(-1.0);
19     const double eps = 1e-6;
20     const int INF = 0x3f3f3f3f;
21      
22     const int MAXN =1e5+10;
23      
24     char s[MAXN][10+10];
25     long long int march[5+5];
26     int main(){
27         int N =0;
28         scanf("%d",&N);
29         long long int ans =0;
30         for(int i=0;i<N;i++){
31             scanf("%s",&s[i]);
32         }
33         for(int i=0;i<N;i++){
34             if(s[i][0]=='M')    march[0]++;
35             if(s[i][0]=='A')    march[1]++;
36             if(s[i][0]=='R')    march[2]++;
37             if(s[i][0]=='C')    march[3]++;
38             if(s[i][0]=='H')    march[4]++;
39         }
40         
41         ans=march[0]*march[1]*march[2]+march[0]*march[1]*march[3]+march[0]*march[1]*march[4]+march[0]*march[2]*march[3]+march[0]*march[2]*march[4]+march[0]*march[3]*march[4]+march[1]*march[2]*march[3]+march[1]*march[2]*march[4]+march[1]*march[3]*march[4]+march[2]*march[3]*march[4];
42         
43         printf("%lld",ans);
44         return 0;
45     }
View Code

 


posted @ 2018-03-05 20:59  caomp  阅读(216)  评论(0)    收藏  举报