码农知识堂 - 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
  • 相关阅读:
    PX4模块设计之三十四:ControlAllocator模块
    C++STL——string类与模拟实现
    忙碌生活下的技术适应力:应对新应用学习带来的困扰与挑战
    java毕业设计校园资料在线分享网站mybatis+源码+调试部署+系统+数据库+lw
    LG P3990 【SHOI2013】 超级跳马 解题报告
    ABB机器人欧拉角与四元数的相互转化以及旋转矩阵的求法
    智能座舱架构与芯片- (4) 硬件篇 中
    信息化发展73
    全志烧录工具LiveSuite使用注意事项
    爱普生LQ1900KIIH复位方法
  • 原文地址:https://blog.csdn.net/weixin_42178241/article/details/125510092
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号