浙江省西店中学NOIP初赛练习题之三(程序阅读题)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
NOIP初赛练习之三(阅读程序题)
前言:如何做阅读程序题
阅读程序题是得分的关键,因为不是让你上机去运行程序,所以要一步步地读程序,记录相关变量的值,最好以画表的形式来记录相关变量值的变化情况。
因为程序的运行结果只有输出语句才有输出,所以只写出输出语句的结果。
有时要找出规律才能写出结果,特别是循环次数多的情况,另外要注意边界值,不能多算一步也不能少算一步。
这几年的初赛题一般是四道阅读程序题,每道题8分总分为32,因此阅读程序题最能拉开分差。
{1.1996年初中组基础题第4题}{写出程序运行后变量X的值}
x1:=3;x2:=8;
for i:=1 to 5 do
begin
x:=(x1+x2)*2; x1:=x2;x2:=x;
end;
writeln('x=',x);
{2.1996年初中组第5题高中组第3题}{写出程序段运行后数组元素a1,a2...,a11的值}
a[1]:=1;a[2]:=1;k:=1;
repeat
a[k+2]:=1;
for i:=k downto 2 do a[i]:=a[i]+a[i-1];
k:=k+1;
until k>=10;
{3.1998年写程序运行结果初中组第1题高中组第1题}
program exp1(input,output);
var i,s,nax:integer;
a:array[1..10] of integer;
begin
for i:=1 to 10 do read(a[i]);
max:=a[1];s:=a[1];
for i:=2 to 10 do
begin
if s<0 then s:=0;
s:=s+a[i];
if s>max then max:=s;
end;
writeln('max=',max);
end.
{初中输入:-2 13 -1 4 7 8 -1 -18 24 6}
{ 输出:max= }
{高中输入:8 9 -1 24 6 5 11 15 -28 9}
{ 输出:max= }
{4.1998年初中组写程序运行结果第2题} program exp2(input,output}; const n=5;
var i,j,k:integer;
a:array[1..2*n,1..2*n] of integer;
begin
k:=1;
for i:=1 to 2*n-1 do
if i<=n then
if odd(i) then
for j:=i downto 1 do
begin a[i-j+1,j]:=k;k:=k+1 end
else
for j:=1 to i do begin a[i-j+1,j]:=k;k:=k+1; end
else
if odd(i) then
for j:=n downto i-n+1 do begin a[i-j+1,j]:=k;k:=k+1 end
else
for j:=i-n+1 to n do begin a[i-j+1,j]:=k;k:=k+1; end;
for i:=1 to n do
begin for j:=1 to n do write(a[i,j]:3); writeln; end;
end.
{5.1998年初中组写程序运行结果第3题高中组第
2题}
program exp3(input,output);
const n=10;
var s,i:integer;
function co(i:integer):integer;
var j1,s1:integer;
begin
s1:=n;
for j1:=(n-1) downto (n-i+1) do s1:=s1*j1 div (n-j1+1);
co:=s1;
end;
begin
s:=n+1;
for i:=2 to n do s:=s+co(i);
writeln('s=',s);
end.
{6.1998年初中组写程序运行结果第4题}
program exp4(input,output);
const n=3;
var i,j,s,x:integer;
p:array[0..n+1] of integer;
g:array[0..100] of integer;
begin
for i:=0 to 100 do g[i]:=0;
p[0]:=0;p[n+1]:=100;
for i:=1 to n do read(p[i]); readln;
for i:=0 to n do
for j:=i+1 to n+1 do
g[abs(p[j]-p[i])]:=g[abs(p[j]-p[i])]+1;
s:=0;
for i:=0 to 100 do
if g[i]>0 then begin write(i:4);s:=s+1; end; writeln;
writeln('s=',s);
writeln('input data:');readln(x);
writeln(g[x]);
end.
{ 输入: 10 20 65}
{ input data: 10}
{输出: }
{7.1998年高中组第3题}
program exp3(input,output);
var i,j:integer;
b:array[0..5] of integer;
begin
s:=1;
for i:=1 to 5 fo b[i]:=i;
j:=1;
while j>0 do
begin
j:=5;
while (j>0) and (b[j]=10+j-5) do j:=j-1;
if j>0 then
begin
s:=s+1;b[j]:=b[j]+1;
for i:=j+1 to 5 do b[i]:=b[j]+i-j
end;
end;
writeln('s=',s);
end.
{8 1998年高中组第4题}
program exp4(input, output);
const n=4;
type se=array[1..n*2] of char;
var i,j,i1,j1,k,s,t,s1,l,swap:integer;
temp:char; a:se;
begin
for i:=1 to n*2 do read(a[i]);readln;
s:=0;t:=0;
for i:=1 to n*2 do
if a[i]='1' then s:=s+1 else if a[i]='0' then t=t+1;
if s<>n or t<>n then writeln('error')
else begin
s1:=0;
for i:=1 to 2*n-1 do if a[i]<>a[i+1] then s1:=s1+1;
writeln('jamp=',s1); swap:=0;
for i:=1 to 2*n-1 do
for j:=i+1 to 2*n do
if a[i]<>a[j] then
begin
temp:=a[i];a[i]:=a[j];a[j]:=temp;
s:=0;
for l:=1 to 2*n-1 do if a[l]<>a[l]+1 then s:=s+1;
if s>swap then begin swap:=s;i1=i;j1:=j end;
temp:=a[i];a[i]:=aj]:a[j]:=temp;
end;
if swap>0 then writeln('maxswap=',swap-s1,'i=',i1,'j1=',j1); end
end.
{输入:10101100}
{9. 1999年初中组第1题}
program exp1;
var x,y,y1,jk,j1,gme:integer;
a:array [1..20] of 0..9;
begin
x:=3465;y:=264;jk:=20;
for j1:=1 to 20 do a[j1]:=0;
while y<>0 do
begin
y1:=y mod 10; y:=y div 10;
while y1<>0 do
begin
g:=x;
for e:=jk downto 1 do
begin
g:=g+a[e]; a[e]:=g mod 10; g:=g div 10; end;
y1:=y1-1;
end;
jk:=jk-1;
end;
j1=1;
while a[j1]=0 do j1:=j1+1;
for jk:=j1 to 20 do write(a[jk]:4);
writeln
end.
{10.1999年初中组第2题}
program excp1;
var i,j:integer;
a:array[1..14] of integer;
procedure sw(i1,j1:integer);
var k1:integer;
begin
for k1:=1 to (j1-i1+1) div 2 do
begin
a[i1+k1-1]:=a[i1+k1-1]+a[j1-k1+1];
a[j1-k1+1]:=a[i1+k1-1]-a[j1-k1+1];
a[i1+k1-1]:=a[i1+k1-1]-a[j1-k1+1];
end;
end;
begin
j:=211;
for i:=1 to 14 do begin a[i]:=i;j:=j-i; end;
sw(1,4);sw(5,10);sw(11,14);sw(1,14);
for i:=1 to 14 do
begin
if j mod i=1 then write(a[i]:3);
j:=j-a[i];
end;
writeln
end.
{11. 1999年高中组第2题}
设数组a[1],a[2],……a[N],已存放了数据,调用不同的排序程序,则数据比较的次数会不同。
试计算分别调用下列不同的排序过程的比较运算的次数。
其中swap(i,j)表示a[i]与a[j]交换。
(1) procedure sort1(n:integer);
var i,j:integer;
begin
for i:=1 to n-1 do
for j:=1 to n do
if a[i]<a[j] then swap(i,j);
end;
调用该过程的语句为sort1(n),比较运算的次数为:________
(2) procedure sort2(i,n:integer);
var j:integer;
begin
if i=n then write(a[n])
else for j:=i+1 to n do if a[j]<a[i] then swap(i,j);
write(a[i]);
sort(i+1,n);
end;
调用该过程的语句为sort2(0,n),比较运算的次数为:________
(3) procedure sort3(i,j:integer);
var m:integer;
begin
if i<>j then
begin m:=(i+j) div 2;
sort3(i,m);
sort3(m+1,j);
merge;{假设合并的元素分别为P、Q个,需要比较P+Q次}
end;
end;
调用该过程的语句为sort3(0,n),比较运算的次数为:________
{12. 2000年初中组第1题}
program noi_002;
var i,j,m,n,k,s,t:integer;
b:array[1..10] of 0..9;
begin
readln(m,n);
s:=m;k:=1;t:=m;
while s<n do begin k:=k+1;t:=t*m;s:=s+t end; s:=s-t;n:=n-s-1;
for i:=1 to 10 do b[i]:=0;
j:=11;
while n>0 do
begin
j:=j-1;b[j]:=n mod m; n:=n div m;
end;
for i:=10-k+1 to 10 do write(chr(ord('a')+b[i]));
end;
输入: 4 167 输出:
{13、2000年初中组第2题}
program noi_004;
var i,j,j1,j2,p,q:integer;
p1:boolean;
b,c:array[1..100] of integer;
begin
readln(p,q); j:=1;p1:=true;b[j]:=q;j1:=0;
while (q>0) and p1 do
begin
j1:=j1+1; c[j1]:=q*10 div p; q:=q*10-c[j1]*p;
if q>0 then
begin
j2:=1;
while (b[j2]<>q) and (j2<=j) do j2:=j2+1; if b[j2]=q then
begin
p1:=false;write('0.');
for i:=1 to j2-1 do write(c[i]:1);
write('{');
for i:=j2 to j1 do write(c[i]:1);
writeln('}');
end
else begin j:=j+1;b[j]:=q end;
end;
end;
if q=0 then
begin
write('0.');
for i:=1 to j1 do write(c[i]:1);
writeln
end;
readln
end.
输入: 1 8 输出:
输入: 2 7 输出:
{14、 2000年高中组第1 题}
progarm noi_003;
const n=7;m=6;
var i,j,x0,y0,x1,x2,y1,y2:integer;
d:real; p:boolean; g:array[0..n,0..m] of 0..1;
function disp(x1,y1,x2,y2:integer):real; {计算两点间距离}
begin
disp:=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
end;
begin
for i:0 to n do for j:=0 to m do g[i,j]:=0; readln(x1,y1,x2,y2);
g[x1,y1]:=1; g[x2,y2]:=1; p:=true;
while p do
begin
p:=false;
d:=disp(x1,y1,x2,y2);
x0:=x1; y0:=y1;
for i:=4 to n do
for j:=0 to m do
if (d>disp(i,j,x2,y2)) and (g[i,j]=0) then
begin
d:=disp(i,j,x2,y2); x0:=i;y0:=j; end;
if (x0<>x1) or (y0<>y1) then
begin
x1:=x0;y1:=y0;P:=true;g[x1,y1]:=1;
end;
d:=disp(x1,y1,x2,y2);x0:=x2;y0:=y2;
for i:=0 to 3 do
for j:=0 to m do
if (d<disp(x1,y1,i,j)) and (g[i,j]=0) then
begin
d:=disp(x1,y1,i,j) x0:=i;y0:=j;
end; if (x0<>x2) or (y0<>y2) then
begin x2:=x0;y2:=y0;p:=true;g[x2,y2]:=1; end;
end;
writeln(x1,y1,x2,y2);
end.
输入:7 6 0 0 输出:
{15、2003 高中组第一题}
program Program1;
var a,b,c,d,sum : longint;
begin
read(a,b,c,d);
a := a mod 23;
b := b mod 28;
c := c mo
d 33;
sum := a * 5544 + b * 14421 + c * 1228 - d;
sum := sum + 21252; sum := sum mod 21252;
if (sum = 0 ) then sum := 21252;
writeln(sum);
end.
输入:283 102 23 320 输出____________
{16、2003 高中组第二题}
program Program2;
const u : array[1..4] of integer = (0,5,3,1);
v : array[1..4] of integer = (0,7,6,5);
var a,b,c,d,e,f,x,y,z: integer;
begin
read(a,b,c,d,e,f);
z := f+ e + d + (c+3) div 4; y := 5 * d + u[c mod 4];
if (b > y) then
begin
z := z + (b - y + 8) div 9;
x := ((b - y + 8) div 9 * 9 -(b - y)) * 4 + 11 * e +
v[c mod 4];
end
else x := (y - b) * 4 + 11 * e + v[c mod 4];
if (a > x) then z := z + (a - x + 35) div 36;
writeln(z)
end.
输入: 4 7 9 20 56 47
输出____________________
{17.2003高中组第三题}
program program3;
var m,n:integer;mark:boolean;
function test(m,n:integer):integer;
var i,p:integer;flag:boolean;
begin
m:=m-1;i:=0;flag:=false;
for p:=2*n downto n+1 do
begin
i:=(i+m) mod p;
if i<n then begin test:=0;flag:=true;break; end
end;
if not flag then test:=1;
end;
begin
read(n);m:=1; mark:=false;
repeat
if test(m,n)=1 then begin writeln(m);break;end;
m:=m+1;
until mark;
end.
输入:7 输出_________
{18.2003 年高中组第四题}
var m,n,i,j:integer;
p,w,a,b:array[0..19] of integer;
begin
read(n);m:=0;
for i:=0 to n-1 do begin read(p[i]);b[i]:=1;end; for i:=0 to n-1 do
begin
if i>0 then a[m]:=p[i]-p[i-1] else a[m]:=p[i]; m:=m+1;
while (m>1) and (a[m-1]=0) do begin m:=m-1;b[m]:=1;end;
if m>0 then w[i]:=b[m-1] else w[i]:=b[0];
a[m-1]:=a[m-1]-1;
for j:=0 to m-1 do b[j]:=b[j]+1;
while (m>1) and (a[m-1]=0) do begin m:=m-1;b[m]:=1;end;
end;
for i:=0 to n-1 do
begin
write(w[i]);write(' ');
end;
writeln(' ');
end.
输入:9
4 6 6 6 6 8 9 9 9 9
输出:____________________
{19、2003初中组第一题}
var a,x,y,ok1,ok2:integer;
begin
a:=100; x:=10;y:=20;ok1:=5;ok2:=0;
if (x>y) or ((y<>20) and (ok1=0)) and (ok2<>0) then a:=1
else if (ok1<>0) and (ok2=0) then a:=-1 else a:=0;
writeln(a);
end. {20、2003初中组第三题}
var a,b,c,d,sum:longint;
begin
read(a,b,c,d);
a:=a mod 23; b:=b mod 28; c:=c mod 33;
sum:=a*5544+b*14421+c*1288-d;
sum:=sum+21252;
sum:=sum mod 21252;
if sum=0 then sum:=21252;
writeln(sum);
end.
输入: 3 9 8 6 输出:_____________
{21、2003 初中组第四题}
var a:array [0..5] of integer;
sum,n,max,i,j,k:integer;
cover:array[0..22000] of boolean;
begin
read(a[5],a[4],a[3],a[2],a[1],a[0]);
if (a[5]=0) and (a[3]=0) and (a[1]=0) then
begin
a[5]:=a[4];a[4]:=a[2];a[3]:=a[0];a[2]:=0;a[0]: =0;
end;
for i:=0 to 5 do if a[i]>10 then a[i]:=10+a[i] mod 2;
sum:=0;
for i:=0 to 5 do sum:=sum+a[i]*(6-i);
if sum mod 2<>0 then begin writeln('Can''t be divided.');exit;end;
sum:=sum div 2; max:=0; cover[0]:=true;
for i:=1 to sum*2 do cover[i]:=false;
for i:=0 to 5 do
begin
j:=0;
while (j<a[i]) do
begin
for k:=max downto 0 do
begin if cover[k] then cover[k+6-i]:=true; end;
max:=max+6-i;j:=j+1;
end;
end;
if cover[sum] then writeln('Can be divided') else writeln('Can''t be divided');
end.
输入: 9 8 4 5 6 7 输出:_____________________ 输入: 6 5 4 3 2 1 输出:___________________ 输入:20 40 60 30 10 70 输出:___________________。