[Hdu5527] [5acm/ICPC Changchun station in Asia] Too Rich

Source: Internet
Author: User

[Hdu5527] [5acm/ICPC Changchun station in Asia] Too Rich


Question and Answer:
I feel that I am really weak. I think that I am greedy and wrong. I didn't even think of the 20-50 special sentence.
Code:
(Almost the same as the one that gathers, ORZ)

#include#include#include#includeusing namespace std;int val[11]={0,1,5,10,20,50,100,200,500,1000,2000};int x,T,p,num[11],vis[11],use[11];int ans=-1;long long sum;int solve(){    memset(use,0,sizeof(use));    if (vis[5]>num[5] || vis[8]>num[8]) return 0;    long long tmp=vis[5]*val[5]+vis[8]*val[8];    int tmpn=vis[5]+vis[8];    for (int i=1;i<=10;i++)    {        if (vis[i]==-1)        {            tmp+=num[i]*val[i];            tmpn+=num[i];            use[i]=num[i];        }        else        {            use[i]=num[i]-vis[i];            if (use[i]%2==1) use[i]--;            tmpn+=use[i];            tmp+=use[i]*val[i];        }        if (tmp>=x)        {            long long chao=tmp-x;            for (int j=i;j>=1;j--)            {                if (vis[j]==-1)                {                    long long tui=min((long long)use[j],chao/val[j]);                    tmpn-=tui;                    chao-=tui*val[j];                               }                else                {                    long long tui=min((long long)use[j],chao/val[j]);                    if (tui%2==1) tui--;                                        tmpn-=tui;                    chao-=tui*val[j];                }                if (chao==0)                {                    ans=max(ans,tmpn);                    return 0;                }            }            return 0;        }    }}int main(){    scanf("%d",&T);    while(T--)    {        scanf("%d",&x);        memset(vis,-1,sizeof(vis));             for (int i=1;i<=10;i++)        {            scanf("%d",&num[i]);            sum+=num[i]*val[i];        }        if (sum

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.