(贪心)Color the Fence - CF 202 Div2B
2017-02-07 09:42
399 查看
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
http://codeforces.com/contest/349/problem/B
给你染料的体积 以及 数字1~9 的需要的染料体积
求 能染出来的最大的数
最大的数字:
1. 位数多
2. 在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
http://codeforces.com/contest/349/problem/B
给你染料的体积 以及 数字1~9 的需要的染料体积
求 能染出来的最大的数
最大的数字:
1. 位数多
2. 在1前提下高位尽量大
#include <bits/stdc++.h> using namespace std; int main() { int i,v,minnum; int sum,cnt,flag; int num[11]; while (cin>>v) { minnum=1e6; sum=0; cnt=0; for (i=1; i<=9; i++) { cin>>num[i]; if (num[i] <= minnum) { minnum=num[i]; ///耗费染料最少的数 染出来位数多 } } cnt=v/minnum; ///cnt 能染出来的最大位数 flag=cnt; sum=1; while (flag--) { for (i=9; i>=1; i--) /// 从高位开始染 { if (v>=num[i] && (v-num[i])/minnum + sum == cnt) /// sum+cnt==the longest lenght notice : v>=num[i] { v-=num[i]; sum++; ///已经染得位数 cout<<i; break; ///染完继续下一位 } } } if (!cnt) { cout<<"-1"; } cout<<endl; } return 0; }
相关文章推荐
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - 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
- CF#202 div2 B Color the Fence
- Codeforces Round #202 (Div. 2)B. Color the Fence
- cf 349 B. Color the Fence(贪心)
- CF 349B - Color the Fence
- nyoj 791 Color the fence 【贪心】
- Codeforces 349 B Color the Fence (思维+贪心)
- NYOJ791 Color the fence(贪心)
- Codeforces Round #202 B:Color the Fence
- codeforces349B - Color the Fence 贪心+DP
- 349B - Color the Fence (贪心)
- CodeForces 349B--Color the Fence(贪心)
- H - Color the Fence -贪心
- 贪心——区间选点——xyoj 1782火柴字、xyoj 2080 Color the fence