首页 / GO / Bessie Goes Moo
Bessie Goes Moo
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Bessie Goes Moo,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2986字,纯文字阅读大概需要5分钟。
内容图文
Bessie Goes Moo
题目描述
Bessie gives FJ the expression (B+E+S+S+I+E)(G+O+E+S)(M+O+O), containing the seven variables B,E,S,I,G,O,M (the "O" is a variable, not a zero). For each variable, she gives FJ a list of up to 500 integer values the variable can possibly take. She asks FJ to count the number of different ways he can assign values to the variables so the entire expression evaluates to a multiple of 7.
Note that the answer to this problem can be too large to fit into a 32-bit integer, so you probably want to use 64-bit integers (e.g., "long long"s in C or C++).
输入
输出
样例输入
10
B 2
E 5
S 7
I 10
O 16
M 19
B 3
G 1
I 9
M 2
样例输出
2
提示
The two possible assignments are
(B,E,S,I,G,O,M) = (2, 5, 7, 9, 1, 16, 19) -> 51,765
= (2, 5, 7, 9, 1, 16, 2 ) -> 34,510
分析:对每个数取模,然后暴力即可,复杂度O(7^7);
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) constint maxn=1e3+10; constint dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}}; usingnamespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} int n,m,k,t; ll ans; char a[10]; int gao(char p) { int i; string q="BESIGOM"; for(i=0;q[i]!=p;i++); return i; } set<int>p[7]; int q[7][7]; int main() { int i,j; scanf("%d",&n); while(n--) { scanf("%s%d",a,&m); m%=7; while(m<0)m+=7; p[gao(a[0])].insert(m); q[gao(a[0])][m]++; } for(int x:p[0]) for(int y:p[1]) for(int z:p[2]) for(int s:p[3]) for(int t:p[4]) for(int e:p[5]) for(int r:p[6]) { if((x+y+y+z+z+s)*(t+e+y+z)*(r+e+e)%7==0) ans+=1LL*q[0][x]*q[6][r]*q[1][y]*q[2][z]*q[3][s]*q[4][t]*q[5][e]; } printf("%lld\n",ans); //system("pause");return0; }
原文:http://www.cnblogs.com/dyzll/p/5775230.html
内容总结
以上是互联网集市为您收集整理的Bessie Goes Moo全部内容,希望文章能够帮你解决Bessie Goes Moo所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。