HDU 5976 Detachment(拆分)

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

 

Problem Description - 题目描述

  In a highly developed alien society, the habitats are almost infinite dimensional space.
  In the history of this planet,there is an old puzzle.
  You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments: a1,a2, … (x= a1+a2+…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space:
    1.Two different small line segments cannot be equal ( ai≠aj when i≠j).
    2.Make this multidimensional space size s as large as possible (s= a1∗a2*...).Note that it allows to keep one dimension.That's to say, the number of ai can be only one.
  Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7)
在一个高度发达的外星文明中,有着近乎无限维度的生存空间。
在这颗星球的历史中,有道古老的谜题。
你有一条长x个单位长度的线段表示一个维度。这条线段可以被拆分为若干小线段:a1,a2, … (x= a1+a2+…)并分配为不同的维度。然后,多维空间就建立起来了。现在,这个空间有两个限制:
.两个不同的小线段不能相等( ai≠aj when i≠j)。
.多维空间的大小s要尽可能大(s= a1∗a2*...)。注意,各维度只能保持一种。也就是说,ai的值必须唯一。
现在的你能解决这个问题并找出最大的空间吗?(结果可能很大,输出模10^+)

CN

Input - 输入
  The first line is an integer T,meaning the number of test cases.
  Then T lines follow. Each line contains one integer x.
  1≤T≤10^6, 1≤x≤10^9
第一行为一个整数T,描述测试用例的数量。
随后T行。每行有一个整数x。
≤T≤^, ≤x≤^

CN

Output - 输出

  Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.
s的最大值需要模10^+。注意,模10^+7是在获得最大乘积后。

CN

Sample Input - 输入样例

1
4

Sample Output - 输出样例

4

题解
  先猜一发最优策略:2+3+4+5+6+……

  然后再猜一发对于剩下数的分配策略:每次从后往前,对每个数+1。

  接着就发现似乎策略就是这样了。

  后面需要做的处理:求前n项和,求前n项积。

  最后遇到(a % mod)/(b % mod)的时候需要用逆元。

  把(a/b)%mod转化为(a * inv b)%mod 不嫌弃速度的话可以用费马小定理:

    mod为质数时,inv a = a^(mod - 2)

  或者用其他方法…………

代码 C++

 #include <cstdio>
#include <algorithm>
#define mod 1000000007
#define mx 44722
__int64 mul[mx] = { }, sum[mx];
__int64 qMod(__int64 a, int n){
__int64 opt = ;
while (n){
if (n & ) opt = (opt*a) % mod;
n >>= ;
a = (a*a) % mod;
}
return opt;
}
__int64 lr(int l, int r){//[l, r]
return (mul[r] * qMod(mul[l - ], mod - )) % mod;
}
void rdy(){
int i, j;
for (i = , j = ; i < mx; ++i, ++j){
sum[i] = j + sum[i - ];
mul[i] = (j * mul[i - ]) % mod;
}
}
int main(){
rdy();
int t, len, w, l, r;
__int64 x, opt;
scanf("%d", &t);
while (t--){
scanf("%I64d", &x);
if (x < ) opt = x;
else{
len = std::upper_bound(sum, sum + mx, x) - sum - ;
r = len + (x - sum[len]) / len;
w = (x - sum[len]) % len;
opt = lr(r - len + , r - w);
if (w) opt *= lr(r + - w, r + ), opt %= mod;
}
printf("%I64d\n", opt);
}
return ;
}

HDU 5976 Detachment(拆分)的更多相关文章

  1. HDU 5976 Detachment 打表找规律

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5976 Detachment Time Limit: 4000/2000 MS (Java/Other ...

  2. HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)

    Detachment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. hdu 5976 Detachment

    Detachment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. hdu 5976 Detachment 脑洞题 猜结论

    题目链接 题意 将\(x\)拆成\(a_1+a_2+...+\)的形式,且\(a_1\lt a_2\lt...\),使得\(a_1*a_2*...\)取到最大值 思路 大胆猜结论. 首先拆分的形式中肯 ...

  5. HDU - 5976 Detachment(逆元)

    题意:将一个数x拆成a1+a2+a3+……,ai不等于aj,求最大的a1*a2*a3*……. 分析: 1.预处理前缀和前缀积,因为拆成1对乘积没有贡献,所以从2开始拆起. 2.找到一个id,使得2+3 ...

  6. HDU 5976 数学,逆元

    1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...

  7. HDU 1028(数字拆分 分治)

    题意是求所给的数能够被拆分成的不同组合数目. 方法有三种: 一.完全背包. 限制条件:所用数字不大于 n. 目标:求分解种数(组合出 n 的方法数). 令 dp[ i ][ j ] = x 表示 用前 ...

  8. HDU 5976 数学

    Detachment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  9. HDU 1028 整数拆分 HDU 2082 找单词 母函数

    生成函数(母函数) 母函数又称生成函数.定义是给出序列:a0,a1,a2,...ak,...an, 那么函数G(x)=a0+a1*x+a2*x2+....+ak*xk +...+an* xn  称为序 ...

随机推荐

  1. django 常用方法总结 < 手写分页-上传头像-redis缓存,排行 ...>

    1.不使用自带模块<Paginator>的手写分页功能views.pydef post_list(request): page = request.GET.get('page', 1) # ...

  2. mybatis源码解析4---Configuration解析

    Configuration类解析 Configuration类位于mybatis包的org.apache.ibatis.session目录下,是mybatis的全局变量,属性就是对应于mybatis的 ...

  3. linux下卸载mysql(rpm)

    linux下卸载mysql 查看是否安装了mysql的组件 rpm –qa |grep –I mysql 卸载前关闭mysql服务 service mysql status service mysql ...

  4. [转载] Oracle之内存结构(SGA、PGA)

    2011-05-10 14:57:53 分类: Linux 一.内存结构 SGA(System Global Area):由所有服务进程和后台进程共享: PGA(Program Global Area ...

  5. linux /etc/shadow--passwd/pam.d/system-auth文件详解

     在linux操作系统中, /etc/passwd文件中的每个用户都有一个对应的记录行,记录着这个用户的一下基本属性.该文件对所有用户可读.   而/etc/shadow文件正如他的名字一样,他是pa ...

  6. 现代汽车加入Linux 基金会和 AGL协作平台

    1月4日,现代汽车宣布已加入 Linux 基金会和其旗下的非营利协作平台 Automotive Grade Linux(AGL),现代汽车公司副总裁兼信息娱乐技术中心负责人 Paul Choo 表示: ...

  7. eclipse的svn插件添加代理访问svn

    1.首先找到插件配置文件 C:\Users\Administrator\AppData\Roaming\Subversion这个目录下的servers文件 打开找到 # http-proxy-host ...

  8. Java Thread.yield详解

    这是Java中的一种线程让步方法,让Java中的线程从执行状态变成就绪状态,然后处理器再从就绪队列中挑选线程进行执行(优先级大的,被挑选的概率较大),这种转换也不确定,让或者不让都是取决与处理器,线程 ...

  9. django 表单常用field

    BooleanField字段:相当于单选框 CharField:接受字符串 参数:max_length最大长度,min_length最小长度 require字段是否是必须的,默认为required=T ...

  10. Vue基础进阶 之 计算属性的使用

    计算属性的基本使用 初始小示例: 代码: window.onload = () =>{ new Vue({ el:'div', data:{ msg:'' } }) } </script& ...