Detachment

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 392    Accepted Submission(s):
131

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)

 
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
 
Output
Maximum s you can get modulo 10^9+7. Note that we wants
to be greatest product before modulo 10^9+7.
 
Sample Input
1
4
 
Sample Output
4
 
Source
 
题意:有一个数字n,将它拆分成m个数,这m个数相加等于n,且这m个数各不相同  问怎样拆分使得这m个数的乘积最大,输出这个最大的乘积值
将n拆成 2 3 4 5 6 7 8 9 .........l +r 这样的形式,这样可以保证m的个数尽量多,因为m的个数多的话,得到的乘积明显大,现在就是这个r的值,倘若r刚好为0,
则n无多余,则这个乘积一定最大,如果r>0的话
我们只需要通过x+r=l+1 找到x 理由如下
2  3  4  5       1
如果把1加到小的值上 乘积是最大的,3*3*4*5=180;
当加到最大的数上的话  2*3*4*6=144
证明省略 
做一个预处理,求前缀和,和累积
以下有一个有关逆元的 
利用
inv[1]=1;
for(i=2;i<=n;i++)
inv[i]=(mod-mod/i)*inv[mod%i]%mod;求出每个数的逆元

2 3 4 5 6 7 8 9 ......l  +r
b[i]=(b[i-1]*i)%mod;
比如2+r>l
结果只需要ans=b[l]*inv[2]*(2+r);
因为2在做累积进行了取模运算 所以不能直接除2,要乘以她的逆元
 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string.h>
#include<map>
#define INF 1000000000
#define LETTER 26
#define SIZE 45000
#define pi 3.14159265358979
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const long long mod=INF+;
int a[SIZE],inv[SIZE];
ll b[SIZE];
int low,high,mid;
void f(){
a[]=;
b[]=;
inv[]=;
for(int i=;i<=SIZE;i++){
a[i]=a[i-]+i;
b[i]=(b[i-]*i)%mod;
inv[i]=(mod-mod/i)*inv[mod%i]%mod; }
}
void erfen(int n){
low=,high=SIZE;
while(low+<high){
mid=(low+high)>>;
if(n>=a[mid]) low=mid;
else high=mid;
}
}
int main(){
int i,j,k;
int t;
int n;
f();
ll ans;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
if(n<=){cout<<n<<endl;continue;}
erfen(n);
int l=low,r=n-a[l];
if(+r>l){
ans=b[l]*inv[]%mod*(+r)%mod;
}
else{
k=l+-r;
ans=b[l]*inv[k]%mod*(l+)%mod;
}
printf("%lld\n",(ans+mod)%mod); } }

hdu 5976 Detachment的更多相关文章

  1. HDU 5976 Detachment(拆分)

    HDU 5976 Detachment(拆分) 00 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem D ...

  2. HDU 5976 Detachment 打表找规律

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

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

    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 5976 数学

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

  8. hdu5976贪心乘法逆元

    hdu 5976 Detachment题目连接 题意: 给定一个自然数x,让你给出一种拆分方式n=a1+a2+...(ai≠aj),使得每个小部分的乘积s=a1*a2*...最大 解题思路: 我们要乘 ...

  9. 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)

    http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...

随机推荐

  1. python之路-Day6

    time & datetime模块 #_*_coding:utf-8_*_ __author__ = 'Alex Li' import time # print(time.clock()) # ...

  2. VS使用过程中,编写JS没有智能提示解决方法

    问题:编写基本Script代码没有问题,但是在编写DOM代码时候没有智能提示.也就是在编写一般javascript代码时候没有问题,但是要写DOM代码的时候发现没有智能提示,如document等都需要 ...

  3. eclipse导入PIL报错

    有些模块,比如PIL,已经装入过,但是在pydev中无法自动提示,甚至有报 unresolved import的问题,虽然不会引起运行时问题,但是无法实现自动提示,还是一件很麻烦的事情. 下面有个解决 ...

  4. LeetCode之Largest Rectangle in Histogram浅析

    首先上题目 Given n non-negative integers representing the histogram's bar height where the width of each ...

  5. JavaScript Dom基础

    一.DOM查找 1.document.getElementById("id") -功能:返回对拥有指定ID的第一个对象的引用 -返回值:DOM对象 -说明:id为DOM元素上id属 ...

  6. POJ1236 network of schools

    100个学校,有单向网络连接,从而分享软件. 问题一:几个学校得到软件就可使所有学校都得到? 问题二:再加几条单向网络可以使得"任意学校得到软件,就可使得所有学校都有软件"? -- ...

  7. AJAX请求 $.post方法的使用

    使用jQuery的$.post方法可以以POST形式向服务器发起AJAX请求.$.post方法是jQuery的实用工具方法. $.post方法语法 $.post(url,parameters,call ...

  8. C/C++ 记录时间

    http://stackoverflow.com/questions/2808398/easily-measure-elapsed-time https://github.com/picanumber ...

  9. eclipse- Web-app verson=2.5 调整将Dynamic Web Module3.0降为2.5

    如果提示cannot change version of project facet Dynamic Web Module to 2.5 1.把Dynamic Web Module复选框,勾选去掉,点 ...

  10. sql server 分页存储过程

    ----------------------分页存储过程------------------------------------------------------------------------ ...