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的 ...
随机推荐
- MySQL数据库篇之完整性约束和表关系
主要内容: 一.完整性约束 二.表关系 1️⃣ 完整性约束 (1)何为完整性约束? 约束条件与数据类型的宽度一样,都是可选参数. 作用:用于保证数据的完整性和一致性 (2)分类主要有以下五类: 1.n ...
- 第一个MFC实例:计算圆周长和圆面积
一.基于Microsoft MFC的编程方法 MFC是微软基础类库(Microsoft Foundation Class)的缩写.与API不同,MFC不是Windows操作系统的组成部分,而是微软公司 ...
- Docker CE部署
一.概述 Docker 在1.13版本之后,从2017年的3月1日开始,版本命名规则变为如下: 项目 说明 版本格式 YY.MM Stable 每个季度发行 Edge版本 每个月发行 同时Docker ...
- http协议简析(一)
HTTP:hype-text transfer protocol,超文本传输协议,超文本(html)在网络间(电脑与电脑之间)传输过程中所遵循的一些规则. 两台电脑之间要实现数据传输的条件 1.两台电 ...
- HTTPS加密那点事--轻松秒懂HTTPS非对称加密
本文转载自微信公众号(苦逼的码农),原文地址: https://mp.weixin.qq.com/s/j-ss95ItMnWsZHLpUGBMkQ 用漫画的形式解释技术问题是不是有眼前一亮的感觉呢?以 ...
- Can not find -lXXXX
Description I had the error message Can not find -lGL when i run qt qmake long ago. The error messag ...
- linux操作系统下,怎么使用kill按照PID一次杀死多个进程
1.ps -ef | grep firefox | grep -v grep | cut -c 9-15 | xargs kill -s 9 说明:“grep firefox”的输出结果是,所有含有关 ...
- pcl point merge
http://pointclouds.org/documentation/tutorials/pairwise_incremental_registration.php#pairwise-increm ...
- json操作工具-LitJson
LitJSON是json生成与读取的操作工具,使用很方便并且网上还能找到源码.下面是使用LitJSON的例子: 一.生成json:实例化一个JsonData,然后按照List数组的方式向里面填. Js ...
- mysql:查询数据库版本的几种方式
Mysql版本: 登入数据库的时候: select @@version; select version(); mysql> select @@version; +-----------+ | @ ...