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. xml 的 <![CDATA["URL"]]>

    <![CDATA["URL"]]>:用于 xml 处理特殊字符,比如:& <PolicyURL><![CDATA[ http://ectp.t ...

  2. spring部分注解

    @Controller @SpringBootApplication @Configuration @ComponentScan(basePackages={"first",&qu ...

  3. MongoDB-Java的两个基本操作Upsert和insertMany

    此文只是为了记录几个基本操作,首先Upsert,有多种方法可以进行,但是都需要指定UpdateOptions.upsert(true),其中最简单的办法如下(eqq是一个用来filter的BSON,具 ...

  4. 细数那些不懂Spring底层原理带来的伤与痛

    1. 什么是spring? Spring 是个Java企业级应用的开源开发框架.Spring主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用.Spring 框架目标是简化Jav ...

  5. GROUP BY 和 ORDER BY 同时使用问题

    GROUP BY 和 ORDER BY一起使用时,ORDER BY要在GROUP BY的后面.

  6. Eloquent JavaScript #08# Bugs and Errors

    索引 Notes strict mode js类型 js测试 Debugging Exceptions finally 异常分支 Exercise Retry The locked box Notes ...

  7. HTML5 canvas游戏工作原理

    HTML5已经不是一个新名词.它看上去很cool,有很多feature,大多数人普遍看好它的发展.对于我来说,最感兴趣的是它的canvas标签,可以结合Javascript来绘制游戏画面. 我们可以在 ...

  8. shell脚本一键安装redis集群

    简介: 明天再写,上脚本 #!/bin/bash #-------------------------------------------------------------------------- ...

  9. maven的使用记录

    maven的使用记录 使用的版本为3.6.0. maven配置部署项目 在cmd命令行中切换到Maven项目的根目录,比如:D:/xxxwork/java/maven-test,然后执行命令:$ mv ...

  10. 单片机中printf函数的重映射

    单片机中printf函数的重映射 一.源自于:大侠有话说 1.如果你在学习单片机之前学过C语言,那么一定知道printf这个函数.它最最好用的功能 除了打印你想要的字符到屏幕上外,还能把数字进行格式化 ...