zoukankan      html  css  js  c++  java
  • Codeforces Round #549 (Div. 2)B. Nirvana

    B. Nirvana
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    Input

    The only input line contains the integer nn (1n21091≤n≤2⋅109).

    Output

    Print the maximum product of digits among all integers from 11 to nn.

    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 389=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。

    代码如下:

     1 #include<iostream>
     2 #include<cmath>
     3 using namespace std;
     4 int n ;
     5 int cj(int k)
     6 {
     7     if(k==0)
     8     return 1;
     9     if(k<10)
    10     {
    11         return k;
    12     }
    13     
    14     return max(cj(k/10)*(k%10),cj(k/10-1)*9);
    15     
    16 }
    17 int main()
    18 {
    19     cin>>n;
    20     cout<<cj(n);
    21     return 0 ;
    22 }
  • 相关阅读:
    css文本省略号
    javascript在数组的循环中删除元素
    ASP.NET MVC 微信公共平台开发之 微信接入
    ASP.NET Url重写
    通过FTP连接Azure上的网站
    UniversalApp启动页面设置
    ASP.NET页面动态添加js脚本
    使用HyperV虚拟机装系统
    使用一般处理程序HTTPHandler下载文件
    Egret Engine(白鹭引擎)介绍及windows下安装
  • 原文地址:https://www.cnblogs.com/yewanting/p/10727219.html
Copyright © 2011-2022 走看看