1 / 11

题 1030 : 买小猫小狗

题 1030 : 买小猫小狗 某动物饲养中心用 X 元专款购买小狗 ( 每只 A 元 ) 和小猫 ( 每只 B 元 ) 两种小动物。 要求专款专用 ,( 至少 猫狗各一 ), 正好用完 ? 请求出方案的总数。如没有请输出 0. Input 输入一行,只有三个整数 . 分别为 X,A,B. ( 100 < X < 32768; 1 <= A, B <= 100 ) Output 输出只有一行(这意味着末尾有一个回车符号),包括 1 个整数。 Sample Input 1700 31 21. 正好用完. 至少 猫狗各一.

gypsy
Download Presentation

题 1030 : 买小猫小狗

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 题1030:买小猫小狗 某动物饲养中心用X元专款购买小狗(每只A元)和小猫(每只B元)两种小动物。 要求专款专用,(至少猫狗各一),正好用完?请求出方案的总数。如没有请输出0. Input 输入一行,只有三个整数.分别为X,A,B. ( 100 < X < 32768; 1 <= A, B <= 100 ) Output 输出只有一行(这意味着末尾有一个回车符号),包括1个整数。 Sample Input 1700 31 21 正好用完 至少猫狗各一 n:=x div a; {x元全部买小狗,能买n只} for i:=1 to n do {如果买i只小狗} if ((x-a*i) mod b=0) and ((x-a*i) div b >=1) then sum:=sum+1; 小猫的个数要符合两个条件,一个买小狗剩下的钱刚好用完,另一个小猫的个数要至少一只以上

  2. ( 100 < X < 32768; 1 <= A, B <= 100 ) for i:=1 to x div a do {买小狗所有可能的只数} for j:=1 to x div b do {买小狗所有可能的只数} i*a+j*b=x then inc(t) 符合条件的组合的个数 10^8 超时

  3. 题1027:兑换硬币 Description 用一张一元票换1分、2分和5分的硬币,每种至少一枚, 问有几种换法. Input 无 Output 输出只有一行(这意味着末尾有一个回车符号),包括1个整数。 一元=100分

  4. program ex27;var i,j,k,t:integer;begin  t:=0;  for i:=1 to 100 do   for j:=1 to 50 do  for k:=1 to 20 doif i+j+2+k*5=100 then inc(t);  write(t); end. program ex27;var i,j,k,t:integer;begin  t:=0;  for i:=1 to 100 do   for j:=1 to 50 do  for k:=1 to 20 doif i*0.01+j*0.02+k*0.05=1  then inc(t);  write(t); end. 所有的计算要换成二进制,计算过程会产生误差,x*x-x=0 x*x-x<0.00001 695 404

  5. 计算机不仅限制了实数的范围,也限制了实数的运算精度。计算机不仅限制了实数的范围,也限制了实数的运算精度。   例如某台计算机系统最多可提供七位十进制的有效数字,那么当运算结果超过七位时,就会产生舍入误差。如:某一算术运算结果应为123.45678,机器的实际输出为123.4568,最后一位8被进位了。因此我们在进行实型数的运算时往往会出现误差,这也是整型数和实型数的根本区别之一。   255 用十进制表示,3位 用2进制表示,多少位? 1 1 2 10

  6. 8位一个字节 integer -32768..32767 2   带符号16位 longint-2147483648..2147483647 4   带符号32位

  7. 类型        数值范围     占字节数  格式shortint-128..1271   带符号8位integer-32768..327672   带符号16位longint-2147483648..2147483647   4   带符号32位byte0..2551   带符号8位word0..655352   带符号16位 类型         数值范围    占字节数  有效位数real2.9e-39..1.7e386         11..12single1.5e-45..3.4e384           7..8double5.0e-324..1.7e3088   15..16extended3.4e-4932..1.1e493210        19..20comp-2^63+1..2^63-18         19..20

  8. program pzf; var i,n:integer; a,s,p:real; begin readln(n); s:=0; for i:=1 to n do begin read(a); s:=s+a; end; p:=s/n; writeln(s:0:2); write(p:0:2); end. 输入n个学生的某门课程的成绩,输出总分与平均分 输入n个同学与成绩 输出总分与平均分 样例: 输入: 4 67.5 80 90 45.5 输出:283.00 70.75 p i a s 如果要输出所有小于平均分的成绩,程序应当如何改?

  9. a1 a2 a3 … an 数组 名字相同下标不同的一组数数组 a[1] a[2] a[3] … a[n]

  10. n<=10 program pzf; var i,n:integer; s,p:real; a:array[1..10] of real; begin readln(n); s:=0; for i:=1 to n do begin read(a[i]); s:=s+a[i]; end; p:=s/n; for i:=1 to n do if a[i]<p then write (a[i] :6:2); end. 输入n个学生的某门课程的成绩,输出总分与平均分 a[1] a[2] a[3] ……

  11. A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] A[10] 56 21 15 98 5 90 56 23 19 20 作业:读入10个数,完成以下操作,2-10依次向前移动,第一个数,放到第十个位置上,最后输出调整后的10个数

More Related