CodeForces 349B Color the Fence
2016-07-19 10:54
351 查看
B. Color the Fence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires ad liters
of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence.
Input
The first line contains a positive integer v (0 ≤ v ≤ 106).
The second line contains nine positive integers a1, a2, ..., a9 (1 ≤ ai ≤ 105).
Output
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
Examples
input
output
input
output
input
output
题目大意:用一定量的油漆绘出一个最大的数字,第一行给出数V代表油漆的总量,第二行九个数分 别代表1-9这9个数字所需的所耗费的油漆量,问能绘出的最大数字是多少。
思路:我们用一个变量MIN表示1-9这9个数字所耗油漆量的最小值,那么V/MIN就表示V升油漆可绘 制的数字的最大长度。这样最大长度就有了,接下来我们开始找最大的数。从最高位开 始找,从大到小暴力9个数字,若发现某个数字可以绘制并且绘制后不会改变最大长度(例 如V = 5, 9个数分别为2、2、3、4、5、6、7、8、9,那么最大长度为2,当选择数字 1,2,3时不会改变最大长度,但若选择4时,便无法再继续选择,此时最大长度为1)时,
就选用这个数,然后退出。不断循环,直到无法选择为止。
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires ad liters
of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence.
Input
The first line contains a positive integer v (0 ≤ v ≤ 106).
The second line contains nine positive integers a1, a2, ..., a9 (1 ≤ ai ≤ 105).
Output
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
Examples
input
5 5 4 3 2 1 2 3 4 5
output
55555
input
2 9 11 1 12 5 8 9 10 6
output
33
input
0 1 1 1 1 1 1 1 1 1
output
-1
题目大意:用一定量的油漆绘出一个最大的数字,第一行给出数V代表油漆的总量,第二行九个数分 别代表1-9这9个数字所需的所耗费的油漆量,问能绘出的最大数字是多少。
思路:我们用一个变量MIN表示1-9这9个数字所耗油漆量的最小值,那么V/MIN就表示V升油漆可绘 制的数字的最大长度。这样最大长度就有了,接下来我们开始找最大的数。从最高位开 始找,从大到小暴力9个数字,若发现某个数字可以绘制并且绘制后不会改变最大长度(例 如V = 5, 9个数分别为2、2、3、4、5、6、7、8、9,那么最大长度为2,当选择数字 1,2,3时不会改变最大长度,但若选择4时,便无法再继续选择,此时最大长度为1)时,
就选用这个数,然后退出。不断循环,直到无法选择为止。
#include<cstdio> #include<cstring> #include<vector> #include<iostream> #include<algorithm> using namespace std; typedef pair<int,int> P; int v; vector<P> Num; int main() { scanf("%d",&v); int MIN = 1e9; for(int i = 1; i <= 9; i++){ int x; scanf("%d",&x); Num.push_back(P(i,x)); MIN = min(MIN,x); } string s; int ans = -1; while(v >= MIN){ int len = v/MIN; for(int i = 8; i >= 0; i--){ if(v >= Num[i].second && (v-Num[i].second)/MIN+1 == len){ s.push_back(Num[i].first+48); v -= Num[i].second; break; } } } if(!s.empty()){ cout << s << endl; } else cout << "-1" << endl; }
相关文章推荐
- js 屏蔽 浏览器(IE和FireFox)的 刷新功能
- $(this.el).html 与 this.$el.tml区别
- 全面了解JavaScript对象进阶
- jQuery插件stickup.js 源码解析初步
- JS操作JSON总结
- jQuery监听回车事件
- 左右select选择 (jQuery实现)
- CodeForces 347A Difference Row
- 同源及跨域问题解决
- 移动设备wap手机网页html5通过特殊链接:打电话,发短信,发邮件详细教程
- javascript的日期对象Date操作时间日期值
- HTML5 对于手机页面长按会粘贴复制的禁用 (解决方案)
- html图片如何等比缩放
- css兼容小问题
- html中offsetTop、clientTop、scrollTop、offsetTop各属性介绍
- React Router中pushState的使用方法
- jquery实现div拖拽宽度示例代码
- jQuery小技巧
- jQuery小技巧
- html中offsetTop、clientTop、scrollTop、offsetTop各属性介绍