Bessie Goes Moo

题目描述

Farmer John and Bessie the cow love to exchange math puzzles in their free time. The last puzzle FJ gave Bessie was quite difficult and she failed to solve it. Now she wants to 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 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++).

输入

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 will appear in this list at least once and at most 500 times. No possible value will be listed more than once for the same variable. All possible values will be in the range −105 to 105.

输出

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.

样例输入

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的更多相关文章

  1. 【题解】Luogu P3123 [USACO15OPEN]贝茜说哞Bessie Goes Moo

    Luogu P3123 [USACO15OPEN]贝茜说哞Bessie Goes Moo 题目描述 Farmer John and Bessie the cow love to exchange ma ...

  2. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. Moo University - Financial Aid

    Moo University - Financial Aid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6020 Accep ...

  5. poj 2010 Moo University - Financial Aid

                                                                                                Moo Univ ...

  6. poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)

    Description Bessie noted that although humans have many universities they can attend, cows have none ...

  7. bzoj 4506: [Usaco2016 Jan]Fort Moo

    4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any ...

  8. DP【洛谷P3135】[USACO16JAN]堡哞Fort Moo

    [洛谷P3135][USACO16JAN]堡哞Fort Moo Bessie和她的朋友Elsie正在建筑一个堡垒,与任何一个好的堡垒一样,这个需要一个强固的框架.Bessie想造一个轮廓是1m宽的空心 ...

  9. bzoj4506: [Usaco2016 Jan]Fort Moo(暴力)

    4506: [Usaco2016 Jan]Fort Moo Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 145  Solved: 104[Submi ...

随机推荐

  1. 今天开通博客,记录我作为一个小菜鸟在iOS学习中的点点滴滴

    一直以来都是默默的关注各位同仁,没有为网站作什么贡献. 现在借开始学习iOS开发的这个机会开博,集中于介绍这个过程,激励我自己. 谢谢大家!

  2. iOS长按选择

    确实,其实就是一个长按手势 + 图片二维码识别,原生SDK从8.0开始支持 /** *  从照片中直接识别二维码 *  @param qrCodeImage 带二维码的图片 *  @param myQ ...

  3. 用caffe给图像的混乱程度打分

    Caffe应该是目前深度学习领域应用最广泛的几大框架之一了,尤其是视觉领域.绝大多数用Caffe的人,应该用的都是基于分类的网络,但有的时候也许会有基于回归的视觉应用的需要,查了一下Caffe官网,还 ...

  4. 自定义cell,根据数据源,要对cell的布局进行调整,没有实现调整的相应效果

    自定义cell,用于两种显示情况,首次进来A种情况(主材页面),正确显示,然后切换B种情况(辅材情况),可以正确显示,但是当再次切换回A种情况(主材情况)的时候,主材cell不能正常显示了,遗留的B中 ...

  5. Eclipse下配置和使用Hibernate Tools

    本文转自:http://radiumwong.iteye.com/blog/358585 Hibernate Tools可以通过访问已经建立好的数据库以反向工程方式生成POJO文件. 今天就来说一下如 ...

  6. sql优化__rownum的使用【转】

    ROWNUM的概念ROWNUM是一个虚假的列.它将被分配为 1,2,3,4,...N,N 是行的数量.一个ROWNUM值不是被永久的分配给一行 (这是最容易被误解的).表中的某一行并没有标号:你不可以 ...

  7. php秒杀

    我们知道数据库处理sql是一条条处理的,假设购买商品的流程是这样的: sql1:查询商品库存 ? 1 2 3 4 5 if(库存数量 > 0) {   //生成订单...   sql2:库存-1 ...

  8. OpenGL ES着色器语言之变量和数据类型(一)(官方文档第四章)和varying,uniform,attribute修饰范围

    OpenGL ES着色器语言之变量和数据类型(一)(官方文档第四章)   所有变量和函数在使用前必须声明.变量和函数名是标识符. 没有默认类型,所有变量和函数声明必须包含一个声明类型以及可选的修饰符. ...

  9. struts2中的文件上传,文件下载

    文件上传: Servlet中的文件上传回顾 前台页面 1.提交方式post 2.表单类型 multipart/form-data 3.input type=file 表单输入项 后台 apache提交 ...

  10. div.2/Bellovin<最长上升子序列>

    题意: 序列arr[i--n];输出以a[i]为结尾的最长上升子序列.1<=n<=100000; 思路: O(n*log(n)),求最长上升子序列. #include<cstdio& ...