Codeforces Round #202 (Div. 2) B. Color the Fence
来源:互联网 发布:软件质量保证书范本 编辑:程序博客网 时间:2024/05/29 07:34
B. Color the Fence
time limit per test
2 seconds
memory limit per test
256 megabytes
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.
Sample test(s)
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
思路:贪心
#include <iostream>#include <cstdio>using namespace std;int main() { int n ; int a[10] ; while(~scanf("%d",&n)) { int minn = 1000010 ; for(int i = 0 ; i < 9 ; ++i ) { scanf("%d",&a[i]) ; if( a[i] < minn ) minn = a[i] ; } int num = n/minn; if (!num) printf("-1") ; int temp = n ; while(num) { for( int i = 8 ; i >= 0 ; --i) { if( a[i] <= temp && (temp-a[i])/minn == num-1 ) { printf("%d",i+1) ; temp -=a[i] ; --num ; break; } } } printf("\n") ; } return 0 ;}
0 0
- Codeforces Round #202 (Div. 2) B.Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2)B. Color the Fence
- Codeforces Round #202 (Div. 2)B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- Codeforces Round #202 B:Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence(贪心)
- Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)
- CodeForces 349B - Color the Fence
- codeforces 349B Color the Fence
- CodeForces 349B Color the Fence
- CodeForces 349B Color the Fence
- CodeForces 349B Color the Fence
- CF#202DIV2:B. Color the Fence
- CF#202 div2 B Color the Fence
- 《Windows Internals》第六版 Chapter 6 Security 笔记
- UISlider 和 UISegement
- 博客我来了
- 针对报出 cvc-complex-type.2.4.a: Invalid content was found starting with element 问题解决办法
- DRW入门之异常:java.lang.ClassNotFoundException: org.directwebremoting.servlet.DwrServlet.class
- Codeforces Round #202 (Div. 2) B. Color the Fence
- SDKD Summer Team Contest C
- 反射、注解和线程、Thread、同步锁问题和基于多线程的Server通信(8.4)
- Shiny应用基础(3):页面布局
- Objective-C学习-字典类型 NSDictionary 和 NSMutableDictionary
- opencv学习(三)书本《学习Opencv》(中文版)第四章的样例Ex4-1(opencv3.0.0+VS2012+win7)
- CTS Fail项目解决方法集锦
- 2015 多校联赛 ——HDU5349(水)
- hdu 2203 亲和串(给两个字符串s1,s2,问s2可不可能出现在以s1为循环节的串中)