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 ...
随机推荐
- OpenGL编程逐步深入(九)插值处理
注:文中VS代指顶点着色器,FS代指片段着色器. 准备知识 这个教程和大家展示3d管道中非常重要的部分,即Interpolation(插值).光栅化程序执行的插值变量由VS产生.正如你已经见到过的,为 ...
- EasyUI--Alert()
1.$.messager.alert(title, msg, icon, fn) 2 <script type="text/javascript"> $(functio ...
- POJ 1144 Network【割顶】
学习的这一篇:https://www.byvoid.com/blog/biconnect 割顶:对于无向图G,如果删除某个点u后,连通分量数目增加,称u为图的关节点或者割顶 u为割顶的条件: (1)u ...
- PL/SQL恢复默认窗口样式
对于初学者来讲,使用PL/SQL时会不小心将窗体关闭,如下图 2. 怎么恢复呢?其实很简单 3. 搞定 转自:http://blog.csdn.net/hello_word2/article/deta ...
- Qihoo 360 altas 实践
Qihoo 360 altas 实践 简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Prox ...
- php八大设计模式之策略模式
策略模式提供一个虚拟的整体,根据不同的要求(参数)提供不同的"零件"(调用不同的"零件"实现不同的结果). <?php /** * 策略模式 * 跟工厂模 ...
- Mysql 主从主主复制总结(详细)
环境:Centos 6.9,Mysql 8.0 配置准备:1.为Centos配置好网络,使用远程工具连接. 2.安装mysql,途径不限.mysql8.0和5.7区别不大,8.0在配置主从的时候默认开 ...
- [洛谷P1939]【模板】矩阵加速(数列)
题目大意:给你一个数列a,规定$a[1]=a[2]=a[3]=1$,$a[i]=a[i-1]+a[i-3](i>3)$求$a[n]\ mod\ 10^9+7$的值. 解题思路:这题看似是很简单的 ...
- 学习参考《Python基础教程(第3版)》中文PDF+英文PDF+源代码
python基础教程ed3: 基础知识 列表和元组 字符串 字典 流程控制 抽象(参数 作用域 递归) 异常 魔术方法/特性/迭代器 模块/标准库 文件 GUI DB 网络编程 测试 扩展python ...
- 洛谷P1006 传纸条 (棋盘dp)
好气,在洛谷上交就过了,在caioj上交就只有40分 之前在51nod做过这道题了. https://blog.csdn.net/qq_34416123/article/details/8180902 ...