博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
母函数:HDU1085 Holding Bin-Laden Captive!
阅读量:3897 次
发布时间:2019-05-23

本文共 2456 字,大约阅读时间需要 8 分钟。

Problem Description

We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“Oh, God! How terrible! ”
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!

Input

Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.

Output

Output the minimum positive value that one cannot pay with given coins, one line for one case.

Sample Input

1 1 3
0 0 0

Sample Output

4

题意就是给你价值 1 2 5的这个三种硬币的数量,然后输出最小的,用这三种硬币数量不能组成的价格

#include
#include
//#include
#include
#include
using namespace std;//Holding Bin-Laden Captive! 这还是关于母函数的问题//先创建一个结构体数组,用来存储1 2 5 和他们对应的numstruct N{
int v; int num;}n[3];int main(){
n[0].v=1; n[1].v=2; n[2].v=5; int i,j,k; //还是一样,创建一个存次数系数的数组和存中间值的数组,40是自己定的大小 int c[40]={
0}; int temp[40]={
0}; //然后输入对应的num while(scanf("%d%d%d",&n[0].num,&n[1].num,&n[2].num)!=EOF&&(n[0].num!=0&&n[1].num!=0&&n[2].num!=0)){
//对第一项赋初值 for(i=0;i<=n[0].num;i++){
//第一项的x可以等于0 到n[0].num c[i]=1; } //然后开始计算,从第二项开始,然后到第三项 for(i=1;i<=2;i++){
//这里首项是0 所以第二项是1 for(j=0;j<40;j++){
for(k=0;k+j<40&&k<=(n[i].v*n[i].num);k+=n[i].v){
//对第二项也有要求,最大值不能超过该项的硬币总价值 temp[k+j]+=c[j]; } } //然后开始赋初值 for(j=0;j<40;j++){
c[j]=temp[j]; temp[j]=0; } } //然后开始判断最小的那个,也就是从1开始,第一个系数为0的值 for(i=1;i<40;i++){
if(c[i]==0){
printf("%d\n",i); break;//并跳出循环 } continue; } }}

转载地址:http://akfen.baihongyu.com/

你可能感兴趣的文章
SAP HANA CREATE SCHEMA
查看>>
SAP HANA CREATE TABLE
查看>>
SAP HANA CREATE USER
查看>>
SAP HANA index type
查看>>
SAP HANA SQL GROUP BY / ORDER BY / OVER / CASE
查看>>
gethostbyname和gethostbyaddr的用法
查看>>
IPv6和IPv4之间的通信机制和方法
查看>>
用syslog记录UNIX日志
查看>>
syslog(),openlog(),closelog()
查看>>
Ubuntu安装后的一些配置
查看>>
ubuntu9.10 tftp服务设置(这个绝对好使)
查看>>
关于UNIXDOMAIN协议的接收发送者验证
查看>>
I/O操作上设置超时之alarm闹钟法
查看>>
查看返回接收到UDP数据包的宿地址结构--(适用于LINUX和BSD系统)
查看>>
如何开启_GNU_SOURCE宏
查看>>
从网上搜索到的一些关于pcap源代码,入门级的
查看>>
Linux—— Posix IPC
查看>>
在ubuntu下安装ACE编译环境
查看>>
公司HR面试经常问的问题及回答思路
查看>>
ACE之反应堆学习(一)
查看>>