博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TOJ 5021: Exchange Puzzle
阅读量:7193 次
发布时间:2019-06-29

本文共 1570 字,大约阅读时间需要 5 分钟。

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

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

#include
int S[128],v[10][10];int main(){int n;S['B']=0,S['E']=1,S['S']=2,S['I']=3,S['G']=4,S['O']=5,S['M']=6;scanf("%d",&n);for(int i=0;i

 

转载于:https://www.cnblogs.com/BobHuang/p/7283475.html

你可能感兴趣的文章
js performance
查看>>
〖Linux〗zigbee实验之cc2430的cc debugger固件升级实录
查看>>
数组前半部分和后半部分有序的全排序
查看>>
动态规划法的一般方法
查看>>
在 Xen 虚拟机下修改系统当前时间
查看>>
Spider Studio 数据挖掘集成开发环境
查看>>
<<.NET B/S 架构实践>> 几种概念区别 - 算法、设计模式、企业应用架构模式、架构模式...
查看>>
SilverLight自定义ImageButton
查看>>
关于PHP写的投票网站之刷票终结版
查看>>
使用ActivityGroup来切换Activity和Layout
查看>>
网上收集的网页清理浮动方法大全及经验总结
查看>>
微信支付
查看>>
【ipython技巧】使用shell命令
查看>>
nginx / apache / tomcat /resin等 http server的benchmark性能测试方法
查看>>
CImageList类Create函数参数解析
查看>>
Java中类的设计技巧
查看>>
每日英语:Why Mom's Time Is Different From Dad's Time
查看>>
RegisterStartupScript和RegisterClientScriptBlock区别
查看>>
每日英语:Foreign Tourists Skip Beijing
查看>>
easyui扩展
查看>>