BestCoder Round #76 (div.2)-DZY Loves Partition(模拟)
来源:互联网 发布:苹果2017秋季发布会mac 编辑:程序博客网 时间:2024/04/30 17:25
DZY Loves Partition
Accepts: 154
Submissions: 843
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 262144/262144 K (Java/Others)
问题描述
DZY喜欢拆分数字。他想知道能否把nnn拆成恰好kkk个不重复的正整数之和。思考了一会儿之后他发现这个题太简单,于是他想要最大化这kkk个正整数的乘积。你能帮帮他吗?由于答案可能很大,请模109+710^9+7109+7输出。
输入描述
第一行ttt,表示有ttt组数据。接下来ttt组数据。每组数据包含一行两个正整数n,kn,kn,k。(1≤t≤50,2≤n,k≤1091\le t\le 50, 2\le n,k \le 10^91≤t≤50,2≤n,k≤109)
输出描述
对于每个数据,如果不存在拆分方案,输出−1-1−1;否则输出最大乘积模109+710^9 + 7109+7之后的值。
输入样例
43 43 29 3666666 2
输出样例
-1224110888111
Hint
第一组数据没有合法拆分方案。第二组数据方案为3=1+23=1+23=1+2,答案为1×2=21\times 2 = 21×2=2第三组数据方案为9=2+3+49=2+3+49=2+3+4,答案为2×3×4=242\times 3 \times 4 = 242×3×4=24。注意9=3+3+39=3+3+39=3+3+3是不合法的拆分方案,因为其中包含了重复数字。第四组数据方案为666666=333332+333334666666=333332+333334666666=333332+333334,答案为333332×333334=111110888888333332\times 333334= 111110888888333332×333334=111110888888。注意要对109+710^9 + 7109+7取模后输出,即110888111110888111110888111。
AC代码:
#include<iostream>#include<functional>#include<algorithm>#include<cstring>#include<string>#include<vector>#include<cstdio>#include<queue>#include<cmath>#include<map>#include<set>using namespace std;#define CRL(a) memset(a,0,sizeof(a))#define QWQ ios::sync_with_stdio(0)#define inf 0x3f3f3f3ftypedef unsigned long long LL;typedef long long ll;const int T = 500000+50;const int mod = 1000000007;ll a[200055];int main(){#ifdef zsc freopen("input.txt","r",stdin);#endifint N,n,m,i,j,k,u,v;scanf("%d",&N);while(N--){scanf("%d%d",&n,&m);ll sum = 1LL*m*(m+1)/2;//以1为起点在[1,m]范围内的和if(sum>n){//不能构成m个数printf("-1\n");continue;}int x = (n-m*(m-1)/2)/m;//还能平均分多少值给m个数int y = (n-m*(m-1)/2)%m;//剩余了小于m的数for(i=0;i<m;++i){//给m个数赋值a[i] = x+i;}for(i=m-1;i>=m-y;--i)a[i]++;//将剩余的数给结尾ll ans = 1;for(i=0;i<m;++i)ans =(ans*a[i])%mod;printf("%lld\n",ans);} return 0;}
0 0
- BestCoder Round #76 (div.2)-DZY Loves Partition(模拟)
- 【BestCoder Round #76 (div.2)】DZY Loves Partition(数学分析)
- BestCoder Round #76 (div.2) DZY Loves Balls
- 【BestCoder Round #76 (div.2)】HDU5646DZY Loves Partition
- Codeforces Round #FF (Div. 2) 447A - DZY Loves Hash(模拟)
- 【HDU5646 BestCoder Round 76 (div1)A】【贪心】DZY Loves Partition n个数拆分k个最大乘积
- 【BestCoder Round #76 (div.2)】HDU5646DZY Loves Balls
- CA Loves Stick(BestCoder Round #78 (div.2))
- [Codeforces] Round #254 (Div. 2) B. DZY Loves Chemistry
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard
- Codeforces Round #254 (Div. 2)B. DZY Loves Chemistry
- Codeforces Round #254 (Div. 2):A. DZY Loves Chessboard
- Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard
- Codeforces Round #254 (Div. 2)B. DZY Loves Chemistry
- Codeforces Round #254 (Div. 2) B DZY Loves Chemistry
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard
- 经典算法——扑克牌的顺子
- 软硬件调试九法:第一条规则,理解系统
- Android的消息机制学习(一)Looper,Handler,MessageQueue
- [React Native 笔记]几个命令行工具作用备忘
- Android 进程常驻(2)----细数利用android系统机制的保活手段
- BestCoder Round #76 (div.2)-DZY Loves Partition(模拟)
- Paint Fence 栅栏涂色
- Git分享(二)—代码冲突解决和分支应用
- 软硬件调试九法:第二条规则,重现失败
- ubantu(Linux) 系統如何安裝AdobeFlash
- LeetCode-74-Search a 2D Matrix(二分查找)-Medium
- visual SVN安装及使用方法
- 机器学习:线性判别分析LDA
- 剑指offer:和为S的两个数字