Bessie Goes Moo
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)
- const int maxn=1e3+;
- const int dis[][]={{,},{-,},{,-},{,}};
- using namespace std;
- ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
- ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
- int n,m,k,t;
- ll ans;
- char a[];
- int gao(char p)
- {
- int i;
- string q="BESIGOM";
- for(i=;q[i]!=p;i++);
- return i;
- }
- set<int>p[];
- int q[][];
- int main()
- {
- int i,j;
- scanf("%d",&n);
- while(n--)
- {
- scanf("%s%d",a,&m);
- m%=;
- while(m<)m+=;
- p[gao(a[])].insert(m);
- q[gao(a[])][m]++;
- }
- for(int x:p[])
- for(int y:p[])
- for(int z:p[])
- for(int s:p[])
- for(int t:p[])
- for(int e:p[])
- for(int r:p[])
- {
- if((x+y+y+z+z+s)*(t+e+y+z)*(r+e+e)%==)
- ans+=1LL*q[][x]*q[][r]*q[][y]*q[][z]*q[][s]*q[][t]*q[][e];
- }
- printf("%lld\n",ans);
- //system("pause");
- return ;
- }
Bessie Goes Moo的更多相关文章
- 【题解】Luogu P3123 [USACO15OPEN]贝茜说哞Bessie Goes Moo
Luogu P3123 [USACO15OPEN]贝茜说哞Bessie Goes Moo 题目描述 Farmer John and Bessie the cow love to exchange ma ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Moo University - Financial Aid
Moo University - Financial Aid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6020 Accep ...
- poj 2010 Moo University - Financial Aid
Moo Univ ...
- poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)
Description Bessie noted that although humans have many universities they can attend, cows have none ...
- bzoj 4506: [Usaco2016 Jan]Fort Moo
4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any ...
- DP【洛谷P3135】[USACO16JAN]堡哞Fort Moo
[洛谷P3135][USACO16JAN]堡哞Fort Moo Bessie和她的朋友Elsie正在建筑一个堡垒,与任何一个好的堡垒一样,这个需要一个强固的框架.Bessie想造一个轮廓是1m宽的空心 ...
- bzoj4506: [Usaco2016 Jan]Fort Moo(暴力)
4506: [Usaco2016 Jan]Fort Moo Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 145 Solved: 104[Submi ...
随机推荐
- 解决“Xlib.h not found when building graphviz on Mac OS X 10.8”错误
After installing XQuartz you may add a symlink to your X11 installation folder by just entering (安装X ...
- karma+jasmine自动化测试
1.安装nodejs,进入项目目录 2.安装karma和相关插件 npm install karma --save-dev npm install karma-jasmine karma-chrome ...
- 转: Windows下安装Oracle Database 12c Release 1(12.1.0.2.0) - Enterprise Edition
http://www.cnblogs.com/xqzt/p/4395053.html Windows下安装Oracle Database 12c Release 1(12.1.0.2.0) - Ent ...
- plsql 安装后database下拉没有东西
今天第一天上班我自己也有点紧张,但是问题还是有的: 今天来说一下问题,就是装了plsql竟然在database这一栏没有东西,我也是纠结了很久,感觉今天的任务也被拉下了. 其实这个问题在我以前装的时候 ...
- 【纯欧拉函数】 poj 2407
#include <cstdio> #include <iostream> using namespace std; int phi(int x) { int t=x; ;i& ...
- opencv---cvor
void cvXor计算两个数组中的每个元素的按位异或. void cvXor (const CvArr* src1, const CvArr* src2, CvArr* dst, const CvA ...
- 689D Magic Odd Square 奇数幻方
1 奇数阶幻方构造法 (1) 将1放在第一行中间一列; (2) 从2开始直到n×n止各数依次按下列规则存放:按 45°方向行走,向右上,即每一个数存放的行比前一个数的行数减1,列数加1 (3) 如果行 ...
- Setting DPDK+OVS+QEMU on CentOS
Environment Build Step: these packages are needed for building dpdk+ovs: yum install -y make gcc gli ...
- DZY Loves Partition
问题描述 DZY喜欢拆分数字.他想知道能否把nn拆成恰好kk个不重复的正整数之和. 思考了一会儿之后他发现这个题太简单,于是他想要最大化这kk个正整数的乘积.你能帮帮他吗? 由于答案可能很大,请模10 ...
- 视频 -> 帧 浅析
原创:转载请注明出处 关于帧率 首先以下几个概念必须弄清楚 1.一个帧就是一个画面 2.视频有无数个帧组成 3.表达时间的量 CMTime 的定义: typedef struct { CMTimeV ...