Bessie Goes Moo Topic Description Farmer John and Bessie the cow love to exchange math puzzles in their free time. The last puzzle FJ gave Bessie is quite difficult and she failed to solve it. Now she wants-get even with FJ by giving him a challenging puzzle.
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 V Ariable, not a zero). For each variable, she gives FJ a list of up to $ 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 is too large to fit into a 32-bit integer, so we probably want to use 64-bit int Egers (e.g., "Long long" s in C or C + +). Enter the first line of the input contains an integer N. The next N lines each contain a variable and a possible value for that variable. Each variable would appear in the this list at least once and at the most times. No possible value would be listed more than once for the same variable. All possible values would be in the range−105 to 105. Output print a single integer, giving the number of ways FJ can assign values to variables so the expression above evaluates to A multiple of 7. Sample input
10B 2E 5S 7I 10O 16M 19B 3G 1I 9M 2
Sample output
2
Tips
The possible assignments is
(b,e,s,i,g,o,m) = (2, 5, 7, 9, 1, (+), 51,765)
= (2, 5, 7, 9, 1,, 2), 34,510
Analysis: For each number modulo, then violence can, Complexity O (7^7);
Code:
#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>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e3+Ten;Const intdis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespacestd;ll gcd (ll p,ll q) {returnq==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;}returnF;}intn,m,k,t;ll ans;Chara[Ten];intGaoCharBP) { inti; stringq="Besigom"; for(i=0; q[i]!=p;i++); returni;}Set<int>p[7];intq[7][7];intMain () {inti,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(intx:p[0]) for(inty:p[1]) for(intz:p[2]) for(ints:p[3]) for(intt:p[4]) for(inte:p[5]) for(intr: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"); return 0;}
Bessie Goes Moo