题目链接:

DZY Loves Partition

Time Limit: 4000/2000 MS (Java/Others)   

 Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 323    Accepted Submission(s): 127

Problem Description
DZY loves partitioning numbers. He wants to know whether it is possible to partition n into the sum of exactly k distinct positive integers.

After some thinking he finds this problem is Too Simple. So he decides to maximize the product of these k numbers. Can you help him?

The answer may be large. Please output it modulo 109+7.

 
Input
First line contains t denoting the number of testcases.

t testcases follow. Each testcase contains two positive integers n,k in a line.

(1≤t≤50,2≤n,k≤109)

 
Output
For each testcase, if such partition does not exist, please output −1. Otherwise output the maximum product mudulo 109+7.
 
Sample Input
4
3 4
3 2
9 3
666666 2
 
Sample Output
-1
2
24
110888111
 
题意:
 
把n拆成k个互不相同的正整数,并使其乘积最大,问这个乘积最大是多少;
思路:首先判断是否能拆分,能拆分的话把这些平分,并使其成递增的数组,再把n/k剩下的n%k分给剩下的数,k为odd是从最大的数往前n%k个数分别+1;k位even时先把k/2个小点数从大到小分别+1,还有多的话在把剩下的大的k/2个数从大到小+1;最后求得的积就是结果;
 
 
AC代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const long long mod=1e9+;
int t;
long long n,k,a[];
int main()
{ scanf("%d",&t);
while(t--)
{
cin>>n>>k;
long long x=n/k;
if(k*(k+)/>n)
{
printf("-1\n");
}
else
{
if(k%)
{
for(int i=k/;i>;i--)
{
a[i]=x-(k/-i+);
}
for(int i=k/+;i<=k;i++)
{
a[i]=x+(i-k/-);
}
int m=n%k;
for(int i=k;m>;m--,i--)
{
a[i]++;
}
}
else
{
for(int i=k/;i>;i--)
{
a[i]=x-(k/-i+);
}
for(int i=k/+;i<=k;i++)
{
a[i]=x+(i-k/);
}
int m=n%k;
for(int i=k/;i&&m;i--,m--)
{
a[i]++;
}
if(m>)
{
for(int i=k;i>k/&&m;i--,m--)
{
a[i]++;
}
}
}
long long ans=a[];
for(int i=;i<=k;i++)
{
ans*=a[i];
ans%=mod;
}
cout<<ans<<"\n";
} }
return ;
}

hdu-5646 DZY Loves Partition(贪心)的更多相关文章

  1. HDU 5646 DZY Loves Partition 数学 二分

    DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves parti ...

  2. HDU 5646 DZY Loves Partition

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5646 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  3. hdu 5646 DZY Loves Partition 二分+数学分析+递推

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5646 题意:将n分成k个正整数之和,要求k个数全部相同:并且这k个数的乘积最大为多少?结果mod 1e^9 ...

  4. hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  5. hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序

    DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

  6. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  7. HDU 5645 DZY Loves Balls 水题

    DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...

  8. CF447B DZY Loves Strings 贪心

    DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter ...

  9. 数据结构(线段树):HDU 5649 DZY Loves Sorting

    DZY Loves Sorting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

随机推荐

  1. Selenium+Python :WebDriver设计模式( Page Object )

    Page Object 设计原理 Page Object设计模式是Selenium自动化测试项目的最佳设计模式之一,强调测试.逻辑.数据和驱动相互分离. Page Object模式是Selenium中 ...

  2. python之开篇---hello world!

    (1)前沿 (2)python 简介 (3)python hello world 实现 (4) -------------qq:1327706646 ------------------------- ...

  3. getMeasuredHeight(),getScrollY(),getHeight()的区别和联系

    前言:关于控件的高度有两种获取方式,一个是获得控件的实际大小(getMeasuredHeight),就是包含显示部分和已显示的部分: 而getHeight是获得控件的显示的大小,如果控件大小超出的屏幕 ...

  4. python tensorflow 安装

    我是先下载tensorflow-1.5.0rc1-cp36-cp36m-win32.whl,再执行命令行安装的 下载地址:https://pypi.python.org/pypi/tensorflow ...

  5. 让WebRTC支持H264编解码

    近期实验了下怎样让WebRTC支持H264编码.记录下,供有须要的人參考. 说明一下,我是在 Ubuntu Server 14.04 下编译的 WebRTC ,使用 native(C++) api 开 ...

  6. 一篇文章彻底弄清ARC始末

    本文转载至 http://blog.csdn.net/allison162004/article/details/38758265 自动引用计数(ARC)是编译器的一个特色,提供了Objective- ...

  7. Just a Hook(线段树)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. 红米4A手机刷开发版rom并且获取root权限

    1 bl解锁 Critical partition flashing is not allowed就是因为没有bl解锁. 注册小米账号并且关联手机. 下载bl解锁工具 http://www.miui. ...

  9. json.dumps(i['bd_res'], ensure_ascii=False)

    json.dumps(i['bd_res'], ensure_ascii=False) import xlrd import time import sys import os import requ ...

  10. 20179209《Linux内核原理与分析》第十一周作业

    Nmap配合Metasploit进行端口扫描 1.Nmap扫描器基本使用 1.1简介 Nmap(Network Mapper)最早是Linux下的网络扫描嗅探器.其基本功能有三个: 探测一组主机是否在 ...