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+10; const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}}; using namespace 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");return 0; }
转载于:https://www.cnblogs.com/dyzll/p/5775230.html
Bessie Goes Moo相关推荐
- Bessie Goes Moo(暴力)
Bessie Goes Moo 题目传送门 Bessie Goes Moo 题目大意 一共七个字符,分别为BESIGOMBESIGOMBESIGOM 给你n个每个字符对应的数字,可能一个字符对应多个整 ...
- 洛谷 P1885 Moo
P1885 Moo 题目描述 奶牛Bessie最近在学习字符串操作,它用如下的规则逐一的构造出新的字符串: S(0) = "moo" S(1) = S(0) + "m&q ...
- dfs暴力模拟 Moo(洛谷 P1885)
Moo 题目描述 奶牛Bessie最近在学习字符串操作,它用如下的规则逐一的构造出新的字符串: S(0) = "moo" S(1) = S(0) + "m"+ ...
- usaco ★Bessie Come Home 回家
★Bessie Come Home 回家 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃,所以她们开始向谷仓走去. 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有 ...
- POJ 2231 Moo Volume(递推、前缀和)
题外话: POJ 2231 Moo Volume 题意: 解题过程: AC代码: 题外话: emm--第三套题好像综合了其他OJ的题目蛤,那么我就把题目分开了发了蛤蛤-- POJ 2231 Moo V ...
- Moo.fx 超级轻量级的 javascript 特效库
Moo.fx是 一个超级轻量级的 javascript 特效库(7k),能够与 prototype.js 或mootools 框架一起使用.它非常快.易于使用.跨浏览器.符合标准,提供控制和修改任何 ...
- [BZOJ1643][Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
1643: [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪 Time Limit: 5 Sec Memory Limit: 64 MB Submit: ...
- bzoj1679[Usaco2005 Jan]Moo Volume 牛的呼声*
bzoj1679[Usaco2005 Jan]Moo Volume 牛的呼声 题意: N只牛,每只牛都与其他N-1只牛聊着天.一个对话的进行,需要两只牛都按照和她们间距离等大的音量吼叫,计算音量和.N ...
- 【BZOJ】1679: [Usaco2005 Jan]Moo Volume 牛的呼声(数学)
http://www.lydsy.com/JudgeOnline/problem.php?id=1679 水题没啥好说的..自己用笔画画就懂了 将点排序,然后每一次的点到后边点的声音距离和==(n-i ...
最新文章
- C# 结构与类的区别
- Qt 5 打包成一个单文件方法,可以在其他电脑运行(附资源)
- Mongodb源码分析--Replication之主从模式--Master
- python装饰器 property_Python中@property装饰器的使用技巧性解析(代码示例)
- python sys,os模块总结
- Hello XTCPC
- 一起教育科技登陆纳斯达克:首日股价上涨0.67%
- 苹果a10处理器_【突然】苹果宣布2019款iPad降价 发布不到半年最高降500
- 蓝桥杯 省赛 python_第十一届蓝桥杯软件省级大赛第二场python3,类省赛,Python3
- ubuntu安装最新的rails-4.2.0
- 07-图5 Saving James Bond - Hard Version
- razor读取mysql_MVC 数据库增删改查(Razor)方法(1)和数据库
- python md5加密_python中的md5加密
- 渗透神器----Windows10 渗透工具包
- NRF52840开发注意
- [Python][Scrapy] Scrapy 官方文档
- 2021水利水电安全员模拟考试案例题库及答案
- ab进行压力测试详解
- 二叉树的深度和平衡二叉树的深度
- [Python]查看Python版本