Codeforces Round #202 (Div. 2) B. Color the Fence
来源:互联网 发布:nginx怎么配置ssl证书 编辑:程序博客网 时间:2024/05/22 06:07
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.
The first line contains a positive integer v (0 ≤ v ≤ 106). The second line contains nine positive integers a1, a2, ..., a9 (1 ≤ ai ≤ 105).
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.
55 4 3 2 1 2 3 4 5
55555
29 11 1 12 5 8 9 10 6
33
01 1 1 1 1 1 1 1 1
-1
先凑位数多的,再凑首个数字大的,就可以了!
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;#define M 100050struct node{ int p,i;}pri[14];bool cmp(node a,node b){ if(a.p!=b.p)return a.p<b.p; else return a.i>b.i;}int main(){ int v,i; while(scanf("%d",&v)!=EOF){ for(i=1;i<=9;i++) scanf("%d",&pri[i].p),pri[i].i=i; sort(pri+1,pri+10,cmp); int n=v/pri[1].p; if(n==0)printf("-1\n"); else { int res=v-n*pri[1].p,maxx=pri[1].i,kk=0; while(1){ int temp=-1;maxx=pri[1].i; for(i=1;i<=9;i++){ if(res+pri[1].p>=pri[i].p&&maxx<pri[i].i){ temp=i; maxx=pri[i].i; } } if(temp==-1)break; res=res-pri[temp].p+pri[1].p; printf("%d",maxx);kk++; } for(;kk<n;kk++)printf("%d",pri[1].i); printf("\n"); } } return 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
- Android 怎样获得手机信息
- MS SQL Server 索引集中说明
- POJ 3685Matrix(两次二分)
- OnEraseBkGnd() 与OnPaint()的关系,以及解决闪烁的问题
- eclipse 执行模拟器时报Re-installation failed due to different application signatures.错误。
- Codeforces Round #202 (Div. 2) B. Color the Fence
- 50条学习C++建议
- SKG多功能料理机评测
- 远程桌面登录端口号
- c#的owner
- SKG多功能料理机评测
- 大小端模式完全剖析
- SKG多功能料理机评测
- 解决Win7 Android SDK Manager不能连接下载的问题