zoukankan      html  css  js  c++  java
  • 349B

    Color the Fence
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    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, ..., a9(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.

    Sample Input

    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升染料,有1-9个数字,写每个数字都耗费不同的燃料,问你用这些燃料最多能写出来的数字是多少
    
    #感悟:爆炸,尽然没想起来这么贪,最长的长度肯定cur=v/minv然后,枚举cur位,都尽可能的取一个最大的数
    
    */
    
    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    using namespace std;
    int a[11];
    vector<int> v;
    int n;
    int minv=INF;
    int mini;
    int cur;
    int main(){
        // freopen("in.txt","r",stdin);
        v.clear();
        scanf("%d",&n);
        for(int i=0;i<9;i++){
            scanf("%d",&a[i]);
            if(a[i]<=minv){
                minv=a[i];
                mini=i;
            }
        }
        cur=n/minv;
        if(cur==0){
            puts("-1");
            return 0;
        }
        int res=0;
        for(int i=0;i<cur;i++){//查找每一位
            for(int j=8;j>=0;j--){
                //每一位都找最大的
                if(n<=minv){
                    v.push_back(mini+1);
                    break;
                }
                if(a[j]>n) continue;
                if( (n-a[j])/minv+v.size()+1==cur){
                    res+=a[j];
                    v.push_back(j+1);
                    n-=a[j];
                    break;
                }
            }
        }
        for(int i=0;i<v.size();i++){
            printf("%d",v[i]);
        }
        printf("
    ");
        return 0;
    }
  • 相关阅读:
    js打印指定元素内容
    c# RedisHelper
    T4生成整理
    T4随记
    c# 文本超长截断
    mysql自动安装教程说明
    完全卸载mysql免安装版
    解决WebClient或HttpWebRequest首次连接缓慢问题
    c# 停靠窗体
    c#透明panel
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6574817.html
Copyright © 2011-2022 走看看