【hdu5527】【2015ACM/ICPC亚洲区长春站 】Too Rich

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5527

题意&题解:

感觉自己真是弱啊,自己想的贪心是错的,根本没想到20,50的特判,╮(╯▽╰)╭

附我参考的聚聚的题解:

http://blog.csdn.net/snowy_smile/article/details/49592521

代码:

(几乎和那位聚聚的一样,ORZ)

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using 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<x)
        {
            printf("-1\n");
            continue;
        }
        ans=-1;
        vis[5]=0,vis[8]=0; solve();
        vis[5]=1,vis[8]=1; solve();
        vis[5]=1,vis[8]=0; solve();
        vis[5]=0,vis[8]=1; solve();
        printf("%d\n",ans);
    }
}
时间: 2024-11-01 23:52:07

【hdu5527】【2015ACM/ICPC亚洲区长春站 】Too Rich的相关文章

2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich

Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 245    Accepted Submission(s): 76 Problem Description You are a rich person, and you think your wallet is too heavy and full now. So yo

2015ACM/ICPC亚洲区长春站 G hdu 5534 Partial Tree

Partial Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 228    Accepted Submission(s): 138 Problem Description In mathematics, and more specifically in graph theory, a tree is an undirect

2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building

House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 145    Accepted Submission(s): 123 Problem Description Have you ever played the video game Minecraft? This game has been one of t

2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 368    Accepted Submission(s): 202 Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips

2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b

Count a * b Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 211    Accepted Submission(s): 116 Problem Description Marry likes to count the number of ways to choose two non-negative integers a

2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me

Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 186    Accepted Submission(s): 124 Problem Description The sky was brushed clean by the wind and the stars were cold in a bl

2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array

Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 447    Accepted Submission(s): 201 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort,

2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild

Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 446    Accepted Submission(s): 113 Problem Description Archaeologists find ruins of Ancient ACM Civilization, and they want to rebuild i

2015ACM/ICPC亚洲区长春站-重现赛 1006 Almost Sorted Array

Problem Description: We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. But sometimes it is an overkill to use these algorithms for an almost sorted array. We say an array