zoukankan      html  css  js  c++  java
  • HDU 5976 数学

    Detachment

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


    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 ( aiaj when i≠j).
    2.Make this multidimensional space size s as large as possible (s= a1a2*...).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
    思路:拆成连续的数字,剩余的从后往前加在每个数字上。

    代码:

     1 #include<bits/stdc++.h>
     2 //#include<regex>
     3 #define db double
     4 #include<vector>
     5 #define ll long long
     6 #define vec vector<ll>
     7 #define Mt  vector<vec>
     8 #define ci(x) scanf("%d",&x)
     9 #define cd(x) scanf("%lf",&x)
    10 #define cl(x) scanf("%lld",&x)
    11 #define pi(x) printf("%d
    ",x)
    12 #define pd(x) printf("%f
    ",x)
    13 #define pl(x) printf("%lld
    ",x)
    14 #define MP make_pair
    15 #define PB push_back
    16 #define inf 0x3f3f3f3f3f3f3f3f
    17 #define fr(i,a,b) for(int i=a;i<=b;i++)
    18 const int N=1e5+5;
    19 const int mod=1e9+7;
    20 const int MOD=mod-1;
    21 const db  eps=1e-18;
    22 const db  PI=acos(-1.0);
    23 using namespace std;
    24 ll x;
    25 ll F[N],inv[N],Finv[N];
    26 bool cal(ll n){
    27     if((n*n+n-2)/2<=x) return 1;
    28     return 0;
    29 }
    30 
    31 void init(){
    32     inv[1] = 1;
    33     for(int i = 2; i < 45000; i ++){
    34         inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;//单个逆元
    35     }
    36     F[1] = Finv[1] = 1;
    37     for(int i = 2; i < 45000; i ++){
    38         F[i] = F[i-1] * 1ll * i % mod;//阶乘
    39         Finv[i] = Finv[i-1] * 1ll* inv[i] % mod;//逆元阶乘
    40     }
    41 }
    42 int main(){
    43 //freopen("data.in","r",stdin);
    44 //freopen("data.out","w",stdout);
    45     int t;
    46     ci(t);
    47     init();
    48     while(t--)
    49     {
    50         cl(x);
    51         if(x<5) {pl(x);continue;}
    52         ll l=2,r=45000,sum;
    53         while(l<r){
    54             ll mid=l+(r-l+1)/2;
    55             if(cal(mid)) l=mid;
    56             else r=mid-1;
    57         }
    58         ll ans=x-(l*l+l-2)/2;
    59         if(ans==l) sum=F[l+2]*inv[2]%mod*inv[l+1]%mod;
    60         else sum=F[l+1]*Finv[l-ans+1]%mod*F[l-ans]%mod;
    61         pl(sum);
    62     }
    63     return 0;
    64 }
  • 相关阅读:
    阿里云ecs环境配置
    linux下Nginx安装Zend Optimizer组件步骤
    phpcms 按价格、按销量、按时间等排序实现思路
    云服务器 ECS Linux Web 环境配置站点的方法
    CentOS7安装和配置FTP
    Centos7安装SVN
    ExtJs桌面组件(DeskTop)
    jsapi支付,提示redirect_uri 参数错误
    php判断来源网址地址并且限制非法来源
    php正则表达式获取表格内容
  • 原文地址:https://www.cnblogs.com/mj-liylho/p/7625949.html
Copyright © 2011-2022 走看看