Bessie Goes Moo
题目传送门
题目大意
一共七个字符,分别为
B
E
S
I
G
O
M
BESIGOM
BESIGOM
给你n个每个字符对应的数字,可能一个字符对应多个整数
求满足
(
B
+
E
+
S
+
S
+
I
+
E
)
(
G
+
O
+
E
+
S
)
(
M
+
O
+
O
)
%
7
=
0
(B+E+S+S+I+E)(G+O+E+S)(M+O+O)\%7=0
(B+E+S+S+I+E)(G+O+E+S)(M+O+O)%7=0的情况数
思路
对输入的数,可以先进行取模,即对7模数相同的可以看做一个数
然后直接
O
(
n
7
)
O(n^7)
O(n7)暴力模拟即可
AC Code
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<set>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
// #define TDS_ACM_LOCAL
const int N=2e5 +9;
char s;
int n, m;
int flag[10][N];
set<int> a[10];
void solve(){
cin>>n;
string tep="BESIGOM";
for(int i=1; i<=n; i++){
cin>>s>>m;
m=(m%7+7)%7;
int j;
for(j=0; j<7; j++) if(tep[j]==s) break;
a[j].insert(m);
flag[j][m]++;
}
int ans=0;
for(auto b:a[0])
for(auto e:a[1])
for(auto s:a[2])
for(auto i:a[3])
for(auto g:a[4])
for(auto o:a[5])
for(auto m:a[6])
if((b+e+s+s+i+e)*(g+o+e+s)*(m+o+o)%7==0)
ans+=flag[0][b]*flag[1][e]*flag[2][s]*flag[3][i]*flag[4][g]*flag[5][o]*flag[6][m];
cout<<ans<<endl;
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
solve();
return 0;
}