Fantasy of a Summation(找规律,水)
来源:互联网 发布:java什么叫缺省 编辑:程序博客网 时间:2024/05/29 19:28
题目来源:https://vjudge.net/problem/LightOJ-1213
【题意】
根据题面上的代码可以得知题意,他的意思就是让求一个类似于深搜的一个简单模拟,反正,,举个例子(语言能力表达不强)。。。
第二组样例: 2 3 32000,数组是1 2,那么题意的意思就是
1+1+1
1+1+2
1+2+1
1+2+2
2+1+1
2+1+2
2+2+1
2+2+2,然后把这些全部加起来,取余32000,得出结果。
【思路】
模拟一遍第二组样例就知道,一共有n^k个排列,每个排列k个数,并且通过数1,2的个数可以发现,数组里每个数出现的次数是一样的,所以我们可以先求一共出现了多少个数:n^k*k,然后呢,每个数出现的次数是一样的,所以:n^k*k/n,这是每个数出现的次数,那么直接快速幂就可以了。
【代码】
#include<set>#include<map>#include<stack>#include<cmath>#include<queue>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;const int INF=1e9;typedef unsigned long long ll;typedef long long LL;int a[1010];int n,k,mod;int quick_pow(int a,int b){ int ans=1,base=a; while(b!=0) { if(b&1) { ans=ans%mod*base%mod; } base=base%mod*base%mod; b>>=1; } return ans;}int main(){ int T,cases=1; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&k,&mod); int pow=quick_pow(n,k-1); LL sum=0; for(int i=0;i<n;i++) { scanf("%d",&a[i]); sum+=a[i]; } int ans=sum%mod*pow%mod*k%mod; printf("Case %d: %d\n",cases++,ans); }}
阅读全文
0 0
- Fantasy of a Summation(找规律,水)
- Fantasy of a Summation
- Fantasy of a Summation
- Light OJ 1213 Fantasy of a Summation (快速幂+规律)
- lightoj1213 - Fantasy of a Summation
- LightOJ1213 Fantasy of a Summation
- poj1213Fantasy of a Summation(找规律,优化代码)
- LightOj 1220 Fantasy of a Summation(快速幂)
- light oj 1213 - Fantasy of a Summation (数学计数)
- lightOJ 1213 Fantasy of a Summation
- LightOJ 1213 Fantasy of a Summation
- 【Light】[1213]Fantasy of a Summation
- LightOJ 1213 Fantasy of a Summation
- light oj 1220 Fantasy of a Summation
- LightOJ 1213 - Fantasy of a Summation (排列组合+快速幂)
- lightoj 1213 - Fantasy of a Summation 【数学计数】
- LightOJ 1213 Fantasy of a Summation(快速幂)
- ACM_1007_Numerical Summation of a Series
- go语言的性能测试脚本
- Spring实战4之缓存篇
- 如何清除Win7中被占用的COM口 串口
- ActiveMQ从入门到精通(三)
- JavaScript的onchange 事件
- Fantasy of a Summation(找规律,水)
- 面试失败流的泪往往是写简历时脑袋进的水
- 玩转Redis集群(上)
- Java中构造函数执行顺序的问题
- MFC实现选择文件夹的对话框
- 执行spring boot jar包
- 对ThreadLocal的源码解读
- [RK3288][Android6.0] 调试笔记 --- 播放搜狐视频会Crash问题
- 浅谈Java web 中request的setAttribute()用法