Color the fence

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述

Tom has fallen in love with Mary. Now Tom wants to show his love and write a number on the fence opposite to

Mary’s house. Tom thinks that the larger the numbers is, the more chance to win Mary’s heart he has.

Unfortunately, Tom could only get V liters paint. He did the math and concluded that digit i requires ai liters paint.

Besides,Tom heard that Mary doesn’t like zero.That’s why Tom won’t use them in his number.

Help Tom find the maximum number he can write on the fence.

 
输入
There are multiple test cases.
Each case the first line contains a nonnegative integer V(0≤V≤10^6).
The second line contains nine positive integers a1,a2,……,a9(1≤ai≤10^5).
输出
Printf the maximum number Tom can write on the fence. If he has too little paint for any digit, print -1.
样例输入
5
5 4 3 2 1 2 3 4 5
2
9 11 1 12 5 8 9 10 6
样例输出
55555
33
本题题意是给V升的油漆,以及1-9每个数字需要的油漆,问用这些油漆能刷出的最大的数字?
如给得第一个测试用例,有5升油漆,数字5需要1升油漆,故把数字5刷5次得到的数字最大
但存在这样的测试用例
9
5 4 2 3 5 4 6 4 5
则全用来刷数字3的话,为3333,还剩1升油漆
如果刷3个数字2,还剩3升用来刷数字4,则结果为4333,比全用来刷数字2大
同时还存在一种测试用例
8
5 4 3 2 5 4 6 1 1
有油漆相同的情况,应该选择数字最大的
本题还未考虑下面这种情况,参考codeforce给出的测试用例才知道
898207
99745 99746 99748 99752 99760 99776 99808 99872 100000
结果为987654321
#include <iostream>
#include <vector>
#include <algorithm> using namespace std; int main(){
int v;
while(cin >> v){
vector<int> num(,);
int minIndex = ;
for(int i = ; i < ; ++ i){
cin >> num[i];
if(num[minIndex]>=num[i]) minIndex = i;
}
if(v < num[minIndex]) cout<<-<<endl;
else if(v%num[minIndex] == ) cout<<string(v/num[minIndex],''+minIndex)<<endl;
else{
int cnt = v/num[minIndex], remain = v%num[minIndex];
for(int i = ; i < cnt; ++ i){
for(int j = ; j > ; -- j){
if(j <= minIndex){
cout<<minIndex;
break;
}
if(remain-(num[j]-num[minIndex]) >= ){
remain -=(num[j]-num[minIndex]);
cout<<j;
break;
}
}
}
cout<<endl;
}
}
}

 
 

最新文章

  1. epub电子书--目录结构介绍
  2. Android MVP + 泛型,实现了友好VP交互及Activity潜在的内存泄露的优化
  3. rpm命令
  4. jquery操作radio单选按钮、checked复选框。
  5. 在 Ubuntu 13.10 中搭建Java开发环境 - 懒人版
  6. 转换 TColor 到 HTML 颜色串
  7. jQuery版推箱子游戏详解和源码
  8. Windows内核中的内存管理
  9. JavaScript 执行机制
  10. ASP.NET Core 2.1 Web API + Identity Server 4 + Angular 6 + Angular Material 实战小项目视频
  11. python-迭代器与可迭代对象
  12. Spring声明式事务配置
  13. 记OI退役
  14. CFtpConnection Class
  15. 如何查看.net framework 版本
  16. Fiddler 手机抓包 手机联网异常解决方案
  17. 7-51单片机ESP8266学习-AT指令(8266TCP服务器,编写自己的C#TCP客户端发信息给单片机控制小灯的亮灭)
  18. TCP的TIME_WAIT
  19. Apache Solr 初级教程(介绍、安装部署、Java接口、中文分词)
  20. Unity NavMesh导航网格 初级教程

热门文章

  1. DOM &ndash; 7.动态创建DOM + 8.innerText innerHTML value
  2. AOJ789 买酒
  3. Oracle 【IT实验室】数据库备份与恢复之:如何对Oracle数据库文件进行恢复与备份
  4. js 随机星星 document.createElement(); setAttribute()
  5. js 动态时钟
  6. CQRS及.NET中的参考资料
  7. vector 之删除元素
  8. Redis学习笔记(2) Redis基础类型及命令之一
  9. 什么时候使用CountDownLatch
  10. 【criteria CascadeType】级联的不同情况