Codeforces Round #549 (Div. 2)B. Nirvana
1 second
256 megabytes
standard input
standard output
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.
Help Kurt find the maximum possible product of digits among all integers from 11 to nn.
The only input line contains the integer nn (1≤n≤2⋅1091≤n≤2⋅109).
Print the maximum product of digits among all integers from 11 to nn.
390
216
7
7
1000000000
387420489
In the first example the maximum product is achieved for 389389 (the product of digits is 3⋅8⋅9=2163⋅8⋅9=216).
In the second example the maximum product is achieved for 77 (the product of digits is 77).
In the third example the maximum product is achieved for 999999999999999999 (the product of digits is 99=38742048999=387420489).
解题思路:这道题就是给你一个n数,问你1到n之间哪个数能使各个位数相乘最大;
首先我们想到尽量将每一位变为9,然后每次都向前借一位来减。
注意当K为0时,表示前面的数字没了,所以应该返回1。
代码如下:
#include<iostream>
#include<cmath>
using namespace std;
int n ;
int cj(int k)
{
if(k==)
return ;
if(k<)
{
return k;
} return max(cj(k/)*(k%),cj(k/-)*); }
int main()
{
cin>>n;
cout<<cj(n);
return ;
}
最新文章
- 常用CSS优化总结——网络性能与语法性能建议
- 博文写作——摘要&;摘要图标
- SWFUpload简介及中文参考手册(share)
- 2.Android 自定义通用的Item布局
- 爱默生UPS并机系统:进入与退出操作方法
- Atcoder CODE FESTIVAL 2016 qual C 的E题 Encyclopedia of Permutations
- .net 网站预编译命令
- 新一代 PHP 加速插件 Zend Opcache
- 91. Decode Ways
- PHP联合sqlserver2008使用的全过程 ( 原创 亲测)
- 数据库:JDBC编程
- ArcGIS Runtime SDK for Android开发之调用GP服务(异步调用)
- 我的 MarkDown 学习笔记
- Spring in Action --- 第一章 简介
- SSH防爆破脚本
- centos 7.0远程登录
- webpack中跨域请求proxy代理(vue与react脚手架不同设置方法)
- photoshop 笔记
- CRM项目hellokitty部分交互界面
- ubuntu 16.04启用root和ssh登录