课程练习一 Problem F id: 1005

本文探讨了一道关于使用不同面额纸币支付特定金额的问题。通过算法设计,实现了求解最少及最多纸币数量的方法,并附上了完整的C++代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*题目 Problem F id: 1005


*题意 : 给你一个价格,还有面值分别为1,5,10,50,100(单位:毛)纸币的数量,要你用最少数量的纸币和最多数量的凑出这个价格,输出最少和最多的数量。


*解题思路 :因为我们要求的是花的最多数量纸币,所以就是要保证手上的纸币数量最少!!这样想的话问题就比较简单了,就转化为最少数量问题了。假设手上总共有p毛,而价格为q毛,我们用手上最少的数量的纸币去凑(p-q)毛,然后再用总数量减去该最少数量即可。


*感想:放了几天假,忘了写了啥


*AC源码



 # include<iostream>  
 # include<cstdio>  
 # include<cstring>  
 # include<algorithm>  
 # include<cmath>  
  
 # define N 1010  
 # define ll long long  
  
using namespace std;  
  
int s,i;  
int a[7];
int b[7];
int c[7]= {0,1,5,10,50,100};
  
int main() {  
  
    int t;  
    cin>>t;  
    while(t--) {  
        scanf("%d",&s);  
        for(int i=1; i<=5; i++) {  
            scanf("%d",&a[i]);  
        }  
        int x=s;  
        int Min=0,Max=0;  
        memset(b,0,sizeof b);  
        for( i=5; i>=1; i--) {  
            if(x>=c[i]) {  
                int num=x/c[i];  
                if(num>=a[i])  
                    num=a[i];  
                Min+=num;  
                a[i]-=num;  
                b[i]=num;  
                x-=num*c[i];  
            }  
        }  
        if(x!=0)Min=-1;  
        if(Min==-1) {  
            printf("-1 -1\n");  
            continue;  
        }  
        Max=Min;  
     
        while(1) {  
            int flag=1; 
            for(int i=5; i>1; i--) {  
                if(b[i]) {
                    for(int j=i-1; j>=1; j--) {  
                        if(b[i]==0)  
                            break;  
                           
                        if(a[j]*c[j]>=c[i]) {  
                            int x=a[j]*c[j]/c[i];  
                            if(x>=b[i]) {  
                                Max=Max-b[i]+c[i]*b[i]/c[j];  
                                b[j]+=c[i]*b[i]/c[j];  
                                a[i]+=b[i];  
                                a[j]=a[j]-c[i]*b[i]/c[j];  
                                b[i]=0;  
                                flag=0;  
                            } else {  
                                Max=Max-x+c[i]*x/c[j];  
                                b[j]+=c[i]*x/c[j];  
                                a[i]+=x;  
                                a[j]=a[j]-c[i]*x/c[j];  
                                b[i]-=x;  
                                flag=0;  
                            }  
                        }  
                    }  
                }  
            }  
            if(flag)  
               break;  
        }  
        printf("%d %d\n",Min,Max);  
    }  
    return 0;  
}  


Problem F

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 161   Accepted Submission(s) : 59
Problem Description
"Yakexi, this is the best age!" Dong MW works hard and get high pay, he has many 1 Jiao and 5 Jiao banknotes(纸币), some day he went to a bank and changes part of his money into 1 Yuan, 5 Yuan, 10 Yuan.(1 Yuan = 10 Jiao)
"Thanks to the best age, I can buy many things!" Now Dong MW has a book to buy, it costs P Jiao. He wonders how many banknotes at least,and how many banknotes at most he can use to buy this nice book. Dong MW is a bit strange, he doesn't like to get the change, that is, he will give the bookseller exactly P Jiao.
 

Input
T(T<=100) in the first line, indicating the case number. T lines with 6 integers each: P a1 a5 a10 a50 a100 ai means number of i-Jiao banknotes. All integers are smaller than 1000000.
 

Output
Two integers A,B for each case, A is the fewest number of banknotes to buy the book exactly, and B is the largest number to buy exactly.If Dong MW can't buy the book with no change, output "-1 -1".
 

Sample Input
   
3 33 6 6 6 6 6 10 10 10 10 10 10 11 0 1 20 20 20
 

Sample Output
   
6 9 1 10 -1 -1
 

Statistic |  Submit |  Back

内容概要:本文档详细介绍了基于MATLAB实现多目标差分进化(MODE)算法进行无人机三维路径规划的项目实例。项目旨在提升无人机在复杂三维环境中路径规划的精度、实时性、多目标协调处理能力、障碍物避让能力和路径平滑性。通过引入多目标差分进化算法,项目解决了传统路径规划算法在动态环境和多目标优化中的不足,实现了路径长度、飞行安全距离、能耗等多个目标的协调优化。文档涵盖了环境建模、路径编码、多目标优化策略、障碍物检测与避让、路径平滑处理等关键技术模块,并提供了部分MATLAB代码示例。 适合人群:具备定编程基础,对无人机路径规划和多目标优化算法感兴趣的科研人员、工程师和研究生。 使用场景及目标:①适用于无人机在军事侦察、环境监测、灾害救援、物流运输、城市管理等领域的三维路径规划;②通过多目标差分进化算法,优化路径长度、飞行安全距离、能耗等多目标,提升无人机任务执行效率和安全性;③解决动态环境变化、实时路径调整和复杂障碍物避让等问题。 其他说明:项目采用模块化设计,便于集成不同的优化目标和动态环境因素,支持后续算法升级与功能扩展。通过系统实现和仿真实验验证,项目不仅提升了理论研究的实用价值,还为无人机智能自主飞行提供了技术基础。文档提供了详细的代码示例,有助于读者深入理解和实践该项目。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值