HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)
Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 570 Accepted Submission(s): 192Problem DescriptionIn 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)InputThe 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^9OutputMaximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.Sample Input1
4Sample Output4SourceRecommend
题目链接:
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亚洲区大连站)的更多相关文章
- HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)
Convex Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)
http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...
- 2016ACM/ICPC亚洲区大连站-重现赛
题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016ACM%2FICPC%D1%C7%D6%DE%C7%F8%B4%F3%C ...
- 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)(7/10)
1001题意:n个人,给m对敌对关系,X个好人,Y个坏人.现在问你是否每个人都是要么是好人,要么是坏人. 先看看与X,Y个人有联通的人是否有矛盾,没有矛盾的话咋就继续遍历那些不确定的人关系,随便取一个 ...
- HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Relative atomic mass Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
随机推荐
- Swing实现个人简历
源码: import java.awt.Container;import java.awt.FlowLayout;import java.awt.Font; import javax.swing.*; ...
- P1759 通天之潜水(不详细,勿看)(动态规划递推,组合背包,洛谷)
题目链接:点击进入 题目分析: 简单的组合背包模板题,但是递推的同时要刷新这种情况使用了哪些物品 ac代码: #include<bits/stdc++.h> using namespace ...
- git命令初级
git是开源的分布式版本控制系统,分布式主要区别于集中式代表CVS(Concurrent Version System,遵从C/S架构,同步比较笨拙.)和SVN(Subversion),linux开发 ...
- 性能测试培训day2
上节课 性能测试,多线程.协议.场景 实施:1,脚本开发 运行 排错(看回放,然后view-test_results,看业务) 参数化.关联.检查点.事务.思考时间.集合点 参数化:不做参数化的话, ...
- 2017icpc 西安 XOR
XOR Consider an array AAA with n elements . Each of its element is A[i]A[i]A[i] (1≤i≤n)(1 \le i \le ...
- css3 & background & background-image
css3 & background & background-image https://developer.mozilla.org/en-US/docs/Web/CSS/backgr ...
- [luoguP2444] [POI2000]病毒(AC自动机 + dfs)
传送门 先把所有串建一个AC自动机, 如果要找一个不包含任意一个串的串, 说明这个串一直在AC自动机上匹配但匹配不到, 也就是说,匹配时除去val值为1的点,除去fail指针指向val值为1的点,是否 ...
- Thinkphp5.0 的实践一
Thinkphp5.0 的实践一 tp5.0默认没有__SELF__,需要定义, define('__SELF__',strip_tags($_SERVER['REQUEST_URI'])); tp5 ...
- hdu - 2822 Dogs (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2822 给定起点和终点,问从起点到终点需要挖几次只有从# 到 .或者从. 到 . 才需要挖一次. #includ ...
- POJ 3469_Dual Core CPU
题意: N个模块可以在A,B两个核上运行,分别需要A[i]和B[i],模块之间需要传递数据,若两个模块在同一核上,则不需要花费,否则需要花费w[i].问最少需要花费多少? 分析: 用最小的费用将两个对 ...