codeforces 349B Color the Fence 贪心,思维

时间:2023-03-08 21:13:15
codeforces 349B   Color the Fence   贪心,思维

1、codeforces 349B    Color the Fence

2、链接:http://codeforces.com/problemset/problem/349/B

3、总结:

刷栅栏。1-9每个字母分别要ai升油漆,问最多可画多大的数字。

贪心,也有点考思维。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f int main()
{ int v,a[];
while(~scanf("%d",&v))
{
int m=;
for(int i=;i<=;i++)
{
scanf("%d",&a[i]);
if(a[m]>a[i])m=i;
} int num=v/a[m]; //求出最多有多少个数字
if(num==)puts("-1");
else
{
for(int i=;i<num;i++) //循环num次,每次输出可得到的最大的那个
{
v%=a[m];
for(int j=;j>=m;j--)
{
if((a[j]-a[m])<=v){ //如符合多出的小于余下的,就输出
v-=(a[j]-a[m]);
printf("%d",j);
break;
} }
}
printf("\n");
}
} return ;
}