TOJ 5021: Exchange Puzzle
5021: Exchange Puzzle 
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
我感觉我的代码稳稳稳,因为时间限制,不可能枚举那么多数,只存在+的关系,所以先取模分下类
#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的更多相关文章
- POJ 2893 M × N Puzzle(树状数组求逆序对)
M × N Puzzle Time Limit: 4000MS Memory ...
- 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) ...
- M × N Puzzle POJ - 2893(奇数码)
The Eight Puzzle, among other sliding-tile puzzles, is one of the famous problems in artificial inte ...
- 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜
Eight Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...
- POJ 2983 M × N Puzzle
M × N Puzzle Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 4860 Accepted: 1321 Des ...
- OpenCASCADE Data Exchange - 3D PDF
OpenCASCADE Data Exchange - 3D PDF eryar@163.com Abstract. Today most 3D engineering model data are ...
- Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net
Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...
- RabbitMQ学习系列(四): 几种Exchange 模式
上一篇,讲了RabbitMQ的具体用法,可以看看这篇文章:RabbitMQ学习系列(三): C# 如何使用 RabbitMQ.今天说些理论的东西,Exchange 的几种模式. AMQP协议中的核心思 ...
- [Exchange 2013]创建约会和会议
简介 会议和约会之间的重要区别是,会议有与会者,并且没有约会.约会和会议可以是单实例或属于重复序列,但与会者. 房间或资源中不包括约会,因为它们不需要发送一条消息.在内部,Exchange 使用相同的 ...
随机推荐
- Apache Kafka框架学习
背景介绍 消息队列的比较 kafka框架介绍 术语解释 文件存储 可靠性保证 高吞吐量实现 负载均衡 应用场景 背景介绍: kafka是由Apache软件基金会维护的一个开源流处理平台,由scala和 ...
- 在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个。必须提供所有成员。 (microsoft.sqlserver.smo)
问题:在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个.必须提供所有成员. (micro ...
- [转]八款开源Android游戏引擎
八款开源Android游戏引擎 1.Angle Angle是一款专为Android平台设计的,敏捷且适合快速开发的2D游戏引擎,基于OpenGL ES技术开发.该引擎全部用Java代码编写,并且可以根 ...
- A*和IDA*介绍
\(A*\)算法是一种很神奇的搜索方法,它属于启发式搜索中的一种.A*最主要的功能当然就是用来剪枝,提高搜索的效率.A*主要的实现方法是通过一个估价函数,每次对下一步进行一个估价,根据估价出的值来决定 ...
- Log4J的配置与使用详解
一.简介 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务器.NT的事件记录器.UNIX Syslog守护 ...
- 字符串数组 输入3个字符串,要求按由小到大的字母顺序输出; 输入n个学生的姓名和学号到字符串数组中,在输入一个姓名,如果班级有该生则返回其信息,否则返回本班无此人
输入3个字符串,要求按由小到大的字母顺序输出 如 输入franch england china,输出结果是china england franch 三个数排序输出,比较三个数的大小怎么做? a=18 ...
- ios之自定义导航栏上的返回按钮
导航栏的按钮,右边的按钮是可以自己随意添加的.但左边的返回按钮怎么定制?你会说,添加一个自己的按钮呗!你可以试试看,这样行不行. 正确的答案是重载UINavigationController类的pus ...
- ios之UIActionSheet
UIActionSheet是在IOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件. 为了快速完成这例子,我们打开Xcode 4.3.2, 先建立一个single view applicatio ...
- JS原型链(一)
一.创建对象 // 第一种方式:字面量 var o1 = {name: 'o1'}; var o2 = new Object({name: 'o2'}); // 第二种方式:构造函数 var M = ...
- 【模板】任意模数NTT
题目描述: luogu 题解: 用$fft$水过(什么$ntt$我不知道). 众所周知,$fft$精度低,$ntt$处理范围小. 所以就有了任意模数ntt神奇$fft$! 意思是这样的.比如我要算$F ...