[题解] 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为起始位 ...
随机推荐
- ubuntu 16.04安装perf
ljc@ubuntu:~$ perf 程序“perf”尚未安装. 您可以使用以下命令安装: sudo apt install linux-tools-common ljc@ubuntu:~$ sudo ...
- 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之十 || AOP面向切面编程浅解析:简单日志记录 + 服务切面缓存
代码已上传Github+Gitee,文末有地址 上回<从壹开始前后端分离[ .NET Core2.0 Api + Vue 2.0 + AOP + 分布式]框架之九 || 依赖注入IoC学习 + ...
- GlideNewDemo【Glide4.7.1版本的简单使用以及圆角功能】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 简单记录下Glide4.7.1版本的使用和实现圆角方案. 注意:关于详细使用请仔细阅读<官方指南>. 效果图 使用步骤 ...
- AsyncTask原理
一.概述 Android开发中我们通常让主线程负责前台用户界面的绘制以及响应用户的操作,让工作者线程在后台执行一些比较耗时的任务.Android中的工作者线程主要有AsyncTask.IntentSe ...
- 学习ASP.NET Core Razor 编程系列十五——文件上传功能(三)
学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...
- Session的使用与Session共享问题
Session的使用与Session共享问题 Session方法 getId():获取sessionId,这个id不一定是数字,比方说它用字符串来表示唯一标识,所以它返回值是String; boole ...
- python学习第九讲,python中的数据类型,字符串的使用与介绍
目录 python学习第九讲,python中的数据类型,字符串的使用与介绍 一丶字符串 1.字符串的定义 2.字符串的常见操作 3.字符串操作 len count index操作 4.判断空白字符,判 ...
- pwnable.tw applestore 分析
此题第一步凑齐7174进入漏洞地点 然后可以把iphone8的结构体中的地址通过read修改为一个.got表地址,这样就能把libc中该函数地址打出来.这是因为read函数并不会在遇到\x00时截断( ...
- js对象数组(JSON) 根据某个共同字段 分组
首先判断 var arr = [ {"id":"1001","name":"值1","value": ...
- 使用Golang搭建web服务
如何用golang搭建一个web服务呢?菜鸟官网的go web编程教程已经介绍了web服务器的工作原理,这里就不赘述了. 我们先看个例子:http.go package main import ( & ...