5021: Exchange Puzzle 

Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
Total Submit: 24            Accepted:4

Description

Given 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, given a list of up to 500 integer values the variable can possibly take, you need to count the number of different ways that 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.

Input

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.

Output

Print a single integer, giving the number of ways that you can assign values to variables so the expression above evaluates to a multiple of 7.

Sample Input

10
B 2
E 5
S 7
I 10
O 16
M 19
B 3
G 1
I 9
M 2

Sample Output

2

Hint

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

Source

USACO 2015 US Open

我感觉我的代码稳稳稳,因为时间限制,不可能枚举那么多数,只存在+的关系,所以先取模分下类

#include<stdio.h>
int S[],v[][];
int main(){
int n;S['B']=,S['E']=,S['S']=,S['I']=,S['G']=,S['O']=,S['M']=;
scanf("%d",&n);
for(int i=;i<n;i++){
getchar();
char c;int x;
scanf("%c%d",&c,&x);
v[S[c]][((x%)+)%]++;
}
__int64 cnt=;
for(int i=;i<;i++){__int64 B=v[][i];
for(int j=;j<;j++){int E=v[][j];
for(int k=;k<;k++){int S=v[][k];
for(int l=;l<;l++){int I=v[][l];
for(int m=;m<;m++){int G=v[][m];
for(int n=;n<;n++){int O=v[][n];
for(int o=;o<;o++){int M=v[][o];
if((i+*j+*k+l)*(m+n+j+k)*(o+*n)%==)
cnt+=B*E*S*I*G*O*M;}}}}}}}
printf("%I64d\n",cnt);
return ;}

TOJ 5021: Exchange Puzzle的更多相关文章

  1. POJ 2893 M × N Puzzle(树状数组求逆序对)

                                                               M × N Puzzle Time Limit: 4000MS   Memory ...

  2. UESTC_Eight Puzzle 2015 UESTC Training for Search Algorithm & String<Problem F>

    F - Eight Puzzle Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) ...

  3. M × N Puzzle POJ - 2893(奇数码)

    The Eight Puzzle, among other sliding-tile puzzles, is one of the famous problems in artificial inte ...

  4. 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜

    Eight Puzzle Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...

  5. POJ 2983 M × N Puzzle

    M × N Puzzle Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 4860   Accepted: 1321 Des ...

  6. OpenCASCADE Data Exchange - 3D PDF

    OpenCASCADE Data Exchange - 3D PDF eryar@163.com Abstract. Today most 3D engineering model data are ...

  7. Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net

    Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...

  8. RabbitMQ学习系列(四): 几种Exchange 模式

    上一篇,讲了RabbitMQ的具体用法,可以看看这篇文章:RabbitMQ学习系列(三): C# 如何使用 RabbitMQ.今天说些理论的东西,Exchange 的几种模式. AMQP协议中的核心思 ...

  9. [Exchange 2013]创建约会和会议

    简介 会议和约会之间的重要区别是,会议有与会者,并且没有约会.约会和会议可以是单实例或属于重复序列,但与会者. 房间或资源中不包括约会,因为它们不需要发送一条消息.在内部,Exchange 使用相同的 ...

随机推荐

  1. PL/SQL 多表关联UPDATE

    假设有两个表A和B,A表字段a,b,c,d,B表字段b,e,f,两表的关联条件是字段b,现在想做个data patch,欲将B表中的字段e的值patch给A表的字段c. 有如下两种方法: 1 upda ...

  2. 解决部分浏览器不能显示itext生成的PDF文件文本域内容问题

    利用Itext可以实现pdf的高效动态生成,但在实践过程中遇到了一个问题: 即itext利用map中的值设置到pdf模板上建立的文本域中时:能成功生成,但是在部分浏览器上(360,QQ,等浏览器)无法 ...

  3. MAC无法确认开发者身份

    网上下载的软件,如果来自身份不明的开发者,在MAC上打开时会提示无法确认开发者的身份,在网上找到了一篇尝试解决的文章,文章链接地址为http://jingyan.baidu.com/article/f ...

  4. MySQL出现GROUP BY clause错误解决办法

    #1)当mysql数据库出现如下错误:#which is not functionally dependent on columns in GROUP BY clause; this is incom ...

  5. 在使用线程池时应特别注意对ThreadLocal的使用

    使用ThreadLocal并且有线程池时要特别注意,ThreadLocal是以线程为key的,而线程池里面的线程是会被重新利用的,所以如果有使用线程池并且使用ThreadLocal来保存状态信息时要特 ...

  6. How to install Eclipse in linux

    http://askubuntu.com/questions/26632/how-to-install-eclipse

  7. 快速WCF

    初级原理:通得过地址调用接口服务,接口服务调用对应实现方法 援引文章地址:http://www.cnblogs.com/iamlilinfeng/archive/2012/09/25/2700049. ...

  8. HtmlUnit爬取Ajax动态生成的网页以及自动调用页面javascript函数

    HtmlUnit官网的介绍: HtmlUnit是一款基于Java的没有图形界面的浏览器程序.它模仿HTML document并且提供API让开发人员像是在一个正常的浏览器上操作一样,获取网页内容,填充 ...

  9. Difference between x:Reference and x:Name

    {x:Reference ...} -> returns just a reference of an object it doesn't create that "bridge&qu ...

  10. ios UITableViewCell重用问题

    在写sina 微博界面的过程中使用到了cell,那么就是在cell上添加一些控件,但是由于每条微博的内容都是不同的,所以在显示的过程中,出现了内容重叠的问题,其实就是UITableViewCell重用 ...