码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 6.25AtCoderABC257E - Addition and Multiplication 2题解


    6.25AtCoderABC257E - Addition and Multiplication 2题解

    • 题目描述
      • 链接
      • 文字描述
    • 题目分析
    • 代码实现

    题目描述

    链接

    AtCoderABC257E - Addition and Multiplication 2

    文字描述

    E - Addition and Multiplication 2 /
    Time Limit: 2 sec / Memory Limit: 1024 MB

    Score : 500 points

    Problem Statement
    Takahashi has an integer x. Initially, x=0.

    Takahashi may do the following operation any number of times.

    Choose an integer i (1≤i≤9). Pay C
    i
    ​
    yen (the currency in Japan) to replace x with 10x+i.
    Takahashi has a budget of N yen. Find the maximum possible value of the final x resulting from operations without exceeding the budget.

    Constraints
    1≤N≤10
    6

    1≤C
    i
    ​
    ≤N
    All values in input are integers.
    Input
    Input is given from Standard Input in the following format:

    N
    C
    1
    ​
    C
    2
    ​
    … C
    9
    ​

    Output
    Print the answer.

    Sample Input 1
    Copy
    5
    5 4 3 3 2 5 3 5 3
    Sample Output 1
    Copy
    95
    For example, the operations where i=9 and i=5 in this order change x as:

    0→9→95.

    The amount of money required for these operations is C
    9
    ​
    +C
    5
    ​
    =3+2=5 yen, which does not exceed the budget. Since we can prove that we cannot make an integer greater than or equal to 96 without exceeding the budget, the answer is 95.

    Sample Input 2
    Copy
    20
    1 1 1 1 1 1 1 1 1
    Sample Output 2
    Copy
    99999999999999999999
    Note that the answer may not fit into a 64-bit integer type.

    题目分析

    1. 此题想让数最大,最大首先保证位数最大,即用最小的数把k除向下取整的值就是,最大数的数位长度。
    2. 在位数最大的基础上,保证首位尽可能的大,但不能影响到取得数位长度。(经典的贪心)
    3. 由此推出每次先从首位挑尽可能大的,判断条件:当取到这位是其余为确定位能不能都填最小的(数位不变)。

    代码实现

    #include<bits/stdc++.h>
    using namespace std;
    
    int k,mi=1e9,n;
    int a[100];
    int main(){
    	scanf("%d",&k);
    	for(int i=1;i<=9;i++){
    		scanf("%d",&a[i]);
    		mi=min(mi,a[i]);
    	}
    	n=k/mi;
    	for(int i=1;i<=n;i++){
    		for(int j=9;j>=1;j--){
    			if(k-a[j]>=mi*(n-i)){
    				k-=a[j];
    				printf("%d",j);
    				break;
    			}
    		}
    	}
    	printf("\n");
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
  • 相关阅读:
    Day02 Spring和SpringBoot
    Qt设置整体背景颜色
    如何安装JetPack?
    回归预测 | MATLAB实现BO-LSSVM贝叶斯优化算法优化最小二乘支持向量机数据回归预测(多指标,多图)
    Apache Atlas删除元数据实体
    「Java开发指南」如何利用MyEclipse启用Spring DSL?(二)
    虹科示波器 | 汽车免拆检修 | 2021款广汽丰田威兰达PHEV车发动机故障灯异常点亮
    Spark基础:Kafka分布式消息系统
    C++ STL详解(五) -------- priority_queue
    常用代码扩展点设计方式
  • 原文地址:https://blog.csdn.net/weixin_42178241/article/details/125510092
  • 最新文章
  • 【FHE】我们如何实现同态加密推理(八):SiLU 的密文化——两条路径,和一个 8 字节的开关
    SQLcl 中 c/old/new 替换变量为何失效?先定位再替换
    不让模型写作文,直接从它脑子里读答案:Jev 决策在 .NET 的两条路线
    Halo插件:支持GitHub的图床附件策略
    电视投屏界的“一股清流”!SimpleTVCast 6.0.0-beta 抢先体验:无需TV端App,界面大换血!✨
    华三VXLAN集中式网关实战指南:Spine多活网关 + 双活接入(M-LAG)
    软件更好写之后口碑会更重要
    大 O、大 Omega、大 Theta 的区别,O(n) 复杂度是什么意思
    Java标签跳转:一个鲜为人知但却很实用的小技巧
    多智能体系统论文速读
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号