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 ...
随机推荐
- AIR使用文件对象操作文件和目录
文件对象是啥?文件对象(File对象)是在文件系统中指向文件或目录的指针.由于安全原因,只在AIR中可用. 文件对象能做啥? 获取特定目录,包括用户目录.用户文档目录.该应用程序启动的目录和程序目录 ...
- Linux网卡配置与绑定
一定要在服务管理中关闭NetworkManager服务并禁用自动启动. 第一步:先查看下本机网卡,使用命令到network-scripts 下 [root@root~]# cd /etc/syscon ...
- 关于iOS socket都在这里了
socket(套接字)是通信的基石,是支持TCP/IP协议的网络通信的基本操作单元,包含进行网络通信必须的五种信息:连接使用的协议,本地主机的IP地址,本地进程的协议端口,远地主机的IP地址,远地进程 ...
- 转载 Deep learning:六(regularized logistic回归练习)
前言: 在上一讲Deep learning:五(regularized线性回归练习)中已经介绍了regularization项在线性回归问题中的应用,这节主要是练习regularization项在lo ...
- java 缓冲流
english.txt The arrow missed the target. They rejected the union demand. Where does this road go to? ...
- sphinx query multiple indexes in php
http://stackoverflow.com/questions/17494784/searching-a-particular-index-using-sphinx-from-multiple- ...
- 剑指offer 重建二叉树
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- 如何让struts2和servlet的共存
如何让struts2和servlet的共存 (2013-08-29 14:07:49) 转载▼ 标签: servlet与struts2共存 同时配置struts2与ser servlet访问不到 分类 ...
- Redis 密码设置和登录
Redis 一般在生产环境中,大家都不使用密码,为了确保安全,都是在防火墙上对redis端口做IP白名单的 我是个技术控,我非得了解一下密码这回事[虽然以后不会用到,呵呵] 好了,废话不多说,简单介绍 ...
- Cacti安装详细步骤(转)
一.cacti概述 1. cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户. ...