zoukankan      html  css  js  c++  java
  • 第二篇博客,新手上路,集训挺充实的

    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

  • 相关阅读:
    通过IP地址和子网掩码与运算计算相关地址
    IP地址与子网掩码的计算
    win10用键盘控制鼠标
    requirements.txt
    vue中axios使用二:axios以post,get,jsonp的方式请求后台数据
    vue中axios使用一:axios做拦截器
    git切换分支冲突解决-删除分支
    获取指定月份前的第一天和最后一天及两个日期之间的月份列表
    git远程版本回退
    git Please move or remove them before you can merge
  • 原文地址:https://www.cnblogs.com/lhclqslove/p/7142433.html
Copyright © 2011-2022 走看看