zoukankan      html  css  js  c++  java
  • The 15th UESTC Programming Contest Preliminary C

    地址: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;
    }

     

  • 相关阅读:
    Linux内核中的双向链表struct list_head
    Linux文件的基本操作函数
    Ubuntu下载源码并编译
    Ubuntu搭建交叉编译开发环境
    终端下更改printk打印级别
    进程内存分配
    程序的内存分配
    C语言数据类型char
    RSA算法原理(简单易懂)
    常见复杂指针声明的解析(很详细)
  • 原文地址:https://www.cnblogs.com/weeping/p/6632158.html
Copyright © 2011-2022 走看看