HDU 2886 Lou 1 Zhuang
思维好重要。。
对于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。
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <map> #pragma comment(linker, "/STACK:1024000000");
#define EPS (1e-8)
#define LL long long
#define ULL unsigned long long int
#define _LL __int64
#define _INF 0x3f3f3f3f
#define Mod 1000000007
#define LM(a,b) (((ULL)(a))<<(b))
#define RM(a,b) (((ULL)(a))>>(b)) using namespace std; map<int,int> Max; int Cal(int x,int n)
{
if(n == 1)
return x;
if(n == 2)
return x*x; if(Max.find(n) == Max.end())
{
if(n&1)
{
int t1 = Cal(x,n/2);
int t2 = Cal(x,n/2 + 1); t1 = t1*t2;
t1 %= 2009; Max.insert(pair<int,int>(n,t1));
return t1; }
else
{
int t1 = Cal(x,n/2); t1 = t1*t1;
t1 %= 2009;
Max.insert(pair<int,int>(n,t1));
return t1;
}
}
return Max[n];
} int main()
{
int n; while(scanf("%d",&n) != EOF)
{
if(n <= 4)
{
printf("%d\n",n);
}
else
{
if(n%3 == 0)
{
printf("%d\n",Cal(3,n/3)%2009);
}
else if(n%3 == 2)
{
printf("%d\n",(Cal(3,n/3)*2)%2009);
}
else
{
printf("%d\n",(Cal(3,n/3 - 1)*4)%2009);
}
}
}
return 0;
}
HDU 2886 Lou 1 Zhuang的更多相关文章
- hdu2886 Lou 1 Zhuang 数学/快速幂
All members of Hulafly love playing the famous network game called 'Lou 1 Zhuang' so much that Super ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- ZOJ 2562 HDU 4228 反素数
反素数: 对于不论什么正整数x,起约数的个数记做g(x).比如g(1)=1,g(6)=4. 假设某个正整数x满足:对于随意i(0<i<x),都有g(i)<g(x),则称x为反素数. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- hpuoj--1695--一道签到题(KMP)
1695: 一道签到题 时间限制: 2 Sec 内存限制: 128 MB 提交: 72 解决: 36 [提交][状态][讨论版] 题目描述 我想说这是一道签到题,意思就是本次测试中最水的一道,不过 ...
- hdoj--1869--六度分离(floyd)
六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- Keyboard input
Keyboard input Python provides a build-in function called raw_input (in version 2.x) that gets input ...
- HikariCP--一款高性能的 JDBC 连接池
源码地址:https://github.com/brettwooldridge/HikariCP 使用方法: Java 8 maven artifact: <dependency> < ...
- zookeeper伪分布安装配置
1.下载路径为:http://mirrors.cnnic.cn/apache/zookeeper/stable/ 2.安装: 第一步 解压zookeeper压缩包: 进入 zookeeper安装目录 ...
- java中"".equals(A)与A.equals("")一样不?
不一样如果a为nulla = null;a.equals("")出错nullPointerException如果写为"".equals(a)-->就可以防 ...
- [国家集训队]整数的lqp拆分 数学推导 打表找规律
题解: 考场上靠打表找规律切的题,不过严谨的数学推导才是本题精妙所在:求:$\sum\prod_{i=1}^{m}F_{a{i}}$ 设 $f(i)$ 为 $N=i$ 时的答案,$F_{i}$ 为斐波 ...
- Git 内部原理 - (3) Git 引用 (4)包文件
Git 引用 我们可以借助类似于 git log 1a410e 这样的命令来浏览完整的提交历史,但为了能遍历那段历史从而找到所有相关对象,你仍须记住 1a410e 是最后一个提交. 我们需要一个文件来 ...
- CF GYM 100781A(菊花图+直径)
题目大意 给出若干颗树用最少的边把它们连成一个无向连通图,同时使图的直径最小.输出最小直径. 题解 我们定义树的半径为(树的直径+1)/2.符合题意的连接方式为.所有树的“中点”连在直径最长的树的中点 ...
- cmd 操作命令
1)cd 操作文件目录的 cd path #进入path cd / #返回到当前盘符的根目录 cd .. #返回到上级目录 2)dir 显示当前目录 dir #显示当前目录下的文件夹 dir path ...