nyoj 791 Color the fence
2014-11-20 15:48
399 查看
描述
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.样例输入
样例输出
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.样例输入
55 4 3 2 1 2 3 4 529 11 1 12 5 8 9 10 6
样例输出
5555533贪心算法,输出的那一部分是难点。。。。 代码: #include<stdio.h> #include<string.h> int main(){ int i,j,k,t; int a[10009]; int n; int min; while(~scanf("%d",&n)){ min=0x3f3f3f3f; for(i=0;i<9;i++){ scanf("%d",&a[i]); if(min>a[i]) min=a[i]; } if(n<a[i]){ printf("-1\n");//判断,如果不要符合条件的话直接退出 continue; } for(i=n/min;i>=0;i--){ for(j=8;j>=0;j--){ if(n>=a[j]&&(n-a[j])/min>=i){//从最大的数开始涂,如果满足大于等于i就执行。 n-=a[j]; printf("%d",j+1); break; } } } printf("\n"); } return 0; }
相关文章推荐
- NYOJ 791 Color the fence
- 南阳oj(nyoj) 791 Color the fence
- nyoj 791 Color the fence(贪心)
- NYOJ-791 Color the fence
- nyoj 791 Color the fence 【贪心】
- nyoj 791——Color the fence——————【贪心】
- NYOJ-791 Color the fence (来源CodeForce)
- NYOJ 791 Color the fence
- nyoj 791 Color the fence
- NYOJ791 Color the fence(贪心)
- 791 Color the fence
- Color the fence(南阳oj791)(贪心+策略)
- NYOJ-Color the fence
- 南阳791 Color the fence
- nyoj color the fence
- Color the fence
- Codeforces Round #202 (Div. 2) B. Color the Fence(贪心)
- ACM Color the fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- (贪心)Color the Fence - CF 202 Div2B