HDOJ水题集合9

Solved Problem ID Title Ratio(Accepted / Submitted)
1001 国王陛下的货币改革 86.36%(19/22)
1002 选课时间 66.67%(12/18)
1003 喜欢数学的洪药师 25.00%(4/16)
1004 Holding Bin-Laden Captive! 61.54%(8/13)

1001 国王陛下的货币改革

国王陛下的货币改革
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 22 Accepted Submission(s) : 19
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
小胖子李翰阳越来越胖了!

我们形容一个人胖的时候,经常会说“胖得像个球!”,但是李翰阳却越胖越“方”。

因为这事比较稀奇,以至于惊动了轰动了整个银河系,都在传说地球出了个奇人。

当然,惊动的也包括火星人,于是他们绑架了李翰阳,逼迫他做国王。

但是,小胖子李翰阳对当国王并不感兴趣,他只想回到地球,回到杭州,回到丁爸信奥班…

不过,什么困难都难不倒地球人,李翰阳决定以国王的名义胡乱改革,他想让火星人觉得国王是个废物,也许就会放了他。

李翰阳首先启动的就是货币改革。

因为自己是“方”的,他就把火星的硬币做成了正方形,并且面值也是“平方数”,具体的说,所有的硬币一共有17种,分别是1-17的平方,即:1元、 4元

、 9元、 16元 … 289元。

比如,一个火星人想支付10元钱,那么他有四种支付方式:
支付10个一元的硬币;
支付1个四元的硬币+6个一元的硬币;
支付2个四元的硬币+2个一元的硬币;
支付1个九元的硬币+1个一元的硬币;

现在想知道,如果火星人想支付N元钱,会有多少种不同的支付方式呢?
Input
输入包含多组测试用例,每组一个整数N(N<=300),N为0的时候表示输入的结束,不做处理。
Output
对于每组测试数据,请输出火星人可以支付的方案数,每组数据输出一行。
Sample Input
2
10
30
0
Sample Output
1
4
27

Hint
欲知翰阳国王能否成功回归地球,且待下回分解~

#include<bits/stdc++.h>
using namespace std;
const int maxn = 310;
int a[maxn], b[maxn], c[maxn];
int f[18];
int main(){
	for(int i = 1; i <= 17; i++)f[i]=i*i;
	for(int i = 0; i < maxn; i++)a[i] = 1;
	for(int i = 2; i <= 17; i++){
		for(int j = 0; j < maxn; j++){
			for(int k = 0; k+j < maxn; k += f[i]){
				b[j+k] += a[j];
			}
		}
		for(int j = 0; j < maxn; j++){
			a[j] = b[j];  b[j] = 0;
		}
	}
	
	int n;
	while(cin>>n &&n){
		cout<<a[n]<<"\n";
	}
	return 0;
}

1002 选课时间

选课时间
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 18 Accepted Submission(s) : 12
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合。你来帮帮他吧。(xhd认为一样学分的课没区别)
Input
输入数据的第一行是一个数据T,表示有T组数据。
每组数据的第一行是两个整数n(1 <= n <= 40),k(1 <= k <= 8)。
接着有k行,每行有两个整数a(1 <= a <= 8),b(1 <= b <= 10),表示学分为a的课有b门。
Output
对于每组输入数据,输出一个整数,表示学n个学分的组合数。
Sample Input
2
2 2
1 2
2 1
40 8
1 1
2 2
3 2
4 2
5 8
6 9
7 6
8 8
Sample Output
2
445
Author
xhd
Source
ACM程序设计期末考试_热身赛(感谢 xhd & 8600)

//多重背包方案数,重量a的物品有b件
#include<bits/stdc++.h>
using namespace std;
int f[110];
int main(){
	int T;  cin>>T;
	while(T--){
		int n, m;  cin>>n>>m;
		memset(f,0,sizeof(f));
		f[0] = 1;
		for(int i = 1; i <= m; i++){
			int a, b;  cin>>a>>b;
			for(int j = n; j >= a; j--){
				for(int k = 1; k <= b; k++){
					if(k*a>j)break;
					f[j] += f[j-k*a];
				}
			}
		}
		cout<<f[n]<<"\n";
	}
	return 0;
}




1003 喜欢数学的洪药师

喜欢数学的洪药师
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 16 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
洪熹林,曾经的数学爱好者,现在的药剂师,浙江省中医院的药剂师,同事们尊称其为“洪药师”。

洪药师每天的任务就是帮病人的中药称重,貌似很乏味。但是,平凡的日子并不能阻止他那颗高贵的心。

看着眼前的N个天平砝码,喜爱数学的洪药师冒出来一个问题:

假设所有砝码的重量之和是S,那么在[1,S]的范围内,哪些重量是无法用天平称出来呢?
Input
输入包含多组测试用例。
每组测试用例的第一行是一个正整数N (1<=N<=100),表示有N个砝码。
接下来一行是N个整数Ai(1<=i<=N),分别表示N个砝码的重量,1<=Ai<=100。
Output
对于每组测试数据,请首先输出不能称出的重量的个数,如果个数不为0,然后接下来一行请输出所有不能称的重量,数据空格隔开,升序排列。
Sample Input
3
1 2 4
3
9 2 1
Sample Output
0
2
4 5

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4+10;
int n, a[110], sum;
int vis[maxn], tmp[maxn];//vis表示当前能称得出来的重量
int main(){
	while(cin>>n){
		memset(vis,0,sizeof(vis));
		memset(tmp,0,sizeof(tmp));
		sum = 0;
		for(int i = 1; i <= n; i++){
			cin>>a[i];  sum += a[i];
		}
		vis[0] = vis[a[1]] = 1;
		for(int i = 2; i <= n; i++){
			for(int j = 0; j <= sum; j++){
				int c1 = j+0, c2 = abs(j-a[i]), c3=j+a[i];//选|不选
				tmp[c1] += vis[j];//如果j称的出来,那么加上a[i]就可以称出来
				tmp[c2] += vis[j];
				tmp[c3] += vis[j];
			}
			for(int j = 0; j <= sum; j++){
				vis[j] = tmp[j];
				tmp[j] = 0;
			}
		}
		vector<int>ans;
		for(int i = 0; i <= sum; i++)
			if(!vis[i])ans.push_back(i);
		if(ans.size()==0){
			cout<<0<<"\n";
			continue;
		}
		cout<<ans.size()<<"\n";
		for(int i = 0; i < ans.size(); i++){
			if(i!=0)cout<<" ";
			cout<<ans[i];
		}
		cout<<"\n";
	}
	return 0;
}



1004 Holding Bin-Laden Captive!

Holding Bin-Laden Captive!
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 8
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
Author
lcy

//给出面值1,2,5的硬币a,b,c枚,求不能支付的最小正数
//分类讨论:a==0肯定是1。当a+2b小于4时完全用不到5,直接加一即可,否则就是全都用上。
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	while(cin>>a>>b>>c){
		if(a==0&&b==0&&c==0)break;
		if(a==0)cout<<"1\n";
		else if(a+2*b<4)cout<<a+2*b+1<<"\n";
		else cout<<a+2*b+5*c+1<<"\n";
	}
	return 0;
}




评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小哈里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值