Detachment

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

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
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  6010 6009 6008 6007 6006 
 

Statistic | Submit | Discuss | Note

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5976

题目大意:

  给一个数N(N<=109),让你把它拆成若干各不相同的数Ai,ΣAi=N,要求ΠAi(累乘)最大。

题目思路:

  【贪心】

  首先肯定要把位数拆的尽量多,手写了20以内的拆法。

  发现以2为首相的递增序列累乘最大,所以我的想法就是把N拆成2+3+...+x<=n,

  先找到x,之后算一下n还多了多少,就把后面依次+1,变成2+3+...+y+(y+2)+(y+3)+...+(x+1)。

  这时候它们的累乘是最大的。

  (特殊情况是从2到x都加1之后还剩余1,这时候把最后一项再加1,变成3+4+...+x+(x+2)

 //
//by coolxxx
/*
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
//#include<stdbool.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
*/
#include<bits/stdc++.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 45004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
LL a[N],ni[N];
LL mi(LL x,LL y)
{
LL z=;
while(y)
{
if(y&)z=(z*x)%mod;
x=(x*x)%mod;
y>>=;
}
return z;
}
void init()
{
int i;
a[]=;
ni[]=;
for(i=;i<N;i++)
{
a[i]=(a[i-]*i)%mod;
ni[i]=(-(mod/i)*a[mod%i])%mod;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
init();
for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
scanf("%d",&n);
if(n<)
{
printf("%d\n",n);
continue;
}
m=n+n+;
LL l,r,mid;
l=;r=;
while(l<r)
{
mid=(l+r+)>>;
if(mid*mid+mid<=m)l=mid;
else r=mid-;
}
m-=l*l+l;
m/=;
if(m==l)
{
aans=a[l]*(l+)%mod*mi(,mod-)%mod;
}
else
{
x=l+-m;
aans=a[l+]*mi(x,mod-)%mod;
}
printf("%lld\n",aans);
}
return ;
}
/*
// //
*/

HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)的更多相关文章

  1. HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)

    Convex Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

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

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

  3. 2016ACM/ICPC亚洲区大连站-重现赛

    题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016ACM%2FICPC%D1%C7%D6%DE%C7%F8%B4%F3%C ...

  4. 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)(7/10)

    1001题意:n个人,给m对敌对关系,X个好人,Y个坏人.现在问你是否每个人都是要么是好人,要么是坏人. 先看看与X,Y个人有联通的人是否有矛盾,没有矛盾的话咋就继续遍历那些不确定的人关系,随便取一个 ...

  5. HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  6. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Relative atomic mass Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    Rabbits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

随机推荐

  1. js 随机生成颜色

    方法一  function randomColor (){ var str='#'; for(var i=0;i<6;i++){ str+=Math.floor(Math.random()*16 ...

  2. Linux下启动tomcat报java.lang.OutOfMemoryError: PermGen space

    一.错误信息 java.lang.reflect.InvocationTargetException    at sun.reflect.NativeMethodAccessorImpl.invoke ...

  3. 对 Spring IoC 的理解

    理解 “ 控制反转(IoC)” 控制反转(IoC):用白话来讲,就是由 Spring 容器控制程序中类与类之间的关系,而非传统实现中,由程序代码直接操控.这也就是所谓 “控制反转” 的概念所在:控制权 ...

  4. Linux忘记root密码,密码找回,图片展示

    忘记root密码 CentOS 7参考地址如下:https://www.baidu.com/s?wd=CentOS7+%E6%89%BE%E5%9B%9Eroot%E5%AF%86%E7%A0%81& ...

  5. 编译Nginx, 并使用自签证书实现https访问

    1. 编译安装nginx1.8.1 [root@centos7 nginx-1.8.1]# ./configure --prefix=/usr/local/nginx.1.8.1 --with-htt ...

  6. 创建Javaweb项目及MyEclipse视图的配置

    在myEclipse里--右键new--Web Project 视图的配置--Window--Show View-Other在里面输入要找的视图例如(servers)或者直接 Window--rese ...

  7. bzoj 1005 [HNOI2008] 明明的烦恼 (prufer编码)

    [HNOI2008]明明的烦恼 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 5907  Solved: 2305[Submit][Status][Di ...

  8. poj 1752 Advertisement (差分约束)

    题目大意:题目大意:有n个人在一条路上跑步,广告商准备在这条路上设置广告牌,假设这条路上每一个点有一个广告牌 现在已知这n个人从Ai开始跑,到Bi结束,那么他可以看到max(Ai,Bi)-min(Ai ...

  9. memcache 原理 & 监测 & 查看状态 & stats & 结构

    Mencache内存存储方式:slab/LRU,采用预先申请固定大小的内存页(slab/page),然后再把内存分成多个块(chunk) 先放一张从网上找到的memcache内存结构图,觉得非常的赞:

  10. hdu - 1394 Minimum Inversion Number(线段树水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...