zoukankan      html  css  js  c++  java
  • Codeforces Round #202 (Div. 2) B. Color the Fence

    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.

    原题链接 http://codeforces.com/contest/349/problem/B

    (1) 题目大意 

    给你一个maxmoney,代表能用的最大钱数,之后给你1-9每位需要花的钱数,问能组成最大的数是多少

    (2)思路

    我的思路就是先贪心位数最大

    然后从首位开始从新贪心,用剩余的钱数去尽可能买数字大的,

    贴代码了(通俗易懂

     1 #include <algorithm>
     2 #include <stack>
     3 #include <istream>
     4 #include <stdio.h>
     5 #include <map>
     6 #include <math.h>
     7 #include <vector>
     8 #include <iostream>
     9 #include <queue>
    10 #include <string.h>
    11 #include <set>
    12 #include <cstdio>
    13 #define FR(i,n) for(int i=0;i<n;i++)
    14 #define MAX 2005
    15 #define mkp pair <int,int>
    16 using namespace std;
    17 const int maxn = 1e6+5;
    18 typedef long long ll;
    19 const int  inf = 0x3fffff;
    20 void read(int  &x) {
    21     char ch; bool flag = 0;
    22     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
    23     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
    24     x *= 1 - 2 * flag;
    25 }
    26 
    27 int n,arr[1005];
    28 int ans[maxn],top = 0;
    29 int main() {
    30     read(n);
    31     int minn = 10000000;
    32     int id = 0;
    33     for(int i=1;i<=9;i++){
    34         read(arr[i]);
    35         if(minn>arr[i]){
    36             minn = arr[i];
    37             id = i;
    38         }
    39     }
    40     //cout<<1<<endl;
    41     if(n<minn){return 0*printf("-1
    ");}
    42     top = n/minn;
    43     for(int i=0;i<top;i++)ans[i]=id;
    44     int last = n-top*minn;
    45     for(int i=0;i<top;i++)
    46     {
    47         last  += arr[ans[i]];
    48         bool an= 1;
    49         for(int j=9;j>=1;j--){
    50             if(last>=arr[j]){
    51                 ans[i]=j;
    52                 an = 0;
    53                 last-=arr[j];
    54                 break;
    55             }
    56         }
    57         if(an)break;
    58        // last-=arr[ans[i]];
    59     }
    60     for(int i=0;i<top;i++){
    61         printf("%d",ans[i]);
    62     }
    63     return 0;
    64 }
    我身后空无一人,我怎敢倒下
  • 相关阅读:
    Web网页数据抽取软件的设计与实现
    以Groovy的方式更稳定地解析HTML(转载)
    HTML 资讯汲取(上篇) 使用 JDOM 、 TagSoup 及 XPath
    html解析
    HTML 資訊汲取(下篇) TagSoup 輸出 namespace 問題的解決方案
    国外免费主机空间
    ASP.NET获取客户端IP地址、系统版本、浏览器版本
    阁下莫非就是当年华山论剑武功独步天下罕有其匹号称一朵梨花压海棠的少林寺智障大师收养的小沙弥低能的爱犬旺财踩扁的蟑螂小强曾滚过的一个粪球?
    html中table里的col标签
    Visual Studio 2010 中的 TODO
  • 原文地址:https://www.cnblogs.com/DreamKill/p/9388169.html
Copyright © 2011-2022 走看看