A题,直接开map统计需要的字母即可。但是样例1的单词不是题目中的那个单词,被坑了一次。不过学习了min原来可以min({1,2,3});这样写来比较多个参数。
B题,类似于筛法nlogn即可。但是题目中说了,如果只有一个宠物,是不会自己打自己的,因此如果只有一个1,答案应该是1(也即答案至少为1)。代码如下:

1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 100000 + 5; 4 5 int n; 6 int a[N]; 7 int vis[N]; 8 9 int main() 10 { 11 cin >> n; 12 int maxn = 0; 13 int ans = 1; 14 for(int i=1;i<=n;i++) {scanf("%d",a+i);vis[a[i]]++; maxn = max(maxn, a[i]);} 15 for(int i=2;i<=maxn;i++) 16 { 17 int cnt = vis[i]; 18 for(int j=2*i;j<=maxn;j+=i) 19 { 20 cnt += vis[j]; 21 } 22 ans = max(ans, cnt); 23 } 24 cout << ans << endl; 25 }
CD题意都看了半天。。C,如果多个场馆内的宠物有一样的几个,那么这最长的长度的阶乘就是对答案的贡献,然后就可以使用下面的方法来做了(注意,如果某些宠物并没有出现,它们也要算阶乘贡献,所以下面计算答案时是遍历到m)。第一次见到对vector的排序(其实就和字典序一样),代码如下:

1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 1000000 + 5; 4 const int mod = 1e9 + 7; 5 6 int n,m; 7 vector<int> pos[N]; 8 9 int main() 10 { 11 cin >> n >> m; 12 for(int i=1;i<=n;i++) 13 { 14 int T;scanf("%d",&T); 15 while(T--) 16 { 17 int id; 18 scanf("%d",&id); 19 pos[id].push_back(i); 20 } 21 } 22 sort(pos+1,pos+1+m); 23 int ans = 1; 24 int t = 1; 25 for(int i=2;i<=m;i++) 26 { 27 if(pos[i-1] == pos[i]) {t++; ans = 1LL* ans * t % mod;} 28 else t = 1; 29 } 30 cout << ans << endl; 31 return 0; 32 }
D题好容易看懂了题目的意思,结果不会- -。tourist的代码如下:

1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int md = 1000000007; 6 7 inline void add(int &a, int b) { 8 a += b; 9 if (a >= md) { 10 a -= md; 11 } 12 } 13 14 const int NUM = 20; 15 const int N = (1 << NUM) + 10; 16 const int LEN = 79; 17 18 int f[LEN][N]; 19 char s[LEN]; 20 21 int main() { 22 int len; 23 scanf("%d", &len); 24 scanf("%s", s); 25 for (int i = 0; i < len; i++) { 26 f[i][0] = 1; 27 for (int t = 0; t < (1 << NUM); t++) { 28 if (f[i][t] == 0) { 29 continue; 30 } 31 int x = 0; 32 for (int j = i; j < len; j++) { 33 x = x * 2 + s[j] - '0'; 34 if (x > NUM) { 35 break; 36 } 37 if (x > 0) { 38 add(f[j + 1][t | (1 << (x - 1))], f[i][t]); 39 } 40 } 41 } 42 } 43 int ans = 0; 44 for (int i = 0; i <= len; i++) { 45 int r = 1; 46 while (r < (1 << NUM)) { 47 add(ans, f[i][r]); 48 r = r * 2 + 1; 49 } 50 } 51 printf("%d ", ans); 52 return 0; 53 }