读书人

Codeforces Round #202 (Div. 二) B

发布时间: 2013-09-29 11:07:08 作者: rapoo

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,eusing 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;}


1楼u0112627228小时前
看你写的就想笑。。。每篇都搞笑。。。

读书人网 >编程

热点推荐