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 使用相同的 ...
随机推荐
- jdk下载安装配置环境变量
因为学习原因要用到一些工具,jdk12的版本与那个工具不兼容,所以这里推荐使用的是jdk1.8的版本, 不知道是电脑原因还是啥原因,jdk 12的版本用不了配不好环境变量. 首先可以在官网下载jdk1 ...
- 关于php和docker
Docker在PHP项目开发环境中的应用 http://www.wolonge.com/zhuanlan/detail/117441 Docker在PHP项目开发环境中的应用 http://linux ...
- JS权威指南-概述学习
<script src="/javascripts/application.js" type="text/javascript" charset=&quo ...
- POJ 1998 Cube Stacking
Description Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes ...
- 玄学C语言之scanf,printf
#include <bits/stdc++.h> using namespace std; int main() { int a,c,d; ]; scanf("%d." ...
- 贴一发STL源码
int my_lower_bound(int size, long long key){ int first = 0, middle; int half, len; len = si ...
- hydra 中文文档
hydra(九头蛇)是一款开源的协议爆破工具,功能十分强大!!! 具体使用如下: -R 继续从上一次进度接着破解 -I 忽略已破解的文件进行破解 -S 采用SSL链接 -s 端口 指定非默认服务端 ...
- 由DAG到背包问题——记忆化搜索和递推两种解法
一.问题描述 物品无限的背包问题:有n种物品,每种均有无穷多个.第 i 种物品的体积为Vi,重量为Wi.选一些物品装到一个容量为 C 的背包中,求使得背包内物品总体积不超过C的前提下重量的最大值.1≤ ...
- 基于Python的Web应用开发实战——2 程序的基本结构
2.1 初始化 所有Flaks程序都必须创建一个程序实例. Web服务器使用一种名为Web服务器网关接口(Web Server Gateway Interface,WSGI)的协议,把接收自客户端的所 ...
- 背包问题2 (lintcode)
这里: for(int j = 1;j <= m;j++) result[0][j] = 0x80000000; 不能从0开始,result[0][0]是可以取到的,是0.其他情况取不到才用最小 ...