[题解] 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为起始位 ...
随机推荐
- 测试 ASP.NET Core API Controller
本文需要您了解ASP.NET Core MVC/Web API, xUnit以及Moq相关知识. 这里有xUnit和Moq的介绍: https://www.cnblogs.com/cgzl/p/917 ...
- 【Android Studio安装部署系列】三十六、Android studio3.2使用过程中注意事项
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 Android Studio升级到3.2之后,运行旧项目的时候出现了各种情况,特此记录下. 一.打包选项多了,一般情况下选择APK即 ...
- Redis 概念以及底层数据结构
Redis 简介 REmote DIctionary Server(Redis) 是一个由SalvatoreSanfilippo写的key-value存储系统. Redis是一个开源的使用ANSI C ...
- API接口通讯参数规范
通常在很多的公司里面,对于接口的返回值没做太大规范,所以会比较常看到各个项目各自定义随意的返回值,比如以下情况: 1. 直接返回bool值(True或者False) 2. 返回void,只要不是异常信 ...
- C++ 编译期封装-Pimpl技术
Pimpl技术——编译期封装 Pimpl 意思为“具体实现的指针”(Pointer to Implementation), 它通过一个私有的成员指针,将指针所指向的类的内部实现数据进行隐藏, 是隐藏实 ...
- JVM上的响应式流 — Reactor简介
强烈建议先阅读下JVM平台上的响应式流(Reactive Streams)规范,如果没读过的话. 官方文档:https://projectreactor.io/. 响应式编程 作为响应式编程方向上的第 ...
- ios键盘弹起 body的高度拉长,页面底部空白问题。ios软键盘将页面抵到上面后,关闭软键盘页面不回弹的问题。
js 监听ios手机键盘弹起和收起的事件 /* js 监听ios手机键盘弹起和收起的事件 */ document.body.addEventListener('focusin', () => { ...
- Java设计模式---ChainOfResponsibility责任链模式
参考于 : 大话设计模式 马士兵设计模式视频 代码参考于马士兵设计模式视频 写在开头:职责链模式:使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系 图来自大话设计模式,下面我的代 ...
- solr8.0 springboot整合solr(四)
引言: solr搭建起后,就该应用到java后台开发里了,接下来就用springboot整合应用solr 一:引入jar包 <!--solr--> <dependency> & ...
- 升鲜宝V2.0_生鲜配送行业,对生鲜配送系统开发与实施的深度对比与思考_升鲜宝生鲜配送系统_15382353715_余东升
升鲜宝V2.0_生鲜配送行业,对生鲜配送系统开发与实施的深度对比与思考_升鲜宝生鲜配送系统_15382353715_余东升 笔者从事生鲜配送软件开发接近10年,前前后后研究了很多 ...