NOIP2013初赛提高组Pascal试题及答案

上传人:xgs****56 文档编号:10799287 上传时间:2020-04-14 格式:DOC 页数:13 大小:216KB
返回 下载 相关 举报
NOIP2013初赛提高组Pascal试题及答案_第1页
第1页 / 共13页
NOIP2013初赛提高组Pascal试题及答案_第2页
第2页 / 共13页
NOIP2013初赛提高组Pascal试题及答案_第3页
第3页 / 共13页
点击查看更多>>
资源描述
第十九届全国青少年信息学奥林匹克联赛初赛提高组 Pascal 语言试题竞赛时间:2013 年 10 月 13 日 14:3016:30选手注意:l试题纸共有 12 页,答题纸共有 2 页,满分 100 分。请在答题纸上作答,写在试题纸上 的一律无效。l不得使用任何电子设备(如计算器、手机、电子词典等)或查阅任何书籍资料。一、单项选择题(共 15 题,每题 1.5 分,共计 22.5 分;每题有且仅有一个正确 选项)1.一个 32 位整型变量占用()个字节。A.4B.8C.32D.1282.二进制数 11.01 在十进制下是()。A.3.25B.4.125C.6.25D.11.1253.下面的故事与()算法有着异曲同工之妙。从前有座山,山里有座庙,庙里有个老和尚在给小和尚讲故事:从前有座山,山 里有座庙,庙里有个老和尚在给小和尚讲故事:从前有座山,山里有座庙,庙里有个 老和尚给小和尚讲故事.A.枚举B.递归C.贪心D.分治4.1948 年,()将热力学中的熵引入信息通信领域,标志着信息论研究的开端。A.冯诺伊曼(John von Neumann)B.图灵(Alan Turing)C.欧拉(Leonhard Euler)D.克劳德香农(Claude Shannon)5.已知一棵二叉树有 2013 个节点,则其中至多有()个节点有 2 个子节点。A.1006B.1007C.1023D.10246. 在一个无向图中,如果任意两点之间都存在路径相连,则称其为连通 图。右图是一个有 5 个顶点、8 条边的连通图。若要使它不再是连通 图,至少要删去其中的( )条边。CCF NOIP2013 初赛提高组 Pascal 语言试题第 13 页,共 12 页A.2B.3C.4D.57.斐波那契数列的定义如下:F1 = 1, F2 = 1, Fn = Fn 1 + Fn 2 (n 3)。如果用下面的函数计 算斐波那契数列的第 n 项,则其时间复杂度为()。funtion F(n : longint) : longint;beginif n 100 do beginsum := sum + i;inc(i);end;C.i := 1;repeatsum := sum + i;inc(i);until i 100;D.i := 1;repeatsum := sum + i;inc(i);until i = 100;2.()的平均时间复杂度为 O(n log n),其中 n 是待排序的元素个数。A.快速排序B.插入排序C.冒泡排序D.归并排序3.以 A0 作为起点,对下面的无向图进行深度优先遍历时(遍历的顺序与顶点字母的下标 无关),最后一个遍历到的顶点可能是()。A.A1B.A2C.A3D.A44.()属于 NP 类问题。A.存在一个 P 类问题B.任何一个 P 类问题C.任何一个不属于 P 类的问题D.任何一个在(输入规模的)指数时间内能够解决的问题5.CCF NOIP 复赛考试结束后,因()提出的申诉将不会被受理。A.源程序文件名大小写错误B.源程序保存在指定文件夹以外的位置C.输出文件的文件名错误D.只提交了可执行文件,未提交源程序三、问题求解(共 2 题,每题 5 分,共计 10 分;每题全部答对得 5 分,没有部 分分)1.某系统自称使用了一种防窃听的方式验证用户密码。密码是 n 个数 s1, s2, , sn,均为 0或 1。该系统每次随机生成 n 个数 a1, a2, , an,均为 0 或 1,请用户回答(s1a1 + s2a2 + + snan)除以 2 的余数。如果多次的回答总是正确,即认为掌握密码。该系统认为,即使 问答的过程被泄露,也无助于破解密码因为用户并没有直接发送密码。然而,事与愿违。例如,当 n = 4 时,有人窃听了以下 5 次问答:问答编号系统生成的 n 个数掌握密码的用户的回答a1a2a3a4111001200110301100411100510000就破解出了密码 s1 = ,s2 = ,s3 = ,s4 = 。2. 现有一只青蛙,初始时在 n 号荷叶上。当它某一时刻在 k 号荷叶上时,下一时刻将等概 率地随机跳到 1, 2, , k 号荷叶之一上,直至跳到 1 号荷叶为止。当 n = 2 时,平均一共 跳 2 次;当 n = 3 时,平均一共跳 2.5 次。则当 n = 5 时,平均一共跳 次。12345四、阅读程序写结果(共 4 题,每题 8 分,共计 32 分)1.varn, i : integer; str : string; isPlalindrome : boolean;begin readln(str);n := Length(str);isPlalindrome := true;for i := 1 to (n div 2) do beginif (stri strn-i+1) thenisPlalindrome := false;end;if (isPlalindrome) then writeln(Yes)elsewriteln(No);end.输入:abceecba输出: 2.vara, b, u, v, i, num : integer;beginreadln(a, b, u, v);num := 0;for i := a to b do beginif (i mod u = 0) or (i mod v = 0) then inc(num);end;writeln(num);end.输入:1 1000 10 15输出: 3.const SIZE = 100;varn, ans, i, j : integer;height, num : array1.SIZE of integer;begin read(n);for i := 1 to n do beginread(heighti);numi := 1;for j := 1 to i-1 do beginif (heightj = numi) thennumi := numj+1;end;end;ans := 0;for i := 1 to n do beginif (numi ans) thenans := numi;end;writeln(ans);end.输入:83 2 5 11 12 7 4 10输出: 4.const SIZE = 100;varn, m, p, count, ans, x, y, i, j : integer;a : array1.SIZE, 1.SIZE of integer;procedure colour(x, y : integer);begin inc(count); axy := 1;if (x 1) and (ax-1y = 0) then colour(x-1, y);if (y 1) and (axy-1 = 0) thencolour(x, y-1);if (x n) and (ax+1y = 0) then colour(x+1, y);if (y m) and (axy+1 = 0) thencolour(x, y+1);end;beginfillchar(a, sizeof(a), 0);readln(n, m, p); for i := 1 to p do beginread(x, y);axy := 1;end;ans := 0;for i := 1 to n dofor j := 1 to m doif aij = 0 then begincount := 0;colour(i, j);if (ans count) then ans := count;end;writeln(ans);end.输入:65 9142324324143455464输出: 五、完善程序(第 1 题 15 分,第 2 题 13 分,共计 28 分)1.(序列重排)全局数组变量 a 定义如下:const int SIZE = 100;int aSIZE, n;它记录着一个长度为 n 的序列 a1, a2, , an。现在需要一个函数,以整数 p (1 p n)为参数,实现如下功能:将序列 a 的前 p 个数与后 n p 个数对调,且不改变这 p 个数(或 n p 个数)之间的相对位置。例如, 长度为 5 的序列 1, 2, 3, 4, 5,当 p = 2 时重排结果为 3, 4, 5, 1, 2。有一种朴素的算法可以实现这一需求,其时间复杂度为 O(n)、空间复杂度为 O(n):procedure swap1(p : longint);vari, j : longint;b : array1.SIZE of longint;beginfor i := 1 to p dob(1) := ai;/(2 分)for i := p + 1 to n do bi - p := ai;for i := 1 to n doai := bi;end;我们也可以用时间换空间,使用时间复杂度为 O(n2)、空间复杂度为 O(1)的算法:procedure swap2(p : longint);vari, j, temp : longint;beginfor i := p + 1 to n do begintemp := ai;for j := i downto(4)do/(2 分)aj := aj - 1;(5):= temp;/(2 分)end;end;事实上,还有一种更好的算法,时间复杂度为 O(n)、空间复杂度为 O(1):procedure swap3(p : longint);varstart1, end1, start2, end2, i, j, temp : longint;beginstart1 := 1;end1 := p;start2 := p + 1;end2 := n; while true do begini := start1;j := start2;while (i = end1) and (j = end2) do begintemp := ai;ai := aj;aj := temp; inc(i); inc(j);end;if i = end1 then start1 := ielse if(4)then/(3 分)beginstart1 := (5) ; /(3 分) end1 := (6) ; /(3 分) start2 := j;end elsebreak;end;end;2. (两元序列)试求一个整数序列中,最长的仅包含两个不同整数的连续子序列。如有多 个子序列并列最长,输出任意一个即可。例如,序列“1 1 2 3 2 3 2 3 3 1 1 1 3 1”中, 有两段满足条件的最长子序列,长度均为 7,分别用下划线和上划线标出。program two;const SIZE = 100;varn, i, j, cur1, cur2, count1, count2, ans_length, ans_start, ans_end : longint;/cur1, cur2 分别表示当前子序列中的两个不同整数/count1, count2 分别表示 cur1, cur2 在当前子序列中出现的次数a : array1.SIZE of longint;begin readln(n);for i := 1 to n do read(ai);i := 1;j := 1;/i, j 分别表示当前子序列的首尾,并保证其中至多有两个不同整数while (j = n) and (aj = ai) do inc(j);cur1 := ai;cur2 := aj;count1 :=(1);/(3 分)count2 := 1;ans_length := j - i + 1;while j 0 do beginif ai = cur1 then dec(count1)elsedec(count2);inc(i);end;cur2 := aj;count2 := 1;endelse beginwhile count1 0 do beginif ai = cur1 then(3)/(2 分)else(4);/(2 分)inc(i);end;(5);/(3 分)count1 := 1;end;end;if (ans_length 1)四、阅读程序题()Yes判定输入的字符串是否是回文串()133到1000中是或的倍数的数的个数()4最长上升子序列的长度()7图中最长通路的长度五、完成程序题.(1) n+i-p(2) i+1-p(3) ai-p(4) j=end2 (5) i(6) J-1(或start2-1)、(1)j-1(2) cur1(3) dec(count1)(4) dec(count2)(5) cur1:=aj
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!