HDU 5976 Detachment 打表找规律
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5976
Detachment
Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)
#### 问题描述
> 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)
#### 输入
> 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
#### 输出
> Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.
####样例输入
> 1
> 4
样例输出
4
题意
给你一个数n,求把它拆分成若干个数的和,使得这些数的乘积最大。
题解
打表找了下规律:
2
阶段1(3~4)
2 3
阶段2(6~8)
2 3 4
阶段3(10~13)
2 3 4 5
...
处理下阶乘和阶乘的逆,二分找下n属于哪个阶段,然后把区间里面的阶乘拆两部分求就可以了(求x*(x+1)...y利用前缀和思想)。
代码
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
//#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-6;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
const int maxn=1e5+10;
const int mod=1e9+7;
LL fac[maxn],invfac[maxn],inv[maxn];
void pre(){
fac[0]=fac[1]=1;
invfac[0]=invfac[1]=1;
inv[1]=1;
for(int i=2;i<maxn;i++){
fac[i]=fac[i-1]*i%mod;
inv[i]=(mod-mod/i)*inv[mod%i]%mod;
invfac[i]=invfac[i-1]*inv[i]%mod;
}
}
int n;
inline LL f(LL x){
return (x+1)*x/2-1;
}
int main() {
pre();
int tc;
scf("%d",&tc);
while(tc--){
scf("%d",&n);
if(n<=4){
prf("%d\n",n);
continue;
}
int l=2,r=100000;
while(l+1<r){
int mid=l+(r-l)/2;
if(f(mid)<=n) l=mid;
else r=mid;
}
int len=l-1;
LL ans=1;
if(f(l+1)-n==1){
ans=fac[3+len-2]*invfac[2]%mod;
ans=ans*fac[l+2]%mod*invfac[l+1]%mod;
}else{
int d=n-f(l);
ans=fac[l+1]*invfac[l+1-d]%mod;
ans=ans*fac[l-d]%mod;
}
prf("%lld\n",ans);
}
return 0;
}
//end-----------------------------------------------------------------------
HDU 5976 Detachment 打表找规律的更多相关文章
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- hdu 3032 sg打表找规律 *
有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- HDU 4731 Minimum palindrome 打表找规律
http://acm.hdu.edu.cn/showproblem.php?pid=4731 就做了两道...也就这题还能发博客了...虽然也是水题 先暴力DFS打表找规律...发现4个一组循环节.. ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- hdu 3032 Nim or not Nim? (sg函数打表找规律)
题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆 Alice先取,问谁能获胜 思路:首先观察这道题的数据范围 1 ≤ N ...
- HDU 3032 (SG打表找规律)
题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围 ...
随机推荐
- DW Basic Knowledge2
DW的元数据是指除去数据本身之外的所有信息. 围绕DBMS方面的元数据可以描述为表定义,分区设置,索引视图定义,以及DBMS级安全方面的特权 与授权等内容. 在任何场合下,ODS要么是一个处在OLTP ...
- 使用selenium实现右键另存为保存文件
1.需要借住autoit工具和Robot类,下载地址:https://www.autoitscript.com/site/autoit/downloads/ 2.autoit的使用不再详细讲解.如下图 ...
- 【温故而知新-Javascript】时间效果(显示当前时间、显示当前日期、显示页面停留时间、倒计时)
1.显示当前时间 <body onload="showtime()"> <div>当前时间: <span id="clock"&g ...
- jquery 地址栏链接与a标签链接匹配 特效代码总结(二)
如题所述,当出现这样的功能,点击某个链接后,给跳转后的该链接地址添加样式,通过添加class为current来增加特殊样式. 如图所示:点击HTML+css3跳转后,给其添加如图样式: js代码如下: ...
- ehcache 一二事 - ssm 中ehcashe的简单配置应用
Ehcache是一个开源Java分布式缓存.可以配合mybatis来使用 首先,在资源文件夹中新建ehcache.xml 内容如下: <?xml version="1.0&qu ...
- 贴图在Unity中的设置
例如:一张512X512的图片占用的内存大小,计算方法:512*512*4/1024=1.024MB. 如果在贴图设置里设置成真彩色那就等于计算的值,设置成16位色彩,内存占用会减少. 在进行性能优化 ...
- [转] Centos 6.4 python 2.6 升级到 2.7
http://blog.csdn.net/jcjc918/article/details/11022345
- Android service ( 二) 远程服务
通常每个应用程序都在它自己的进程内运行,但有时需要在进程间传递对象,你可以通过应用程序UI的方式写个运行在一个不同的进程中的service.在android平台中,一个进程通常不能访问其他进程中的内存 ...
- 3d照片环效果(修改版--添加了x轴y轴双向转动和修复模糊度的bug)
今天用用前两天总结的css3新效果写了一个3d照片环的效果,其中还有些bug大家可以看一看,一起改进. <!DOCTYPE html> <html lang="en&quo ...
- usb驱动开发9之设备描述符
前面分析了usb的四大描述符之端点描述符,接口描述符(每一个接口对应一个功能,与之配备相应驱动),配置描述符,最后分析设备如何包括这些描述符.首先记住,在usb的世界里,设备大于配置,配置大于接口,接 ...