Codeforces Round #202 (Div. 2) B.Color the Fence

大坑题啊大坑题


以为过了

5

2 2 2 2 2 2 2 2 3

就对了的。


结果。。。

19

9 9 9 9 9 9 5 6 8

输出 987


哈哈哈


跟上面那种是一样的原理。先刷小的。刷不够了换一个小的加剩余的  看能不能凑一个大的

但是凑了一个大的以后呢。可能还有余数。那就还要去凑。


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#define lson num<<1,s,mid
#define rson num<<1|1,mid+1,e

using namespace std;

int a[15];
int top;
int ss[1000000];
int main()
{
    top=0;
    int n;
    scanf("%d",&n);

    int Min=99999999;
    int k;
    for(int i=1;i<=9;i++)//找最小
    {
        scanf("%d",&a[i]);
        if(Min>=a[i])
        {
            Min=a[i];
            k=i;   
        }
    }

    if(Min>n)
    {
        printf("-1\n");
        return 0;
    }

    bool found=true;
    int tmp=n%Min;

    while(found)   //凑啊凑   凑不了了就不凑
    {
        int sb=-1;
        int i;
        for(i=k+1;i<=9;i++)
        {
            if(tmp+Min>=a[i])
            {
                sb=i;
            }
        }
        if(sb==-1)found=false;
        else
        {
            tmp-=(a[sb]-Min);
            ss[top++]=sb;
        }
    }

    int ttmp=n/Min;

    if(top!=0)
    ttmp-=top;

    sort(ss,ss+top);

    //printf("top  =%d\n",top);
    for(int i=top-1;i>=0;i--)
    printf("%d",ss[i]);

    for(int i=1;i<=ttmp;i++)
    {
        printf("%d",k);
    }
    puts("");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值