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.
5
5 4 3 2 1 2 3 4 5
55555
2
9 11 1 12 5 8 9 10 6
33
0
1 1 1 1 1 1 1 1 1
-1
简介:先给你数字v,表示你拥有的价值,然后给你个数列a[9]代表你要写1到9这些数字的花费。问你能写的最大值;
题解:先以最小花费的数字求出最大值的长度,然后贪心去取每位数的最大值;
代码如下:
#include <stdio.h> #include <algorithm> #include <string.h> #include<iostream> #define ll long long using namespace std; const int maxn=1e5+5; int a[10]; int b[maxn]; struct node { int id,pri; double xjb; bool operator <(const node a) { if(pri!=a.pri) return pri<a.pri; else return id>a.id; } }st[10]; int v; int main() { scanf("%d",&v); for(int i=1;i<=9;i++) { scanf("%d",&a[i]); st[i].id=i; st[i].pri=a[i]; st[i].xjb=double(i)/double(a[i]); } sort(st+1,st+10);//ll ans=0; bool flag=false; int t=v/st[1].pri; int tmp=v,sd=t; for(int i=0;i<t;i++) { for(int j=9;j>=1;j--) { if((sd-1)*st[1].pri+a[j]<=tmp) { cout<<j; sd--; tmp-=a[j]; flag=true; break; } } } if(flag)cout<<endl; else cout<<-1<<endl;
题目链接http://codeforces.com/contest/349/problem/B
本文介绍了一个编程问题,即如何利用有限的油漆量在围栏上写下最大的数字来表达爱意。文章提供了问题描述、解决思路及C++实现代码。
120

被折叠的 条评论
为什么被折叠?



