思维好重要。。

对于n+m == k , 当n == m || abs(n-m) == 1 时n*m取得最大值。

设 s = x*(l-x),s = lx-x^2.其导函数为 s‘ = -1/2x + l。显然 s 在 x == l/2处取得最大值。

则对于k分解成若干个数,则最后有若干个3和若干个2。

又有,三个2换成两个3。和不变积增大。

所以最后最多之会有两个2,剩下的由3组成。

则题目变成了 求3^m。

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <queue>
  7. #include <cmath>
  8. #include <stack>
  9. #include <map>
  10.  
  11. #pragma comment(linker, "/STACK:1024000000");
  12. #define EPS (1e-8)
  13. #define LL long long
  14. #define ULL unsigned long long int
  15. #define _LL __int64
  16. #define _INF 0x3f3f3f3f
  17. #define Mod 1000000007
  18. #define LM(a,b) (((ULL)(a))<<(b))
  19. #define RM(a,b) (((ULL)(a))>>(b))
  20.  
  21. using namespace std;
  22.  
  23. map<int,int> Max;
  24.  
  25. int Cal(int x,int n)
  26. {
  27. if(n == 1)
  28. return x;
  29. if(n == 2)
  30. return x*x;
  31.  
  32. if(Max.find(n) == Max.end())
  33. {
  34. if(n&1)
  35. {
  36. int t1 = Cal(x,n/2);
  37. int t2 = Cal(x,n/2 + 1);
  38.  
  39. t1 = t1*t2;
  40. t1 %= 2009;
  41.  
  42. Max.insert(pair<int,int>(n,t1));
  43. return t1;
  44.  
  45. }
  46. else
  47. {
  48. int t1 = Cal(x,n/2);
  49.  
  50. t1 = t1*t1;
  51. t1 %= 2009;
  52. Max.insert(pair<int,int>(n,t1));
  53. return t1;
  54. }
  55. }
  56. return Max[n];
  57. }
  58.  
  59. int main()
  60. {
  61. int n;
  62.  
  63. while(scanf("%d",&n) != EOF)
  64. {
  65. if(n <= 4)
  66. {
  67. printf("%d\n",n);
  68. }
  69. else
  70. {
  71. if(n%3 == 0)
  72. {
  73. printf("%d\n",Cal(3,n/3)%2009);
  74. }
  75. else if(n%3 == 2)
  76. {
  77. printf("%d\n",(Cal(3,n/3)*2)%2009);
  78. }
  79. else
  80. {
  81. printf("%d\n",(Cal(3,n/3 - 1)*4)%2009);
  82. }
  83. }
  84. }
  85. return 0;
  86. }

HDU 2886 Lou 1 Zhuang的更多相关文章

  1. hdu2886 Lou 1 Zhuang 数学/快速幂

    All members of Hulafly love playing the famous network game called 'Lou 1 Zhuang' so much that Super ...

  2. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  3. ZOJ 2562 HDU 4228 反素数

    反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. BZOJ2179: FFT快速傅立叶 & caioj1450:【快速傅里叶变换】大整数乘法

    [传送门:BZOJ2179&caioj1450] 简要题意: 给出两个超级大的整数,求出a*b 题解: Rose_max出的一道FFT例题,卡掉高精度 = =(没想到BZOJ也有) 只要把a和 ...

  2. bzoj1026: [SCOI2009]windy数(传说你是数位DP)

    1026: [SCOI2009]windy数 题目:传送门 题解: 其实之前年少无知的时候好像A过...表示当时并不知道什么数位DP 今天回来深造一发... 其实如果对这个算法稍有了解...看到这题的 ...

  3. sublime text3之修改注释颜色

    在用sublime text3编写Python2代码时总觉得注释颜色太浅了, 看起来吃力,于是就尝试去修改,和sublime text2不同, sublime text3的主题配置文件在Sublime ...

  4. php实现自动加载类

    PHP 实现自动加载类:

  5. 【J-meter】正则表达式提取

    当获取的值中含有折行,可采用下面的办法解决:

  6. python 异步IO-aiohttp与简单的异步HTTP客户端/服务器

    参考链接:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143209814 ...

  7. Unity Shader (四)顶点程序示例

    1.在顶点函数中实现凸起效果 Shader "Custom/Example" { properties { _R(,))= //圆的半径,也是凸起的范围 _OX(,))= //x轴 ...

  8. Oracle11g密码忘记处理方法

    c:\>sqlplus /nolog sql>connect / as sysdba sql>alter user 用户名 identified by 密码;(注意在这里输入的密码是 ...

  9. 【转】黄聪:HtmlAgilityPack教程案例

    [转]黄聪:HtmlAgilityPack教程案例 HtmlAgilityPack中的HtmlNode类与XmlNode类差不多,提供的功能也大同小异.下面来看看该类提供功能. 一.静态属性 publ ...

  10. qt 闰年

    bool QDate::isLeapYear ( int year ) [static]