HDU 5976 Detachment 貪心(2016ACM/ICPC亞洲區大連站)__題解

來源:互聯網
上載者:User

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 2016ACM/ICPC亞洲區大連站-重現賽(感謝大連海事大學)  
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 45004using 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=1;while(y){if(y&1)z=(z*x)%mod;x=(x*x)%mod;y>>=1;}return z;}void init(){int i;a[1]=1;ni[1]=1;for(i=2;i<N;i++){a[i]=(a[i-1]*i)%mod;ni[i]=(-(mod/i)*a[mod%i])%mod;}}int main(){#ifndef ONLINE_JUDGEfreopen("1.txt","r",stdin);//freopen("2.txt","w",stdout);#endifint 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<5){printf("%d\n",n);continue;}m=n+n+2;LL l,r,mid;l=2;r=45000;while(l<r){mid=(l+r+1)>>1;if(mid*mid+mid<=m)l=mid;else r=mid-1;}m-=l*l+l;m/=2;if(m==l){aans=a[l]*(l+2)%mod*mi(2,mod-2)%mod;}else{x=l+1-m;aans=a[l+1]*mi(x,mod-2)%mod;}printf("%lld\n",aans);}return 0;}/*////*/


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.