设为首页 收藏本站
查看: 911|回复: 0

[经验分享] TOJ 5021: Exchange Puzzle

[复制链接]

尚未签到

发表于 2017-12-8 16:08:56 | 显示全部楼层 |阅读模式
  5021: Exchange Puzzle DSC0000.gif


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[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<n;i++){
getchar();
char c;int x;
scanf("%c%d",&c,&x);
v[S[c]][((x%7)+7)%7]++;
}
__int64 cnt=0;
for(int i=0;i<7;i++){__int64 B=v[0];
for(int j=0;j<7;j++){int E=v[1][j];
for(int k=0;k<7;k++){int S=v[2][k];
for(int l=0;l<7;l++){int I=v[3][l];
for(int m=0;m<7;m++){int G=v[4][m];
for(int n=0;n<7;n++){int O=v[5][n];
for(int o=0;o<7;o++){int M=v[6][o];
if((i+2*j+2*k+l)*(m+n+j+k)*(o+2*n)%7==0)
cnt+=B*E*S*I*G*O*M;}}}}}}}
printf("%I64d\n",cnt);
return 0;}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-422196-1-1.html 上篇帖子: Bellman_ford 算法 Currency Exchange POJ1860 下篇帖子: Exchange 正版化 授权
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表