[题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana
[题目描述]
B. Nirvana
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 1 to n.
Input
The only input line contains the integer n (1≤n≤2⋅109).
Output
Print the maximum product of digits among all integers from 1 to n.
Examples
input
390
output
216
input
7
output
7
input
1000000000
output
387420489
Note
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).
[解法]
尽量将每一位变为9,或者向前退位来变成9,并且前一位减1.
[代码(AC)]
#include <iostream>
#include <cstdio>
#include <string>
#include <iostream>
#include <iostream>
#include <iostream>
#include <iostream>
#include <iostream>
using namespace std;
int ans(int n){
if(n==)return ;
if(n<)return n;
return max(ans(n/)*(n%),ans(n/-)*);
}
int main()
{
int n;
scanf("%d", &n);
printf("%d", ans(n));
}
2019-04-04 18:05:50
[题解] Codeforces Round #549 (Div. 2) B. Nirvana的更多相关文章
- Codeforces Round #549 (Div. 2)B. Nirvana
B. Nirvana time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #549 (Div. 1)
今天试图用typora写题解 真开心 参考 你会发现有很多都是参考的..zblzbl Codeforces Round #549 (Div. 1) 最近脑子不行啦 需要cf来缓解一下 A. The B ...
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- Codeforces Round #549 (Div. 1) 题解
link 前几天补完了某一场很早以前的div1,突然想来更博客,于是就有了这篇文章 A The Beatles 显然若起点和第一次到达的位置距离为 d ,那么经过的不同站点数为 $\frac{nk}{ ...
- Codeforces Round #549 (Div. 2) 训练实录 (5/6)
The Doors +0 找出输入的01数列里,0或者1先出完的的下标. Nirvana +3 输入n,求1到n的数字,哪个数逐位相乘的积最大,输出最大积. 思路是按位比较,从低到高,依次把小位换成全 ...
- [ Codeforces Round #549 (Div. 2)][D. The Beatles][exgcd]
https://codeforces.com/contest/1143/problem/D D. The Beatles time limit per test 1 second memory lim ...
- Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)
https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...
- Codeforces Round #549 (Div. 2) E 倍增处理按排列顺序的上一个位置
https://codeforces.com/contest/1143/problem/E 题意 p为n的一个排列,给出有m个数字的数组a,q次询问,每次询问a数组区间[l,r]中是否存在子序列为p的 ...
- Codeforces Round #549 (Div. 2) D 数学
https://codeforces.com/contest/1143/problem/D 题意 有nk个城市,第1,k+1,2k+1,...,(n-1)k+1城市有餐厅,你每次能走l距离,a为起始位 ...
随机推荐
- 开源图像标注工具labelme的安装使用及汉化
一 LabelMe简介 labelme是麻省理工(MIT)的计算机科学和人工智能实验室(CSAIL)研发的图像标注工具,人们可以使用该工具创建定制化标注任务或执行图像标注,项目源代码已经开源. 项目开 ...
- javaScript设计模式之面向对象编程(object-oriented programming,OOP)--寄生组合式继承
组合式继承:将类式继承同构造函数继承组合使用,但是存在一个问题,子类不是父类的实例,而子类的原型式父类的实例,所以才有了寄生组合式继承. 意思就是说,寄生就是寄生式继承,寄生式继承就是依托于原型继承, ...
- 强化学习(五)用时序差分法(TD)求解
在强化学习(四)用蒙特卡罗法(MC)求解中,我们讲到了使用蒙特卡罗法来求解强化学习问题的方法,虽然蒙特卡罗法很灵活,不需要环境的状态转化概率模型,但是它需要所有的采样序列都是经历完整的状态序列.如果我 ...
- Chrome浏览器下自动填充的输入框背景
记录下从张鑫旭老师的微博中看到关于input输入框的属性 1.autocomplete="off" autocomplete 属性规定输入字段是否应该启用自动完成功能 自动完成允许 ...
- Window环境下搭建Git服务器
如果公司要搭建自己的 Git 服务器,可以使用 gitblit 这个开源的 Git 服务器 下载gitblit安装包 到 http://gitblit.com/下载安装包 解压缩下载的压缩包即可,无需 ...
- JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识
JAVA WEB快速入门系列之前的相关文章如下:(文章全部本人[梦在旅途原创],文中内容可能部份图片.代码参照网上资源) 第一篇:JAVA WEB快速入门之环境搭建 第二篇:JAVA WEB快速入门之 ...
- Centos7配置MongoDB以及端口修改
一.安装之前可以参考官网安装教程: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 二.登录服务器,配置yum ...
- [TCP/IP] 传输层-ethereal 抓包分析TCP包
开启抓包工具抓取一个HTTP的GET请求,我的ip是10.222.128.159 目标服务器ip是140.143.25.27 握手阶段: 客户端 ===> SYN MSS=1460(我能接 ...
- Java开发笔记(八十三)利用注解技术检查空指针
注解属于比较高级的Java开发技术,前面介绍的内置注解专用于编译器检查代码,另外一些注解则由各大框架定义与调用,像Web开发常见的Spring框架.Mybatis框架,Android开发常见的Butt ...
- while死循环导致的内存溢出
场景:新开发的功能内测,新调用了其它模块的接口,一如既往的点鼠标,计费,但是许久都没有响应页面遮罩一直锁着,最后抛出了以下异常 咋一看这个异常信息,不就是锁表了吗?把锁表进程Kill掉,再来一遍,结果 ...