ACM程序设计与竞赛作业 下载本文

内容发布更新时间 : 2024/5/13 10:56:04星期一 下面是文章的全部内容请认真阅读。

while(scanf(\实现多行实例输入; {

for(i=0;i

if(sum==j) m++;//如果是完数,统计其个数; } printf(\ } } return 0; }

心得:这个题主要考察了输入输出和循环问题,用while语句实现多行输入,首先输入两个数,判断这两个数之间的数(包括这两个数)是不是完数,如果是完数,则记录这两个数之间完数的个数,然后输出。

24问题 C: Fibbonacci Number _Hdu 2070 时间限制: 1 Sec 内存限制: 128 MB

提交: 291 解决: 164 [提交][状态][讨论版]

题目描述

Your objective for this question is to develop a program which will generate a fibbonacci number. The fibbonacci function is defined as such:

f(0) = 0 f(1) = 1

f(n) = f(n-1) + f(n-2)

Your program should be able to handle values of n in the range 0 to 50

输入

Each test case consists of one integer n in a single line where 0≤n≤50. The input is terminated by -1.

输出

Print out the answer in a single line for each test case.

样例输入

3 4 5 -1

样例输出

2 3 5

提示

#include int main() { float a[51];//定义一个浮点型一维数组; int n; a[0]=0;a[1]=1;

while(scanf(\实现多行实例输入,当n等于-1时结束; { for(int i=2;i<=50;++i) a[i]=a[i-1]+a[i-2];//根据公式求出结果; printf(\

}

return 0; }

心得:这个题考察输入与输出,还有首先定义一个浮点型一位数组,数组中第一个第二个数分别赋值为0和1,用while语句实现多行实例输入,然后执行for循环,根据公式算出所要求的结果,然后输出结果。

25问题 A: Packets

时间限制: 1 Sec 内存限制: 128 MB

提交: 37 解决: 9 [提交][状态][讨论版]

题目描述

A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.

输入

输入每行6个整数,空格分开,第1到第6位为1*1,2*2,。。。6*6盒子的个数。当输入为6个0时结束。

输出

输出每行一个整数,表示需要的盒子数。

样例输入

0 0 4 0 0 1 7 5 1 0 0 0 0 0 0 0 0 0

样例输出

2 1

提示

#include #include #include int num[4]={0,5,3,1}; int box[7]; int main() {

//freopen(\ while(1){

int tmp=0;

for(int i=1;i<=6;i++){

scanf(\ // 读入每个物品的数目 tmp+=box[i]; }

if(tmp==0) break;

int ans=box[6]+box[5]+box[4]+(box[3]+3)/4; //a6,a5,a4,每个物品占有一个箱子(a3 + 3 ) / 4 代表a3的物品需要占

int a2=box[4]*5+num[box[3]%4]; //统计所有的大物品放进箱子中后a2物品的空位子有多少

if(box[2]>a2)

ans+=(box[2]-a2+8)/9;

int a1=ans*36-box[6]*36-box[5]*25-box[4]*16-box[3]*9-box[2]*4; if(box[1]>a1) //求a1的空位子,只需要统计剩余的面积即可 ans+=(box[1]-a1+35)/36; printf(\ }

return 0; }

心得:对于6*6以及4*4尺寸的物品每个物品需要占有一个箱子,对于3*3的物品一个箱子可以放4个,2*2的物品箱子可以放9个,1*1的可以放36个,采用面积统计1*1箱子的空位,采用向上去整的方法统计箱子。