大学生程序设计竞赛样题
计算机程序设计大赛竞赛题

计算机程序设计大赛竞赛题□JS 竞赛题题目要求:用HTML + CSS + JavaScript制作一个前台页面(index.html)。
你可以使用纯JavaScript实现页面的动态效果,也可以使用JavaScript库,但最好是jQuery。
注:CSS、JavaScript要独立于html文件,单独保存为外部文件(如index.css、inde x.js)。
具体要求如下:1、设计一个有布局的界面,你可以使用tab或者tree形目录作为导航,但每级导航的内容不可存在于该文件(index.html)中,要放在另外的html文件里。
tree形目录作为导航的,要至少支持3级导航。
希望你能够把以下要求的实现作为某级导航的内容放在该级导航下。
该页面是你展示后续实现的门户,所以请尽量注意美观。
2、使用“题目要求”中提及的技术,实现一个4×4的拼图游戏。
在实现以下“基本要求”的前提下才可以实现后续的“扩展要求”。
“基本要求”务必全部实现,“扩展要求”请尽可能多地实现。
基本要求:1)格子内必须是图片而不是字符。
示例如图1。
图12)通过鼠标点击有图片的格子,将其移动到相邻的无图片的格子。
3)要有游戏功能控制按钮,如“开始”、“重来”等。
4)游戏成功完成后要有提示。
5)需要时请考虑JavaScript的执行效率。
6)游戏的CSS、JavaScript要独立于html文件,单独保存为外部文件。
扩展要求:1)必须考虑JavaScript的执行效率。
2)支持键盘方向键操作,即←↑↓→键的操作。
3)支持“计时”、“计步”玩法。
4)支持预定义好的几种矩阵(方阵)大小,甚至自定义的矩阵(方阵)大小,5×5、6×6等等。
5)支持不只1张拼图背景图片,甚至自定义的拼图背景图片。
6)支持智能拼图,即游戏初始时或游戏进行过程中,通过智能拼图功能完成余下步骤,当然,每一步的时间间隔要足以让肉眼辨别。
3、页面的美观度,布局的合理性,动态效果的流畅度也是评分的重点。
程序设计大赛试题及答案

试题1、数学黑洞(程序文件名maths.c/maths.cpp)【问题描述】任给一个4位正整数,其各位数位上的数字不全相同,将数字重新组合成一个最大的数与最小的数相减,重复这个过程,最多7步,必得6174。
对任给的4位正整数(各位数位上的数字不全相同),编程输出掉进黑洞的步数。
【输入】一行,一个4位正整数n(1000< n<9999)【输出】掉进黑洞的步数输入1234输出32、进制转换(程序文件名conver.c/conver.cpp)【问题描述】任给一个十进制整数n,及正整数m(m<=16且m≠10), 将n转换成m进制并输出。
【输入】一行,两个整数n,m(0 ≤ n ≤ 500000,2 ≤ m ≤ 16,且m≠10),中间用一个空格隔开,其中n 表示十进制数。
【输出】转换后的数【输入输出样例】输入255 8输出3773、分数线划定(程序文件名score.c/score.cpp)【问题描述】公务员选拔工作正在 A 市如火如荼的进行。
为了选拔优秀人才,A 市对所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试。
面试分数线根据计划录取人数的150%划定,即如果计划录取m名公务员,则面试分数线为排名第m*150%(向下取整)名的选手的分数,而最终进入面试的选手为笔试成绩不低于面试分数线的所有选手。
现在就请你编写程序划定面试分数线,并输出所有进入面试的选手的报名号和笔试成绩。
【输入】第一行,两个整数n,m(5 ≤ n ≤ 5000,3 ≤ m ≤ n),中间用一个空格隔开,其中n 表示报名参加笔试的选手总数,m 表示计划录取的人数。
输入数据保证m*150%向下取整后小于等于n。
第二行到第 n+1 行,每行包括两个整数,中间用一个空格隔开,分别是选手的报名号k(1000 ≤ k ≤ 9999)和该选手的笔试成绩s(1 ≤ s ≤ 100)。
数据保证选手的报名号各不相同。
程序设计趣味赛题目

程序设计趣味赛题目一、基础题(3选2,每道5分,最高10分)1.题目:将一个正整数分解质因数。
例如:输入90,打印出90=2*3*3*5。
2.题目:海滩上有一堆桃子,五只猴子来分。
第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。
第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子?3.题目:编写一个函数,根据输入的行数来输出杨辉三角形。
注:杨辉三角形的规律如下:11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1…..二、图形题:(3选2,每题101.题目:编写程序,使运行结果呈现“”的形状,可用星号表现出来,也可用其他符号。
2.题目:编写程序,使运行结果呈现“”的形状,可用星号表现出来,也可用其他符号。
3.题目:编写程序,使运行结果呈现“”的形状,可用星号表现出来,也可用其他符号。
例:编写程序,使运行结果呈现(以上题目不允许用直接打印法)三、串类题:(3选2,每题10分,最高20分)1.题目:写一个函数,其功能是将两个字符串重复出现的字符删除后合并成一个字符串输出。
2.题目:编写一个程序,其功能是将2个字符串合并成一个字符串后,再实现前m个和最后m个的位置转换后输出。
3.题目:计算字符串中子串出现的次数。
四、生活模拟题:(每题10分)1.丁叔刚开始接触电脑就喜欢上了在论坛灌水。
虽然他经营农场很有那么一套,但是到了电脑面前就成了小白。
由于对电脑操作完全不熟悉,他总是找不到一种快速生成超长文本进行灌水的方法,每次都要在键盘上一个一个地敲入成百上千个字符。
终于,丁叔再也无法忍受了,花了一天的时间学习电脑,总算学会了复制、粘贴等基本操作的使用,假设丁叔敲入一个字符需要1个时间单位,复制任何连续的一段已输入的内容需要5个时间单位,粘贴一次需要2个时间单位,那么丁叔生成一段至少包含N个字符的文本最少需要多长时间2.给定n个点的坐标(x,y,z),且n<=50,从点1出发,怎么样才能走一条路径,访问每个点一次且仅一次,使走过的距离和最小?五、初涉acm:简单中文acm题目(输入输出要严格按照题目设定的要求)(每题15分)1.题目:汽车到哪了?Description长途坐车真难受,人们可能在车上早早睡着了,等到醒来的时候,车行驶到哪了?假如长途车经过一些城镇,现在知道长途车行驶路线上相邻的城镇之间的距离和车从出发时算已经行驶的距离,请计算出汽车行驶到哪个城镇或哪两个城镇之间Input(输入格式)第一行是一个整数T,代表接下来有多少组数据接下来是各组数据,每一组数据的第一行是两个整数N,M,分别表示城镇数目(包括起点和终点城镇)和要询问多少次到哪了。
大学程序设计大赛试题答案

大学程序设计大赛试题答案一、选择题1. 在C++中,下列哪个关键字用于定义常量?A. staticB. volatileC. constD. mutable答案:C2. 以下关于Python中的列表(list)说法正确的是:A. 列表是不可变的序列类型。
B. 列表不支持添加元素。
C. 列表可以包含不同类型的元素。
D. 列表的元素不能被删除。
答案:C3. 在Java中,关于异常处理的描述,以下哪项是正确的?A. try块中必须跟catch块。
B. catch块可以捕获所有类型的异常。
C. finally块可以用于执行清理操作,无论是否发生异常都会执行。
D. throw关键字用于声明一个可能抛出的异常类型。
答案:C4. 以下关于数据库事务的描述,哪项是错误的?A. 事务具有原子性。
B. 事务具有一致性。
C. 事务具有隔离性。
D. 事务不具备持久性。
答案:D5. 在HTML5中,用于创建交互式内容的标签是:A. <canvas>B. <svg>C. <iframe>D. <audio>答案:A二、填空题1. 在JavaScript中,可以使用________函数来获取字符串的长度。
答案:length2. 在Python中,使用________关键字可以遍历字典中的所有键。
答案:keys()3. SQL语句中,用于删除表中所有记录但保留表结构的命令是________。
答案:TRUNCATE TABLE4. 在C语言中,使用________关键字可以定义一个指针变量。
答案:*(星号)5. 正则表达式中,\d表示匹配一个________字符。
答案:数字三、编程题1. 题目描述:编写一个程序,输入一个整数n,输出n的阶乘。
C++代码示例:```cpp#include <iostream>using namespace std;int factorial(int n) {if (n <= 1) {return 1;} else {return n * factorial(n - 1);}}int main() {int n;cin >> n;cout << factorial(n) << endl;return 0;}```2. 题目描述:编写一个Python程序,实现一个简单的计算器,支持加、减、乘、除功能。
2023年福建省第三届大学生程序设计竞赛题目

Problem A Solve equationAccept: 111 Submit: 229Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionYou are given two positive integers A and B in Base C. For the equation:A=k*B+dWe know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:(1) A=0*B+123(2) A=1*B+23As we want to maximize k, we finally get one solution: (1, 23)The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.InputThe first line of the input contains an integer T (T≤10), indicating the number of test cases.Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.OutputFor each test case, output the solution “(k,d)” to the equation in Base 10. Sample Input32bc 33f 16123 100 101 1 2Sample Output(0,700)(1,23)(1,0)Problem B Bin & Jing in wonderlandAccept: 4 Submit: 28Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionBin has a dream that he and Jing are both in a wonderland full of beautiful gifts. Bin wants to choose some gifts for Jing to get in her good graces.There are N different gifts in the wonderland, with ID from 1 to N, and all kinds of these gifts have infinite duplicates. Each time, Bin shouts loudly, “I love Jing”, and then the wonder land random drop a gift in front of Bin. The dropping probability for gift i (1≤i≤N) is P(i). Of cause, P(1)+P(2)+…+P(N)=1. Bin finds that the gifts with the higher ID are better. Bin shouts k times and selects r best gifts finally.That is, firstly Bin gets k gifts, then sorts all these gifts according to their ID, and picks up the largest r gifts at last. Now, if given the final list of the r largest gifts, can you help Bin find out the probability of the list?InputThe first line of the input contains an integer T (T≤2,000), indicating number of test cases.For each test cast, the first line contains 3 integers N, k and r (1≤N≤20, 1≤k≤52,1≤r≤min(k,25)) as the description above. In the second line, there are N positive float numbers indicates the probability of each gift. There are at most 3 digits after the decimal point. The third line has r integers ranging from 1 to N indicates the finally list of the r best gifts’ ID.OutputFor each case, output a float number with 6 digits after the decimal points, which indicates the probability of the final list.Sample Input42 3 30.3 0.71 1 12 3 30.3 0.71 1 22 3 30.3 0.71 2 22 3 30.3 0.72 2 2Sample Output0.0270000.1890000.4410000.343000Problem C Floor problemAccept: 133 Submit: 150Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionIn this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.You are given 3 positive integers n, L and R. Print the result off(n,L)+f(n,L+1)+...+f(n,R), please.InputThe first line of the input contains an integer T (T≤100), indicating the number of test cases.Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000,L≤R). OutputFor each test case, print the result of f(n,L)+f(n,L+1)+...+f(n,R) in a single line. Sample Input31 2 3100 2 100100 3 100Sample Output382332Problem D Digits CountAccept: 11 Submit: 64Time Limit: 10000 mSec Memory Limit : 262144 KB Problem DescriptionGiven N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations:Operation 1: AND opn L RHere opn, L and R are integers.For L≤i≤R, we do A[i]=A[i] AND opn (here "AND" is bitwise operation).Operation 2: OR opn L RHere opn, L and R are integers.For L≤i≤R, we do A[i]=A[i] OR opn (here "OR" is bitwise operation).Operation 3: XOR opn L RHere opn, L and R are integers.For L≤i≤R, we do A[i]=A[i] XOR opn (here "XOR" is bitwise operation).Operation 4: SUM L RWe want to know the result of A[L]+A[L+1]+...+A[R].Now can you solve this easy problem?InputThe first line of the input contains an integer T, indicating the number of test cases. (T≤100)Then T cases, for any case, the first line has two integers n and m (1≤n≤1,000,000, 1≤m≤100,000), indicating the number of elements in A and the number of operations.Then one line follows n integers A[0], A[1], ..., A[n-1] (0≤A[i]<16,0≤i<n).Then m lines, each line must be one of the 4 operations above. (0≤opn≤15) OutputFor each test case and for each "SUM" operation, please output the result with a single line.Sample Input14 41 2 4 7SUM 0 2XOR 5 0 0OR 6 0 3SUM 0 2Sample Output718HintA = [1 2 4 7]SUM 0 2, result=1+2+4=7;XOR 5 0 0, A=[4 2 4 7];OR 6 0 3, A=[6 6 6 7];SUM 0 2, result=6+6+6=18.Problem E How many tuplesAccept: 0 Submit: 0Time Limit: 10000 mSec Memory Limit : 65536 KB Problem DescriptionGiven m positive integer a[1],a[2]…a[m]. We run the following program (in C++):const int MAXN = 20;int a[MAXN], m;int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}long long cnt = 0;void gao(int cur, int g) {if (cur > m) {if (g == 1)++cnt;return;}for (int i = 1; i <= a[cur]; ++i)gao(cur + 1, g < 0 ? i : gcd(g, i));}int main() {scanf("%d", &m);for (int i = 1; i <= m; ++i)scanf("%d", a + i);gao(1, -1);cout << cnt << endl;return 0;}Here gcd is the Greatest Common Divisor, Obviously, the program above is to find the number of tuples (b[1], b[2], …, b[m]) such that:(1) gcd(b[1], b[2], …, b[m])=1. (Here we define gcd(num)=num, that is: gcd(9)=9, gcd(2)=2)(2) 1≤b[i]≤a[i]. (1≤i≤m, b[i] is an integer)Now in this problem, the m and a[i] may be very large! So could you write one efficient program to find the answer? The answer may be too large. So you can just output the answer Mod 1,000,000,007.InputThe first line of the input contains an integer T (T≤10,000), indicating the number of test cases.Then T cases, for any case, only two lines.The first line is one integer m(1≤m≤20).The second line has m integers indicate a[1], a[2], …, a[m] (1≤a[i]≤100,000,000,1≤i≤m).The answer may be too large. So you can just output the answer Mod 1,000,000,007. OutputFor each test case, print a line containing the answer Mod 1,000,000,007. Sample Input325 5210000 987321234 5678Sample Output19600261564261566Problem F Hua Rong DaoAccept: 22 Submit: 66Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionCao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?InputThere is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.OutputFor each test case, print the number of ways all the people can stand in a single line. Sample Input212Sample Output18HintHere are 2 possible ways for the Hua Rong Dao 2*4.Problem H Mountain NumberAccept: 2 Submit: 7Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionOne integer number x is called "Mountain Number" if:(1) x>0 and x is an integer;(2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[2i+2](if exists).For example, 111, 132, 893, 7 are "Mountain Number" while 123, 10, 76889 are not "Mountain Number".Now you are given L and R, how many "Mountain Number" can be found between L and R (inclusive) ?InputThe first line of the input contains an integer T (T≤100), indicating the number of t est cases.Then T cases, for any case, only two integers L and R (1≤L≤R≤1,000,000,000). OutputFor each test case, output the number of "Mountain Number" between L and R in a single line.Sample Input31 101 1001 1000Sample Output954384Problem I StarAccept: 78 Submit: 320Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionOverpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.InputThe first l ine of the input contains an integer T (T≤10), indicating the number of test cases.For each test case:The first line contains one integer n (1≤n≤100), the number of stars.The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicat e the points, all the points are distinct.OutputFor each test case, output an integer indicating the total number of different acute triangles.Sample Input130 010 05 1000Sample Output1Problem J Min NumberAccept: 85 Submit: 261Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionNow you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| mea ns the length of n’s 10-base notation. Then we can swap n[i] and n[j].For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?Please note that in this problem, leading zero is not allowed!InputThe first line of the input contains an integer T (T≤100), indicating the number of test cases.Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.OutputFor each test case, output the minimum number we can get after no more than M operations.Sample Input39012 09012 19012 2Sample Output901210921029Problem K TicketsAccept: 14 Submit: 50Time Limit: 3000 mSec Memory Limit : 32768 KB Problem DescriptionYou have won a collection of tickets on luxury cruisers. Each ticket can be used only once, but can be used in either direction between the 2 different cities printed on the ticket. Your prize gives you free airfare to any city to start your cruising, and free airfare back home from wherever you finish your cruising.You love to sail and don't want to waste any of your free tickets. How many additional tickets would you have to buy so that your cruise can use all of your tickets?Now giving the free tickets you have won. Please compute the smallest number of additional tickets that can be purchased to allow you to use all of your free tickets. InputThere is one integer T (T≤100) in the first line of the input.Then T cases, for any case, the first line contains 2 integers n, m (1≤n, m≤100,000). n indicates the identifier of the cities are between 1 and n, inclusive. m indicates the tickets you have won.Then following m lines, each line contains two integers u and v (1≤u, v≤n), indicates the 2 cities printed on your tickets, respectively.OutputFor each test case, output an integer in a single line, indicates the smallest number of additional tickets you need to buy.Sample Input35 31 31 24 56 51 31 21 61 51 43 21 21 2Sample Output12。
2023全国大学生程序设计竞赛题目

2023全国大学生程序设计竞赛题目今年的全国大学生程序设计竞赛将于2023年举行。
本次竞赛将囿于程序设计领域,旨在考察参赛选手的编程能力、解决问题的能力以及团队合作精神。
以下是本次比赛的几道题目,希望能够为参赛选手提供一些思路和挑战。
题目一:图书管理系统设计一个图书管理系统,能够实现以下功能:1. 图书录入:包括图书的基本信息(书名、作者、出版社等)以及库存数量。
2. 图书查询:根据关键词(书名、作者等)进行图书查询,并显示图书的详细信息。
3. 借书与还书:实现图书的借出和归还功能,并更新库存数量。
4. 图书推荐:根据用户的借阅历史推荐相关图书。
题目二:火车票订购系统设计一个火车票订购系统,能够实现以下功能:1. 火车线路与时刻表:提供火车线路和时刻表信息,包括出发地、目的地、经停站点和到达时间等。
2. 站点查询:根据出发地和目的地查询经停该站点的火车。
3. 车票预订:用户选择出发地、目的地和乘车日期后,系统显示可用车次和余票数量,并支持用户预订车票。
4. 订单管理:用户可以查看自己的订单信息,包括已购车票的详细信息和订单状态。
题目三:智能家居控制系统设计一个智能家居控制系统,能够实现以下功能:1. 设备控制:包括灯光、温度、窗帘等设备的远程控制。
2. 定时任务:用户可以设置定时任务,如定时开关灯光、调节室内温度等。
3. 情景模式:用户可以设置情景模式,如影院模式、就寝模式等,系统将根据用户的设置自动调节设备状态。
4. 能耗统计:系统能够记录和展示各个设备的能耗,以便用户了解和管理家庭的能源消耗。
以上是本次竞赛的几道题目,希望参赛选手能够根据自己的技能和经验,在规定时间内完成这些挑战。
祝愿大家在比赛中取得好成绩,展现自己优秀的程序设计和解决问题的能力!。
大学生程序设计竞赛试题(正式赛)

中原工学院第一届大学生程序设计竞赛正式比赛试题主办:中原工学院教务处学生处校团委计算机学院承办:中原工学院计算机学院地点:计算机学院实验中心406实验室时间:2010年4月11日【试题一】兔子【题目描述】兔子具有很强的繁殖能力。
一对成年兔子每个月可以繁殖一对小兔子,而一对小兔子经过m个月之后,就会长成一对成年兔子。
通过分析,我们可以看出:若m=2的时候,每个月兔子的对数构成了一个Fibonacci数列。
但是,若m<>2,这个问题看起来就不那么简单了。
你的任务是计算:假定初始只有一对兔子,那么,经过d个月之后,共有多少对兔子?可以假定,在此阶段没有任何兔子死亡。
【输入】输入包括多组测试数据。
每组测试数据的一行中包括2个整数m(1<=m<=10),d(1<=d<=30)。
当测试数据遇到一行中有两个0时,即m=d=0,测试数据结束。
【输出】针对每组测试数据,在每一行输出经过d个月后共有多少对兔子。
【输入样例】2 33 50 0【输出样例】59【试题二】网页浏览器【题目描述】Mozilla Firefox是一个自由的,开放源码的网页浏览器,适用于Windows, Linux 和MacOS X等平台。
Firefox火狐校园大使是Mozilla开源社区项目的一部分,针对在校的高年级本科生和研究生以及众多技术爱好者,在校园中推广开源项目和开放技术,让更多的开发人员受益于Mozilla的开放技术和免费资源。
你很荣幸得到了这样一个机会,为Firefox编写一个重要的导航模块。
正如上图所示,导航模块要接受用户的后退、前进、进入用户输入的网址以及清空浏览记录等操作。
【输入】为了简化问题,用户所有的操作都以字符的形式从标准输入读入。
每一行描述一个操作,各操作的格式和功能如下所示:操作功能back 如果当前页面不是第一个页面,则跳到到前一个页面,并输出这个页面的网址forward 如果当前页面不是最后一个页面,则跳到到后一个页面,并输出这个页面的网址url 网址跳转到用户输入的网址(网址不含空格)clear 清空浏览记录(当前页面除外)exit 退出浏览器浏览器启动时默认进入中原工学院的主页” ”【输出】对于每一个需要输出网址的操作,输出对应的网址。
程序设计竞赛练习题

徐州师范大学程序设计竞赛练习题2012-2-9酆格斐DescriptionCalculate a + bInputTwo integer a,b (0 ≤ a,b ≤ 10)OutputOutput a + bSample Input1 2Sample Output3Description在一个正方形的灰度图片上,肿瘤是一块矩形的区域,肿瘤的边缘所在的像素点在图片中用0表示。
其它肿瘤内和肿瘤外的点都用255表示。
现在要求你编写一个程序,计算肿瘤内部的像素点的个数(不包括肿瘤边缘上的点)。
已知肿瘤的边缘平行于图像的边缘。
Input只有一个测试样例。
第一行有一个整数n,表示正方形图像的边长。
其后n行每行有n 个整数,取值为0或255。
整数之间用一个空格隔开。
已知n不大于1000。
Output输出一行,该行包含一个整数,为要求的肿瘤内的像素点的个数。
Sample Input5255 255 255 255 255255 0 0 0 255255 0 255 0 255255 0 0 0 255255 255 255 255 255Sample Output1Hint如果使用静态数组来表示图片数据,需要将该数组定义成全局变量。
Description班上有学生若干名,给出每名学生的年龄(整数),求班上所有学生的平均年龄,保留到小数点后两位。
Input第一行有一个整数n(1<= n <= 100),表示学生的人数。
其后n行每行有1个整数,取值为15到25。
Output输出一行,该行包含一个浮点数,为要求的平均年龄,保留到小数点后两位。
Sample Input21817Sample Output17.50Hint要输出浮点数、双精度数小数点后2位数字,可以用下面这种形式:printf("%.2f", num);Description给定一个正整数a,以及另外的5个正整数,问题是:这5个整数中,小于a的整数的和是多少?Input输入一行,只包括6个小于100的正整数,其中第一个正整数就是a。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
附件2 :
大学生程序设计竞赛样题(更多样题参见172.24.10.6)
Description
著名的哥德巴赫猜想是:每个不小于6的偶数都可以表示为两个奇素数之和。
例如,16=3+13=5+11。
下面需要你来编程验证一下哥德巴赫猜想是否正确。
Input
在输入的若干行数据中,每行仅有一个偶数N(6<=N<=2000000000)。
Output
你需要输出N行数据,每行以升序输出两个素数,这两个素数的和等于输入中的那个偶数,如果有多种选择,输出乘积最大的,例如N==16时,输出511,而不是313。
当你发现偶数N不能拆分成两个素数时,请立刻放下手中的程序,直接到A9找校长,因为你和大连东软信息学院都将名垂青史。
Sample Input
6
16
20
Sample Output
3 3
5 11
7 13
C语言答案供参考:
#include<stdio.h>
#include<math.h>
int is_prime(int n)
{
int m=sqrt(n);
int i;
for(i=2;i<=m;++i)
if(n%i==0) return 0;
return 1;
}
void main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int m=n/2;
if(m%2==0) --m;
while(1)
{
if(is_prime(m)&&is_prime(n-m))
{
printf("%d %d\n",m,n-m);
break;
}
else m-=2;
}
}
}。