zoukankan      html  css  js  c++  java
  • N分成不同的数相乘使答案最大

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

    首先队友想出了分的越多答案越多。

    我们就:2,3,4,5,6.。。多出来的尽量往小了加就行了。

      1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
      2 #include <cstdio>//sprintf islower isupper
      3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
      4 #include <iostream>//pair
      5 #include <fstream>//freopen("C:\Users\13606\Desktop\草稿.txt","r",stdin);
      6 #include <bitset>
      7 //#include <map>
      8 //#include<unordered_map>
      9 #include <vector>
     10 #include <stack>
     11 #include <set>
     12 #include <string.h>//strstr substr
     13 #include <string>
     14 #include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
     15 #include <cmath>
     16 #include <deque>
     17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
     18 #include <vector>//emplace_back
     19 //#include <math.h>
     20 #include <cassert>
     21 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
     22 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
     23 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
     24 //******************
     25 int abss(int a);
     26 int lowbit(int n);
     27 int Del_bit_1(int n);
     28 int maxx(int a,int b);
     29 int minn(int a,int b);
     30 double fabss(double a);
     31 void swapp(int &a,int &b);
     32 clock_t __STRAT,__END;
     33 double __TOTALTIME;
     34 void _MS(){__STRAT=clock();}
     35 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
     36 //***********************
     37 #define rint register int
     38 #define fo(a,b,c) for(rint a=b;a<=c;++a)
     39 #define fr(a,b,c) for(rint a=b;a>=c;--a)
     40 #define mem(a,b) memset(a,b,sizeof(a))
     41 #define pr printf
     42 #define sc scanf
     43 #define ls rt<<1
     44 #define rs rt<<1|1
     45 typedef vector<int> VI;
     46 typedef long long ll;
     47 const double E=2.718281828;
     48 const double PI=acos(-1.0);
     49 //const ll INF=(1LL<<60);
     50 const int inf=(1<<30);
     51 const double ESP=1e-9;
     52 const int mod=(int)1e9+7;
     53 const int N=(int)1e6+10;
     54 
     55 ll a[N],sum[N],up[N];
     56 int er[17]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536};
     57 ll qpow(ll a,ll b,ll mod)
     58 {
     59     ll ans;
     60 //    a%=mod;
     61     ans=1;
     62     while(b!=0)
     63     {
     64         if(b&1)
     65             ans=(ans*a)%mod;
     66         b/=2;
     67         a=(a*a)%mod;
     68     }
     69     return ans;
     70 }
     71 
     72 int main()
     73 {
     74     sum[1]=2;
     75     up[1]=2;
     76     a[1]=2;
     77     for(int i=2;i<=N-3;++i)
     78         a[i]=i+1,sum[i]=i+1+sum[i-1],up[i]=up[i-1]*(i+1)%mod;
     79     ll x;
     80     int T;
     81     sc("%d",&T);
     82     while(T--)
     83     {
     84         sc("%lld",&x);
     85         if(x<=4)
     86         {
     87             cout<<x<<endl;
     88             continue;
     89         }
     90         int temp=0;
     91         for(int i=16;i>=0;--i)
     92         {
     93             if(sum[temp+er[i]]<=x)
     94                 temp+=er[i];
     95         }
     96         ll out=x%sum[temp];
     97         if(temp+1-out>=1)
     98         {
     99             ll other=up[temp]*qpow(a[out?temp+1-out:temp],mod-2,mod)%mod;
    100             ll ans=other*(a[out?temp+1-out:temp]+out)%mod;
    101             pr("%lld
    ",ans);
    102         }
    103         else
    104         {
    105             ll other=up[temp]*qpow(2,mod-2,mod)%mod;
    106             ll ans=other*(2+out)%mod;
    107             pr("%lld
    ",ans);
    108         }
    109     }
    110     return 0;
    111 }
    112 
    113 /**************************************************************************************/
    114 
    115 int maxx(int a,int b)
    116 {
    117     return a>b?a:b;
    118 }
    119 
    120 void swapp(int &a,int &b)
    121 {
    122     a^=b^=a^=b;
    123 }
    124 
    125 int lowbit(int n)
    126 {
    127     return n&(-n);
    128 }
    129 
    130 int Del_bit_1(int n)
    131 {
    132     return n&(n-1);
    133 }
    134 
    135 int abss(int a)
    136 {
    137     return a>0?a:-a;
    138 }
    139 
    140 double fabss(double a)
    141 {
    142     return a>0?a:-a;
    143 }
    144 
    145 int minn(int a,int b)
    146 {
    147     return a<b?a:b;
    148 }
  • 相关阅读:
    Delphi使用Indy、ICS组件读取网页
    用SendNotifyMessage代替PostMessage避免消息丢失
    LuaPlus的编译和引用
    如何转换和输出超大整数(64位)
    jQuery 源码:封装 Event
    jQuery 源码:操作样式
    jQuery 源码:元素位置
    模拟ES5 Array.prototype.reduce
    as 和 is 运算符以及安全的类型强制转换
    计算机编程基础
  • 原文地址:https://www.cnblogs.com/--HPY-7m/p/11745651.html
Copyright © 2011-2022 走看看