第二篇博客,新手上路,集训挺充实的

本文介绍了一个编程问题,即如何利用有限的油漆量在围栏上写下最大的数字来表达爱意。文章提供了问题描述、解决思路及C++实现代码。
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, ..., a(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

简介:先给你数字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

 

 

转载于:https://www.cnblogs.com/lhclqslove/p/7142433.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值