The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554

地址:http://acm.uestc.edu.cn/#/problem/show/1554

题目:

C0ins

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

There are infinite coins with values 1,2,5,101,2,5,10.

What's the minimum numbers of coins should be picked that XX and YY can be made change for?

Input

Two integers XX and YY. (1X,Y1091≤X,Y≤109)

Output

The minimum numbers of coins should be picked.

Sample input and output

Sample InputSample Output
8 9
4

Hint

In sample, four coins 1,2,2,51,2,2,5 and 1,1,2,51,1,2,5 both can make change for 88 and 99.

Source

The 15th UESTC Programming Contest Preliminary
 
#include<iostream>
#include<algorithm>
using namespace std;

long long a,b,aa,bb,ans1,ans2,ans110,ans15,ans12,ans11,ans210,ans25,ans22,ans21;

int check(int a,int b)
{
    long long aa,bb,ans1,ans2,ans110,ans15,ans12,ans11,ans210,ans25,ans22,ans21;
    aa=bb=ans1=ans2=ans110=ans15=ans12=ans11=ans210=ans25=ans22=ans21=0;
    aa=a,bb=b;
    if(a<0||b<0)
        return 10000;
    ans110+=a/10;
    a%=10;
    ans15+=a/5;
    a%=5;
    ans12+=a/2;
    a%=2;
    ans11+=a;
    ans210+=b/10;
    b%=10;
    ans25+=b/5;
    b%=5;
    ans22+=b/2;
    b%=2;
    ans21+=b;
    ans1=max(ans110,ans210)+max(ans15,ans25)+max(ans12,ans22)+max(ans11,ans21);
    ans2=ans110+ans15+ans11+ans12;
    bb-=aa;
    ans2+=bb/10;
    bb%=10;
    ans2+=bb/5;
    bb%=5;
    ans2+=bb/2;
    bb%=2;
    ans2+=bb;
    return min(ans2,ans1);
}

int main()
{
    cin>>a>>b;
    if(a>b)
        swap(a,b);
    cout<<min(check(a,b),check(a-6,b-14)+4);
    return 0;
}

 

转载于:https://www.cnblogs.com/weeping/p/6632158.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值