题意:

把n拆分成几个数,把这些数乘起来最大。

思路:

3越多越好。

对4,5特判一下,4的时候是2*2大,5的时候还剩个2,那么就是n%3=1的话,我们先拿个4,n%3==2的话就是先拿个2,后面把有多少个3乘起来就好了;

#include <cstdio>
#include <iostream>
using namespace std;
#define maxn 3022
int n, step;
int ans[maxn];
int main()
{
scanf("%d", &n);
if(n==1)
{
printf("1\n");
return 0;
}
int num=1;
if(n%3==0){
ans[1]=1;
}
if(n%3==1){
ans[1]=4;
n-=4;
}
if(n%3==2){
ans[1]=2;
n-=2;
}
step=n/3;
for(int i=1;i<=step;++i)
{
for(int j=1;j<=num;++j)
ans[j]*=3;
for(int j=1;j<=num+1;++j)
{
ans[j+1]+=ans[j]/10;
ans[j]%=10;
}
int k=num;
while(ans[k+1]!=0)
++k;
num=k;
}
for(int i=num;i>=1;--i)
printf("%d",ans[i]);
printf("\n");
return 0;
}

URAL1222的更多相关文章

随机推荐

  1. xpath 轴,节点之间的关系

    http://www.w3school.com.cn/xpath/xpath_axes.asp http://www.freeformatter.com/xpath-tester.html 测试 轴可 ...

  2. Xcode5.1.1+ios 7.1.2 免证书真机调试

    Xcode假设不破解.无法真机调试, 也无法编译真机Release文件.仅仅有付费开通Apple开发人员账号,才干申请真机调试.而Xcode进行破解后,结合越狱的iPhone或iPad, 就可以免官方 ...

  3. LeetCode(83)题解: Remove Duplicates from Sorted List

    https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 题目: Given a sorted linked list, de ...

  4. android:PopupWindow的使用场景和注意事项

    1.PopupWindow的特点 借用Google官方的说法: "A popup window that can be used to display an arbitrary view. ...

  5. 在苹果iOS平台中获取当前程序进程的进程名等信息

    本文由EasyDarwin开源团队成员Penggy供稿: Objective-C 提供 NSProcessInfo 这个类来获取当前 APP 进程信息, 然而我们的静态库是 pure C++ 工程. ...

  6. types of transfrmations

    http://math.wallawalla.edu/~duncjo/courses/math113/winter08/notes/9-1_math113.pdf Name What Changes ...

  7. MapReduce源代码分析之LocatedFileStatusFetcher

    LocatedFileStatusFetcher是MapReduce中一个针对给定输入路径数组,使用配置的线程数目来获取数据块位置的有用类. 它的主要作用就是利用多线程技术.每一个线程相应一个任务.每 ...

  8. spring IOC(转)

    原文 http://stamen.iteye.com/blog/1489223 引述:IoC(控制反转:Inverse of Control)是Spring容器的内核,AOP.声明式事务等功能在此基础 ...

  9. CSS动画硬件加速

    http://zencode.in/14.CSS%E5%8A%A8%E7%94%BB%E7%9A%84%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96.html http:// ...

  10. 万亿级日志与行为数据存储查询技术剖析——Hbase系预聚合方案、Dremel系parquet列存储、预聚合系、Lucene系

    转自:http://www.infoq.com/cn/articles/trillion-log-and-data-storage-query-techniques?utm_source=infoq& ...