zoukankan      html  css  js  c++  java
  • E 钱币兑换问题

     
     
     
    在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法

    Input每行只有一个正整数N,N小于32768。

    Output对应每个输入,输出兑换方法数。

    Sample Input

    2934
    12553

    Sample Output

    718831
    13137761


    题解:首先都会想到循环,但是只要控制不好都会超时,我的想法是,将循环次数控制到最小;
    首先大循环以三分为基础,剩下就是分配给二分和一分,因为有一分,所以肯定可以分完,
    只要求出两分的有几种就可以,剩下的一分肯定能补齐;代码:
    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<cstdio>
    using namespace std;
    const int MS = 32768/2;
    
    
    int main(){
    
    
     int n;
     while(cin>>n){
        int cnt=0;
        int MA=n/3;
        for(int i=0;i<=MA;i++){
    
            int MZ=(n-i*3);
    
                cnt+=(MZ/2+1);
    
    
        }
    
        cout<<cnt<<endl;
     }
    
    
    
    
    }




    #include<iostream>#include<cmath>#include<cstring>#include<string>#include<cstdio>usingnamespacestd; constint MS = 32768/2; int main(){ int n; while(cin>>n){ int cnt=0; int MA=n/3; for(int i=0;i<=MA;i++){ int MZ=(n-i*3); cnt+=(MZ/2+1); } cout<<cnt<<endl; } }

  • 相关阅读:
    C++高精度乘法
    经典的7种排序算法 原理C++实现
    c++ STL
    二分查找c++
    洛谷P1111 修复公路
    01背包写法
    c++编码规范
    github教程
    windows10锁定屏幕聚焦图片导出
    week 6 Spring history and design philosophy
  • 原文地址:https://www.cnblogs.com/xuyibao/p/7109693.html
Copyright © 2011-2022 走看看