当前位置:网站首页>6.25atcoderabc257e - addition and multiplication 2
6.25atcoderabc257e - addition and multiplication 2
2022-06-29 16:43:00 【bj_ hacker】
6.25AtCoderABC257E - Addition and Multiplication 2 Answer key
Title Description
link
AtCoderABC257E - Addition and Multiplication 2
A word description
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.
Topic analysis
- This question wants to maximize the number , Maximum first guarantee The number of digits is the largest , That is, use the smallest number to k The value divided by rounding down is , The digit length of the maximum number .
- On the basis of the largest number of digits , Make sure the first place is as big as possible , But it can not affect the length of digits .( Classic greed )
- Thus, it is proposed to select the largest one from the first place each time , Judge the condition : When we get this one, we can fill in the minimum for the rest to ensure the positioning ( The number is the same ).
Code implementation
#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;
}
边栏推荐
- New feature of C11 - Auto and decltype type type indicators
- UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
- 数学知识复习:第一型曲线积分
- 使用kalibr標定工具進行單目相機和雙目相機的標定
- 我,大厂测试员,降薪50%去国企,后悔了...
- 资讯 | 扎克伯格被评为全球IT业最不谨慎的CEO;中国移动研发系留式无人机应急通信高空基站
- Stable currency risk profile: are usdt and usdc safe?
- 6.26CF模拟赛D:黑白条题题解
- Take another picture of cloud redis' improvement path
- Possible reasons for not triggering onreachbutton
猜你喜欢

元代理模型可迁移对抗攻击

Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具

Étalonnage de la caméra monoculaire et de la caméra binoculaire à l'aide de l'outil d'étalonnage kalibr

把这份关于软件测试一系列笔记研究完,进大厂是个“加分项”...

curl: (56) Recv failure: Connection reset by peer

Tencent cloud released the upgraded version of CDW Clickhouse to provide a fast experience for massive data real-time analysis scenarios

【OpenGL】杂谈一、通过鼠标拖拽实现相机绕空间中的某点进行球面旋转查看

After studying this series of notes about software testing, it is a "bonus" to enter the factory

Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving

如何配置 logback?30分鐘讓你徹底學會代碼熬夜敲
随机推荐
Graduates are confused and middle-aged people are anxious. How can the career path become wider and wider?
使用kalibr標定工具進行單目相機和雙目相機的標定
Possible reasons for not triggering onreachbutton
Metadata management Apache Atlas Compilation integration deployment and testing
Why does selenium become the first choice for web automated testing? (source code attached)
实践 | 脚本错误量极致优化-让脚本错误一目了然
又拍云 Redis 的改进之路
C language microblog user management system
Nanjing University: Discussion on the training scheme of digital talents in the new era
Time format GTM to Beijing time
After eight years of testing and opening experience and interview with 28K company, hematemesis sorted out high-frequency interview questions and answers
MATLAB给数据加噪声/扰动
数学知识复习:第一型曲线积分
Implement a ThreadLocal by yourself
It's also a test. Why do others get an annual salary of 30w+?
关于XAMPP无法启动mysql数据库
Us chips are hit hard again, and Intel may be defeated by TSMC and reduced to the third place in the world
Redis布隆过滤器和布谷鸟过滤器
Comment configurer logback? 30 minutes pour apprendre à coder et à frapper tard.
分片信息调哪个参数呢?用的是MySQLsource stream api,不是table api