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. 关于PHP静态方法调用和实例化类调用的区别

    1.首先来澄清一些观点 由于静态方法在内存中只有一份,无论你调用多少次,都是共用的,而且没有对象的概念,所以不能在静态方法里面使用$this调用,如果非得调用的话,只能实例化自身类 而实例化不一样,每 ...

  2. Codeforces Round #372 (Div. 2) C 数学

    http://codeforces.com/contest/716/problem/C 题目大意:感觉这道题还是好懂得吧. 思路:不断的通过列式子的出来了.首先我们定义level=i, uplevel ...

  3. Oracle record 解锁

    Oracle修改表中记录时出现record is locked by another user的弹出框问题 是因为在操作表中数据时没有commit,导致表被锁. 执行下面两行语句: (1)查看被锁表的 ...

  4. OpenGL 图形管道(graphics pipeline)过程

    1.总结:Graphics pipeline 主要分为两部分工作 把3D坐标转换成2D坐标 把2D坐标转换成真实的有颜色的像素 2.下图就是一个顶点数据经过几个步骤后转化成显示在屏幕上像素的过程(一般 ...

  5. MYSQL和ORACLE的触发器与存储过程语法差异

    整改了一番脚本,遇到了一些两种数据库之间的差异,记录一下: 触发器: 差异 MYSQL ORACLE 说明 创建语句不同 create trigger `AA` BEFORE INSERT on `B ...

  6. Food on the Plane

    Food on the Plane time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. 以图搜图(一):Python实现dHash算法(转)

    近期研究了一下以图搜图这个炫酷的东西.百度和谷歌都有提供以图搜图的功能,有兴趣可以找一下.当然,不是很深入.深入的话,得运用到深度学习这货.Python深度学习当然不在话下. 这个功能最核心的东西就是 ...

  8. java 线程的中断

    Example12_6.java public class Example12_6 { public static void main(String args[]) { ClassRoom room6 ...

  9. 转:LoadRunner常用函数列表

    Web相关函数 函    数 功 能 描 述 web_custom_request 用户可以通过该函数自行创建一个HTTP请求的函数 web_image 模拟用户单击图片操作的函数 web_link ...

  10. 批量文件重命名工具-极力推荐 advanced renamer

    http://www.advancedrenamer.com/  功能太强大了,自己慢慢探索吧.