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 ;
}
Codeforces Round #549 (Div. 2)B. Nirvana的更多相关文章
- [题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...
- 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. 2) 训练实录 (5/6)
The Doors +0 找出输入的01数列里,0或者1先出完的的下标. Nirvana +3 输入n,求1到n的数字,哪个数逐位相乘的积最大,输出最大积. 思路是按位比较,从低到高,依次把小位换成全 ...
- CodeForces Round #549 Div.2
A. The Doors 代码: #include <bits/stdc++.h> using namespace std; ; int N; , One = ; int a[maxn], ...
- [ 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) Solution
传送门 A.The Doors 看懂题目就会写的题 给一个 $01$ 序列,找到最早的位置使得 $0$ 或 $1$ 已经全部出现 #include<iostream> #include&l ...
- 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的 ...
随机推荐
- 新手C#ListView使用记录2018.08.03
在使用C#的ListView时,感觉有一些部分需要自己注意. ListView1.Clear()这条指令在使用时,用于Click后在ListView中显示数据,应该放在输入数据的前面. 在ListVi ...
- js原型和原型链[转]
附上原文出处:http://hzjavaeyer.group.iteye.com/group/wiki/3086-JavaScript-core-concepts 一.概念: 原型对象:JavaScr ...
- Reducing File Size
[Reducing File Size] 1.Unity strips out unused assets. The amount of assets in your project folder d ...
- idea升级maven工程jar包版本和解决jar包冲突
原来用过eclipse的都知道,想要升级maven工程的jar包版本或者解决jar包冲突,直接在pom文件下的dependency hierarchy视图下右击冲突的jar包,将其exclude掉,然 ...
- Linux静态库与动态库详解
引言 为了代码的复用性和模块化,我们常常使用一些库文件,在Windows操作系统下位.lib .dll作为静态库和动态库的后缀名. 在Linux下,静态链接库名字一般为libabcdef.a,其中ab ...
- Redis初学笔记
1.官网概述 Redis is an open source (BSD licensed), in-memory data structure store, used as database, cac ...
- Golang 之 Qrcode 二维码
二维码大行其道,尤其 qrcode ,怎么能少了大golang 呢. follow me . 1.引用 go get github.com/skip2/go-qrcode 2.写 package ma ...
- tree.J48
Weka为一个Java基础上的机器学习工具.上手简单,并提供图形化界面.提供如分类.聚类.频繁项挖掘等工具.本篇文章主要写一下分类器算法中的J48算法及事实上现. 一.算法 J48是基于C4.5实现的 ...
- Ubuntu14.04下 安装xhprof
1.下载xhprof包: wget http://pecl.php.net/get/xhprof-0.9.4.tgz 2.解压 进入扩展目录 .tgz cd /home/justphp/xhprof- ...
- 【转载】如何选择MySQL存储引擎
一.MySQL的存储引擎 完整的引擎说明还是看官方文档:http://dev.mysql.com/doc/refman/5.6/en/storage-engines.html 这里介绍一些主要的引擎 ...