四川理工学院2012年ACM程序设计赛试题
2012秋C程序设计试卷+答案
{ int t,d;
float p;
scanf("%d,%f",&t,&p);
switch(04)){
case 0: d=0;break;
case 1: d=2;break;
case 2:
case 3:d=5;break;
case 4:
case 5:
case 6: d=8;break;
C)有逻辑类型,但没有构造类型D)没有逻辑类型也没有构造类型9;\"'B)'\031' C)'\b' D)'\0xa5'
24、已知梯形的上底为a,下底为b,高为h,用C语言写的正确的面积公式是()。
A)1/2*(a+b)*h B)1.0/2*(a+b)*h C)1.0/2.0(a+b)h D)1.0\2*a+b*h
B)main函数可以在任何地方出现。一个C程序必须有且仅有一个main函数
C)main函数必须出现在所有函数之后。一个C程序只能有一个main函数
D)main函数出现在固定位置。一个C程序可以有多个main函数
22、C语言中,下列叙述正确的是()。
A)没有逻辑类型,但有构造类型B)既有逻辑类型也有构造类型
34、若有int s[4]={1,2,3,4};,则s[s[0]+2*s[2]-s[3]]的值是()
A)1 B)2 C)3 D)4
35、C语言程序的三种基本结构是()
A)嵌套结构、递归结构、循环结构B)递归结构、循环机构、转移结构
C)顺序结构、选择结构、循环结构D)循环结构、转移结构、顺序结构
36、若函数的调用形式如下:
ACM试题及参考答案
1. 给定一个矩阵M(X, Y),列集为X ,行集为Y 。
如果存在对其列的一个排序,使得每一行的元素都严格递增,称M 是一个次序保持矩阵。
例如下图中存在一个排序x 4,x 1,x 2,x 3,x 5I ⊆X ,满足:子矩阵M(I,Y)是次序保持矩阵。
[测试数据] 矩阵M :[测试数据结果] I={ x 1,x 3,x 4,x 7,x 8}[解题思路] 将该问题归约为在一个有向图中找一条最长路径的问题。
给定矩阵M=(a ij ),行集Y ,列集X ,行子集J ⊆Y ,定义有向图D A =(V A ,E A ),其中V A 含有|X|个顶点,每个顶点代表X 中的一列,如果顶点u ,v 对应的列x u ,x v 满足,对于任意的j ∈J ,u v ij ij a a <,则有一条从u 到v 的弧(u ,v )∈E 。
显然,D A 是个无环图,可以在O(|X|2)时间内构造完毕。
对于任意的条件子集J ,A(I,J)是次序保持的当且仅当对应于J 中条件的顶点在D A 中构成一条有向路径。
从而我们只需在有向图D A 中找一条最长路径,该问题可在O(|V A |+| E A |)时间内完成。
按上面的方法构造有向图如下:有向图中找最长路径的线性时间算法。
一些表示方法如下:d out (u )为顶点u 的出度,d in (u )为顶点u 的入度,source 为入度为0的顶点,sink 为出度为0的顶点,N out (u )为u 指向的邻接点集合,P uv 为从u 到v 的最长路,显然应从source 到sink 。
在每一步为每个顶点关联一个永久的或临时的标签。
v被赋了一个临时标签(v’,i v)表明在当前步,算法找出的最长的从source到v的有向路长度为i v,且经由v’而来。
v被赋了一个永久标签[v’,i v]表明从source到v的最长有向路长度为i v,且经由v’而来,通过回溯每个顶点的永久标签就可以找出最长有向路。
C语言程序设计2012 (含答案)(1)
12年的试题比13年的难很多,笔者费了一早上加一中午才全部做完。
如果对答案有疑问或者觉得哪里有问题请联系我qq553915228 李添锐一、写出下列程序段的运行结果(40分)1、(4分)char a='D'-'A',b='\010',c,d;c = ++a || b++;d = a-- && b--;printf("%d,%d,%d,%d",a,b,c,d);输出:3,7,1,12、(4分)char a=0x123FFF;printf("%d,",a);a=127;printf("%d",++a);输出:-1,-1283、(4分)int a=5,y=0;int main(){while(a=5){a+=5;y+=a;printf("%d,%d,", a, y);if (y>18) break;}return 0;}输出:10,10,10,204、(4分)int i=1, j=2, k=4;printf("%f,", i-(float)j/k);printf("%d,", j>1<k);k+=5/10*i ;printf("%d,",k);printf("%d", (j=1)?2:0);输出:0.500000,1,4,25、(4分)int a[][2]={(1,2),(3,4)};printf("%d",a[0][1]);输出:46、(4分)int ave(int x, int y){return (x+y)/2;}int main(){int a=1, b=2, c=3;printf("%d\n",ave(ave(a,b), ave(b,c)));return 0;}输出:1(\n)7、(4分)void exc(int x, int *y){int t;t=x; x=*y; *y=t;}int main(){int a=5,b=8;exc(a,&b);printf("a=%d,b=%d",a,b); return 0;}输出:a=5,b=58、(4分)char str[10]="believe";char *p=str;*(str+5)=0;puts(2+p);输出:lie9、(4分)struct pt{int x; int y;} p[2]={1,3,5,7}; printf("%.3f",p[1].y/(float)p[0].y+ p[1].x/p[0].x);输出:7.33310、(4分)FILE *fp;char c=49;int d=50, e;fp=fopen("a.tmp","w"); fprintf(fp,"%c%d", c, d); fclose(fp);fp=fopen("a.tmp","r"); fscanf(fp,"%d",&e); printf("%d\n",e);输出:150(\n)二、改错题(20分)以下程序实现:从键盘输入若干个学生的成绩数据,将这些数据存到磁盘文件上,并求这些学生的最高成绩。
2012acm ICPC金华区域赛题目
Problem A. MinesDescriptionTerrorists put some mines in a crowded square recently. The police evacuate all people in time before any mine explodes. Now the police want all the mines be ignited. The police will take many operations to do the job. In each operation, the police will ignite one mine. Every mine has its "power distance". When a mine explodes, any other mine within the power distance of the exploding mine will also explode. Please NOTE that the distance is Manhattan distance here.More specifically, we put the mines in the Cartesian coordinate system. Each mine has position (x,y) and power distance d.The police want you to write a program and calculate the result of each operation.InputThere are several test cases.In each test case:Line 1: an integer N, indicating that there are N mines. All mines are numbered from 1 to N.Line 2…N+1: There are 3 integers in Line i+1 (i starts from 1). They are the i-th mine’s position (xi,yi) and its power distance di. There can be more than one mine in the same point.Line N+2: an integer M, representing the number of operations.Line N+3...N+M+2 : Each line represents an operation by an integer k meaning that in this operation, the k-th mine will be ignited. It is possible to ignite a mine which has already exploded, but it will have no effect.1<=M<=N<=100000,0<=xi,yi<=10^9,0<=di<=10^9Input ends with N=0.OutputFor each test case, you should print ‘Case #X:’ at first, which X is the case number starting from 1. Then you print M lines, each line has an integer representing the number of mines explode in the correspondent operation.Sample Input30 0 01 1 22 2 23123Sample OutputCase #1:12Problem B. BatteryDescriptionRecently hzz invented a new kind of solar battery. The battery is so amazing that the electric power generated by it can satisfy the entire village. People in the villager are all very happy since they can get free and green energy from now on. But the manager of a power company is sorrow about this. So he plans to take some action to obstruct the battery.The battery can be regarded as a segment of L meters. And the manager plans to build n pillars on the battery.Like the picture above, the distance between pillar i and the battery's left end is Xi, and its height is Hi. The thickness of all pillars can be ignored. When the sunlight is slant, some part of the battery will be sheltered by the pillars.One meter battery exposed in the vertical sunlight for one hour will generate one unit of energy. If the sunlight is slant, the amount of energy generated should be multiplied by sinβ(βis the angle between sunlight and horizontal line).The sun rises from the infinite far left end of the horizon at 6 o’clock and goes down at the infinite far right end of the horizon at 18 o’clock. The sun is always infinite far away. So theπ at 12 o′clock.sunlight is parallel, and βis12Please calculate the amount of energy generated by the battery between t1 o’clock and t2 o’clock(6 ≤t1<t2≤18).InputThere are multiple test cases.For each test case:The first line contains two integer L(10≤L≤100,000)and N(4≤N≤1000),indicating the length of the battery and the number of pillars.The second line contains two integers, above mentioned t1 and t2(6≤t1<t2≤18).Then N lines follow, each containing two integers Xi(0≤Xi≤L) and Hi(1≤Hi≤1000), indicating the position and height of a pillar.It is guaranteed that no two pillars will be in the same position. It is also guaranteed that there is a pillar on both end of the battery.The input end with L=0, N=0.OutputFor each test case, you should output a line with the energy described above. Output should be rounded to 5 digits after decimal point.Sample Input10 414 170 25 18 310 10 0Sample Output7.97188Problem C. Magic Board DescriptionSths is a happy boy~Sths has got a Magic Board for his birthday gift! A Magic board is an N*M sized grids which were painted by black and white. According to the parity of N and M, the Magic Board would be a little different, but it can be guaranteed that any two adjacent grids are painted by different colors, and the amount of black grid is not less than white ones.The Magic Board is called MAGIC because it is formed by a Chain. A Chain is a set of grids in which a grid has at most 2 adjacent grids and there are only 2 grids which has only 1 adjacent grid. Those two special grids are called the endpoints of the Chain.The joint between two adjacent grids is very flexible. It can be rotate by any angle. Here’s an example of transforming a Chain into a Magic BoardThe Chain was connected by a Magic String. The existence of Magic String relies on the power of fengshui. But recently the fengshui in Beijing was ruined because there is a university installing air-conditionor (which also cause the HUGE RAIN in Beijing).So the Magic String disappears, and the Magic Board is totally fell apart.Sths feels upset, because he really likes the Magic Board (since it can form a lot of things). So he is thinking about how to reconstruct it. The only thing Sths has got now is the separated grids. But surprisingly, Sths finds out that there are differences between these grids.1.There are black grids and white grids.2.There are three different grids in the same color because the Magic String goes throughit in 3 different ways shown below:So there are 6 different kinds of grids. Now Sths has counted the amount of each kind of grids, he wants to know: by using the grids in his hand, how many kinds of legal Chains (which can form an N*M sized Magic Board) can be constructed.We shall say two Chains is the same if and only if the standard expression of these two Chains is the same.The standard expression is a set of numbers which decided by following method:1.Starting from one of a Chain's endpoint.2.Write down the color of the grids (1 for black and 0 for white) before direction changing.3.Write down 2 then change direction and repeat Step 2 until reaching another endpointof the Chain.4.Choose the expression which lexicographical lower between the two expressions justgenerated since there are two endpoints.For example, the standard expression of the example of “N=M=3” is “10120120120212”(another expression is “10212012012012”, which is lexicographical greater than standard expression). And the standard expression of the example of “N=M=4” is“01012010210120120120212”.InputThere are Multiple Test CasesFor each case, there will be six integer numbers in one line, N, M, BO, BA, WO, and WA, indicating the number of rows and columns, the amount of “Black and Opposite” grids, the amount of “Black and Adjacent” grids, the amount of “White and Opposite” grids, the amount of “White and Adjacent” grids.2<=N*M<=30The input end with a line of 0 0 0 0 0 0.OutputFor each case, output the kinds of legal Chains that can be constructed by given grids.Sample Input3 3 1 2 2 23 3 0 3 3 15 5 56 5 70 0 0 0 0 0Sample Output114Problem D. A very hard Aoshu problem DescriptionAoshu is very popular among primary school students. It is mathematics, but much harder than ordinary mathematics for primary school students. Teacher Liu is an Aoshu teacher. He just comes out with a problem to test his students:Given a serial of digits, you must put a '=' and none or some '+' between these digits and make an equation. Please find out how many equations you can get. For example, if the digits serial is "1212", you can get 2 equations, they are "12=12" and "1+2=1+2". Please note that the digits only include 1 to 9, and every '+' must have a digit on its left side and right side. For example, "+12=12", and "1++1=2" are illegal. Please note that "1+11=12" and "11+1=12" are different equations.InputThere are several test cases. Each test case is a digit serial in a line. The length of a serial is at least 2 and no more than 15. The input ends with a line of "END".OutputFor each test case , output a integer in a line, indicating the number of equations you can get.Sample Input1212123456661235ENDSample output22Problem E. WormsDescriptionWorms is a series of turn-based computer games. Players control a small platoon of earthworms across a deformable landscape, battling other computer- or player-controlled teams. The game feature bright and humorous cartoon-style animation and a varied arsenal of bizarre weapons.During the course of the game, players take turns selecting one of their worms. They then use whatever tools and weapons available to attack and kill the opponents’worms. Over fifty weapons and tools may be available each time a game is played, and differing selections of weapons and tools can be saved into a “scheme” for easy selection in future games.When most weapons are used, they cause explosions that deform the terrain, creating circular cavities. If a worm is hit by a weapon, the amount of damage dealt to the worm will be removed from the worm’s initial amount of health. When a worm fall into the water or its health is reduced to zero, it dies.In this problem, the terrain of a stone can be described as a simple polygon. The worms only use the time bombs. Once a time bomb is thrown, it is only attracted by the force of gravity. In other words, the flying track of the bomb is a parabola. When it reaches the stone (the polygon), the bomb does not blow off or stop immediately. It will still fly along the parabola regardless of the resistance of the stone due to its special character. The time bomb can only be triggered by the timer. When the preset time is used up, the bomb blows up and eliminates all the materials within its explosion range. You need to calculate the area of the eliminated materials of one explosion.InputThere are multiple test cases.The first line of a test case contains seven floating numbers x0, y0, v0, θ, t, g, R. (x0, y0) is the position of the worm who throws the bomb, which could be inside the polygon or outside the polygon (even in the sky or under the water). The initial value of velocity is v0 which forms aθ(0≤θ<90) a ngle with the positive direction of x-axis. The bomb is always thrown upwards. The preset time is t, which is also the time of flying. The value of acceleration of gravity of the worms’planet is g. The direction of gravity is the negative direction of y-axis. The explosion range is a circle and R is the radius.The second line contains an intege r n (3≤n≤100), which indicates the number of edges of the stone(simple polygon). The following n lines contain two real numbers xi and yi each, which describe the coordinates of a vertex. Two vertexes in adjacent lines are adjacent on the polygon.The input contains multiple test cases. It is ended by “0 0 0 0 0 0 0”.OutputFor each test case, output one line containing the area of the eliminated materials of the explosion rounded to two digits to the right of the decimal point.Sample Input0 0 15 45 10 2 103100 0200 0100 1000 0 0 0 0 0 0Sample Output228.74Problem F. Aeroplane chess DescriptionHzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). When Hzz is at grid i and the dice number is x, he will moves to grid i+x. Hzz finishes the game when i+x is equal to or greater than N.There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi≤N)without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is no two or more flight lines start from the same grid.Please help Hzz calculate the expected dice throwing times to finish the game.InputThere are multiple test cases.Each test case contains several lines.The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).The input end with N=0, M=0.OutputFor each test case in the input, you should output a line indicating the expected dice throwing times. Output should be rounded to 4 digits after decimal point.Sample Input2 08 32 44 57 80 0Sample output1.16672.3441Problem G. GPADescriptionGPA(Grade-Point Average) is one way to measure students’ academic performance in PKU. Each course has an integer credit, ranges from 1 to 99. For each course, you will get a score at the end of the semester, which is an integer ranges from 0 to 100. Then you can calculate the Grade-Point of this course with the following formula. (Your score is x and your Grade-Point is p, using real arithmetic)p=4−3100−x2,60≤x≤100 p=0, 0≤x≤60Then you can get the GPA with the following formula (the Grade-Point of course i is p i, and the credit of course i is w i).GPA=p i∙w i mi=1w i mi=1Now it is not far from the final exam, if you do not review, you can only get a basic score in each course.You have n days to review. There are K classes in each day. For each class, only one course can be reviewed. After the review, your score in this course will exactly increase by 1. You can get more increment by spending more classes in this course. But the score may not exceed 100.For some reasons, not any course can be reviewed in any class. Each day you can only review some of the courses.Now you want your GPA to be as high as possible, and at the same time, you do not want to fail in any course. Please calculate the highest GPA you can get.InputThe input consists of several test cases. Each test case begins with 3 integers N (0<=N<=40), K(0<K<=20), M (0<M<=20), representing the number of days, the number of classes in each day and the number of courses. Next line contains M integers representing credits of each course and M integers representing basic scores of each course (0<=score<=100). Next N lines contain an N*M matrix, the j th element in i th row means whether you can review course j in i th day, 1 means you can review course j in i th day, 0 means you cannot. The Input ends with 0 0 0.OutputFor each test case, output the highest possible GPA, round to 6 digits after decimal point. If you have to fail a course, output 0.000000 instead.Sample Input2 10 31 1 250 60 901 1 01 0 12 20 41 1 1 150 50 50 401 1 1 00 0 0 10 0 0Sample Output2.7578130.000000Problem H. SumDescriptionXXX is puzzled with the question below:1, 2, 3, ..., n (1<=n<=400000) are placed in a line. There are m (1<=m<=1000) operations of two kinds.Operation 1: among the x-th number to the y-th number (inclusive), get the sum of the numbers which are co-prime with p( 1 <=p <= 400000).Operation 2: change the x-th number to c( 1 <=c <= 400000).For each operation, XXX will spend a lot of time to treat it. So he wants to ask you to help him.InputThere are several test cases.For each case, the first line begins with two integers --- the above mentioned n and m.Each the following m lines contains an operation.Operation 1 is in this format: "1 x y p".Operation 2 is in this format: "2 x c".OutputFor each operation 1, output a single integer in one line representing the result.Sample Input13 32 2 31 1 3 41 2 3 6Sample Output7Problem I. Minimum Spanning Tree DescriptionXXX is very interested in algorithm. After learning the Prim algorithm and Kruskal algorithm of minimum spanning tree, XXX finds that there might be multiple solutions. Given an undirected weighted graph with n (1<=n<=100) vertexes and m (0<=m<=1000) edges, he wants to know the number of minimum spanning trees in the graph.InputThere are no more than 15 cases. The input ends by 0 0 0.For each case, the first line begins with three integers --- the above mentioned n, m, and p. The meaning of p will be explained later. Each the following m lines contains three integers u, v, w (1<=w<=10), which describes that there is an edge weighted w between vertex u and vertex v( all vertex are numbered for 1 to n) . It is guaranteed that there are no multiple edges and no loops in the graph.OutputFor each test case, output a single integer in one line representing the number of different minimum spanning trees in the graph.The answer may be quite large. You just need to calculate the remainder of the answer when divided by p (1<=p<=1000000000). p is above mentioned, appears in the first line of each test case.Sample Input5 10 122 5 32 4 23 1 33 4 21 2 35 4 35 1 34 1 15 3 33 2 30 0 0Sample Output 4Problem J. Family Name List DescriptionKong belongs to a huge family. Recently he got a family name list which lists all men (no women) in his family over many generations.The list shows that the whole family has a common ancestor, let's call him Mr. X. Of course, everybody except Mr.X in the list is Mr. X's descendant. Everybody's father is shown in the list except that Mr. X's father is not recorded. We define that Mr. X's generation number is 0. His son's generation number is 1.His grandson's generation number is 2, and so on. In a word, everybody's generation number is 1 smaller than his son's generation number. Everybody's generation number is marked in some way in the list.Now Kong is willing to pay a lot of money for a program which can re-arrange the list as he requires ,and answer his questions such as how many brothers does a certain man have, etc. Please write this program for him.InputThere are no more than 15 test cases.For each test case:The first line is an integer N( 1 <= N <= 30,000), indicating the number of names in the list.The second line is the name of Mr. X.In the next N-1 lines, there is a man's name in each line. And if the man's generation number is K, there are K dots( '.') before his name.Please note that :1) A name consists of only letters or digits( '0'-'9').2)All names are unique.3)Every line's length is no more than 60 characters.4)In the list, a man M's father is the closest one above M whose generation number is 1 lessthan M.5)For any 2 adjacent lines in the list, if the above line's generation number is G1 and the lowerline' s generation number is G2, than G2 <= G1 +1 is guaranteed.After the name list, a line containing an integer Q(1<=Q<=30,000) follows, meaning that there are Q queries or operations below.In the Next Q lines, each line indicates a query or operation. It can be in the following 3 formats: 1)LPrint the family list in the same format as the input, but in a sorted way. The sorted way means that: if A and B are brothers(cousins don’t count), and A's name is alphabetically smaller than B's name, then A must appear earlier than B.2) b namePrint out how many brothers does "name" have, including "name" himself.3) c name1 name2Print out the closest common ancestor of "name1" and "name2". "Closest" means thegeneration number is the largest. Since Mr. X has no ancestor in the list, so it's guaranteed that there is no question asking about Mr. X's ancestor.The input ends with N = 0.OutputAlready mentioned in the input.Sample input9Kongs.son1..son1son2..son1son1...sonkson2son1...son1son2son2..son1son3...son1son3son1.son07Lb son1son3son1b son1son2b sonkson2son1b son1c sonkson2son1 son1son2son2c son1son3son1 son1son2Sample outputKongs.son0.son1..son1son1...son1son2son2 ...sonkson2son1 ..son1son2..son1son3...son1son3son1 1322son1son1son1。
acm大赛试题及答案
acm大赛试题及答案ACM大赛试题及答案1. 题目一:字符串反转问题描述:编写一个程序,输入一个字符串,输出其反转后的字符串。
输入格式:输入包含一个字符串,字符串长度不超过100。
输出格式:输出反转后的字符串。
示例:输入:hello输出:olleh答案:```pythondef reverse_string(s):return s[::-1]input_string = input().strip()print(reverse_string(input_string))```2. 题目二:计算阶乘问题描述:编写一个程序,输入一个非负整数n,输出n的阶乘。
输入格式:输入包含一个非负整数n,n不超过20。
输出格式:输出n的阶乘。
示例:输入:5输出:120答案:```pythondef factorial(n):if n == 0:return 1else:return n * factorial(n - 1)n = int(input())print(factorial(n))```3. 题目三:寻找最大数问题描述:给定一个包含n个整数的数组,找出数组中的最大数。
输入格式:输入包含一个整数n,表示数组的大小,随后是n个整数。
输出格式:输出数组中的最大数。
示例:输入:5 1 2 3 4 5输出:5答案:```pythonn = int(input())numbers = list(map(int, input().split()))max_number = max(numbers)print(max_number)```4. 题目四:判断闰年问题描述:编写一个程序,输入一个年份,判断该年份是否为闰年。
输入格式:输入包含一个整数,表示年份。
输出格式:如果输入的年份是闰年,则输出"Yes",否则输出"No"。
示例:输入:2000输出:Yes答案:```pythonyear = int(input())if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):print("Yes")else:print("No")```5. 题目五:斐波那契数列问题描述:编写一个程序,输入一个非负整数n,输出斐波那契数列的第n项。
ACM竞赛基础训练题.docx
ACM竞赛基础训练题H【题目]】N皇后问题(八皇后问题的扩展)【题ri 2】排球队员站位问题【题H 3]把自然数N分解为若干个自然数之和。
【题H 4]把自然数N分解为若干个自然数之积。
【题H 5】马的遍历问题。
【题H 6】加法分式分解【题H 7】地图着色问题【题H 8]在n和的正方形屮放置长为2,宽为1的长条块,【题H 9】找迷宫的最短路径。
(广度优先搜索算法)【题Fl 10]火车调度问题【题H 11]农夫过河【题FI 12]七段数码管问题。
【题H 13]把1-8这8个数放入下图8个格中,要求相邻的格(横,竖,对角线)上填的数不连续. 【题FI 14]在4X4的棋盘上放置8个棋,要求每一行,毎一列上只能放置2个.【题H 15]迷宫问题.求迷宫的路径.(深度优先搜索法)【题H 16]一笔画问题【题H 17]城市遍历问题.【题H 18]棋子移动问题【题H 19]求集合元索问题(l,2x+l,3X+l类)【题RI N皇后问题(含八皇后问题的扩展,规则同八皇后):在N粒的棋盘上, 放置N个皇后,要求每一横行每一列,每一对角线上均只能放置一个皇后,问可能的方案及方案数。
const max=8;var i,j:integer;a: array [1.. max] of 0.. max; {放皇后数组}b:array[2.. 2*max] of boolean; {/对角线标志数组}c:array[-(max-1).. max-1 ] of boolean; {\对角线标志数组}col:array [1.. max] of boolean; {列标志数组}total: integer; {统计总数}procedure output; {输出}var i:inte^er;beginwrite (' No.' :4,' [', total+1:2,']');for i :=1 to max do write (a [i] :3) ;write(, ');if (to tal+1) mod 2 =0 t hen writ eln; inc (to tai);end;function ok(i, dep: integer) :boolean; {判断第dep 行第i 列可放否}begin ok:=false;if ( b[i+dep]二true) and ( c[dep-i]二true) {and (a[dep]=0)} and(col[i]=true) then ok:二trueend;procedure try (dep:integer);var i,j:integer;beginfor i:=l to max do 侮一行均有max种放法}i f ok (i, dep) then begi na [dep]:=i;b[i+dep]:二false; {/对角线已放标志}c[dep-i]:二false; {\对角线已放标志}col [i]:二false; {列已放标志}if dep二max then outputelse try (dep+1) ; {递归下一层}a[dep] :=0; {取走皇后,回溯}b[i+dep]:二true; {恢复标志数组}c[dep-i]:二true;col[i]:二true;end;end;beginfor i:=1 to max do begin a[i]:=0;col[i]:=true;end;for i:=2 to 2*max do b[i]:二true;for i:=-(max-1) to max~l do c[i]:=true;total:二0;try(l); writelntotal , total);end.【测试数据】n二8八皇后问题No.[ 1] 1 5 8 6 3 7 2 4 No. [ 2] 1 6 83 7 4 2 5 No.[ 3] 1 7 4 6 8 2 5 3 No. [ 4] 1 7 58 2 4 6 3 No.[ 5] 2 4 6 8 3 1 7 5 No. [ 6] 2 5 71 3 8 6 4 No.[ 7] 2 5 7 4 1 8 6 3 No. [ 8] 2 6 17 4 8 3 5 No.[ 9] 2 6 8 3 1 4 7 5 No. [10] 2 7 36 8 5 1 4No. [11] 2 7 5 8 1 4 6 3 No. [12] 2 8 61 3 5 7 4 No. [13] 3 1 7 5 8 2 4 6 No. [14] 3 5 28 1 7 4 6 No. [15] 3 5 2 8 6 4 7 1 No. [16] 3 5 71 4 2 8 6 No. [17] 3 5 8 4 1 7 2 6 No. [18] 3 6 25 8 1 7 4 No. [19] 3 6 2 7 1 4 8 5 No. [20] 3 6 27 5 1 8 4 No. [21] 3 6 4 1 8 5 7 2 No. [22] 3 6 42 8 5 7 1 No. [23] 3 6 8 1 4 7 5 2 No. [24] 3 6 81 5 7 2 4 No. [25] 3 6 8 2 4 1 7 5 No. [26] 3 7 28 5 1 4 6 No. [27] 3 7 2 8 6 4 1 5 No. [28] 3 8 47 1 6 2 5 No. [29] 4 1 5 8 2 7 3 6 No. [30] 4 1 58 6 3 7 2 No. [31] 4 2 5 8 6 1 3 7 No. [32] 4 2 73 6 8 1 5 No. [33] 4 2 7 3 6 8 5 1 No. [34] 4 2 75 1 8 6 3 No. [35] 4 2 8 5 7 1 3 6 No. [36] 4 2 86 1 3 5 7 No. [37] 4 6 1 5 2 8 3 7 No. [38] 4 6 82 7 1 3 5 No. [39] 4 6 8 3 1 7 5 2 No. [40] 4 7 18 5 2 6 3 No. [41] 47 3 8 2 5 1 6 No. [42] 4 7 52 6 1 3 8 No. [43] 4 7 5 3 1 6 8 2 No. [44] 4 8 13 6 2 7 5 No. [45] 4 8 1 5 7 2 6 3 No. [46] 4 8 53 1 7 2 6 No. [47] 5 1 4 6 8 2 7 3 No. [48] 5 1 84 2 7 3 6 No. [49] 5 1 8 6 3 7 2 4 No. [50] 5 2 46 8 3 1 7 No. [51] 5 2 47 3 8 6 1 No. [52] 5 2 61 7 48 3 No. [53] 5 2 8 1 47 3 6 No. [54] 5 3 16 8 2 4 7 No. [55] 5 3 1 7 28 6 4 No. [56] 5 3 84 7 1 6 2 No. [57] 5 7 1 3 8 6 4 2 No. [58] 5 7 14 2 8 6 3 No. [59] 5 7 2 4 8 1 3 6 No. [60] 5 7 26 3 1 4 8 No. [61] 5 7 2 6 3 1 8 4 No. [62] 5 7 41 3 8 6 2 No. [63] 5 8 4 1 3 6 2 7 No. [64] 5 8 41 7 2 6 3 No. [65] 6 1 5 2 8 3 7 4 No. [66] 6 2 71 3 5 8 4 No. [67] 6 2 7 1 4 8 5 3 No. [68] 6 3 17 5 8 2 4 No. [69] 6 3 1 8 4 2 7 5 No. [70] 6 3 18 5 2 4 7 No. [71] 6 3 5 7 1 4 2 8 No. [72] 6 3 58 1 4 2 7 No. [73] 6 3 7 2 48 1 5 No. [74] 6 3 72 8 5 1 4 No. [75] 6 3 7 4 1 8 2 5 No. [76] 6 4 15 8 2 7 3 No. [77] 6 4 2 8 5 7 1 3 No. [78] 6 4 71 3 5 2 8 No. [79] 6 4 7 1 8 2 5 3 No. [80] 6 8 24 1 7 5 3 No. [81] 7 1 3 8 6 4 2 5 No. [82] 7 2 41 8 5 3 6 No. [83] 7 2 6 3 1 4 8 5 No. [84] 7 3 16 8 5 2 4 No. [85] 7 3 8 2 5 1 6 4 No. [86] 7 4 25 8 1 3 6 No. [87] 7 4 2 8 6 1 3 5 No. [88] 7 5 31 6 8 2 4 No. [89] 8 2 4 1 7 5 3 6 No. [90] 8 2 53 1 7 4 6 No. [91] 8 3 1 6 2 5 7 4 No. [92] 8 4 13 6 2 7 5 total:92 对于N皇后:【题H 】排球队员站位问题I ----------------- 1图为排球场的平面图,其屮一、二、三、四、五、六为位 置编号, I |二、三、四号位置为前排,一、六、五号位为后排。
理工oj题目.(DOC)
零起点学算法80——逆序输出(数组练习)Time Limit:1000MS Memory Limit:65536KTotal Submit:2994 Accepted:1369Description数组是在程序设计中,为了处理方便,把具有相同类型的若干变量按有序的形式组织起来的一种形式。
这些按序排列的同类数据元素的集合称为数组数组类型说明在C语言中使用数组必须先进行类型说明。
数组说明的一般形式为:类型说明符数组名[常量表达式],……;其中,类型说明符是任一种基本数据类型或构造数据类型。
数组名是用户定义的数组标识符。
方括号中的常量表达式表示数据元素的个数,也称为数组的长度。
例int a[10]; 说明整型数组a,有10个元素。
float b[10],c[20]; 说明实型数组b,有10个元素,实型数组c,有20个元素。
char ch[20]; 说明字符数组ch,有20个元素。
Input多组测试数据。
第一行输入一个整数T表示测试数据组数每组首先输入1个整数n,然后输入n个整数(不大于20)Output对于每组测试数据按照输入相反的顺序输出n个数据Sample Input231 2 352 3 1 4 5Sample Output3 2 15 4 1 3 2Source零起点学算法81——找出数组中最大元素的位置(下标值)Time Limit:1000MS Memory Limit:65536KTotal Submit:4376 Accepted:1535Description找出数组中最大的元素的下标。
Input多组测试,每组先输入一个不大于10的整数n然后是n个整数Output输出这n个整数中最大的元素及下标值Sample Input41 4 5 6Sample Output6 3Source零起点学算法82——数组中查找数Time Limit:1000MS Memory Limit:65536KTotal Submit:3001 Accepted:1393Description在给定的数组中查找一个数Input多组测试,每组第一行输入1个整数n(n<20),然后是n个整数第二行输入1个整数mOutput查找在第一行的n个整数中第一次出现数字m的下标位置并输出,如果没有找到则输出NoSample Input3 4 5 654 2 2 2 22Sample Output1Source零起点学算法83——数组中删数Time Limit:1000MS Memory Limit:65536KTotal Submit:2938 Accepted:961Description在给定的数组中删除一个数Input多组测试,每组第一行输入1个整数n(n<20),然后是n个整数第二行输入1个整数m删除在第一行的n个整数中第一次出现数字m并删除,然后按照顺序输出剩下的数,Sample Input4 1 2 3 43Sample Output1 2 4Hintm有可能在原数组中找不到,找不到则输出原数组Source零起点学算法84——数组中删数IITime Limit:1000MS Memory Limit:65536KTotal Submit:1411 Accepted:754Description在给定的数组中删除数Input多组测试,每组第一行输入1个整数n(n<20),然后是n个整数第二行输入1个整数mOutput删除在第一行的n个整数中的数字m(多个的话都要删除),然后按照顺序输出剩下的数,Sample Input5 1 2 3 4 33Sample Output1 2 4零起点学算法85——数组中插入一个数Time Limit:1000MS Memory Limit:65536KTotal Submit:1566 Accepted:546Description给定有序数组(从小到大),再给你一个数,要求插入该数到数组中并保持顺序Input多组测试,每组第一行输入一个整数n,然后是n个有序的整数第二行输入1个整数m和1个整数KOutput将整数m插入到原数组中保持顺序是升序,然后输出2行第一行是插入以后的数组第二行是插入以后的数组中下标值是K的数n m k不超过20Sample Input3 1 2 53 1Sample Output1 2 3 52Source零起点学算法87——打印所有低于平均分的分数Time Limit:1000MS Memory Limit:65536KTotal Submit:4940 Accepted:1717Description输入n个成绩,打印出所有低于平均分的分数(注意:ave = s/n中s 为float或ave = (float)s/n)。
2012年全国软件大赛真题及其答案
2012年全国软件大赛真题及其答案第一题/*微生物增殖假设有两种微生物X 和YX出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍)。
一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y。
现在已知有新出生的X=10, Y=89,求60分钟后Y的数目。
如果X=10,Y=90 呢?本题的要求就是写出这两种初始条件下,60分钟后Y的数目。
*/#include <stdio.h>int main(void){_int64 x = 10;_int64 y = 90;int time = 60;int time_t = time * 10;for (int t = 5; t <= time_t; t += 5){if (y <= 0){y = 0;break;}if (t % 5 == 0 && t % 10 != 0){y = y - x;}if (t % 30 == 0){x = x * 2;}if (t % 20 == 0){y = y * 2;}}printf("y = %d\n", y);return 0;}答案:094371840第二题:/*古堡算式福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式:ABCDE * ? = EDCBA他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!”华生:“我猜也是!”于是,两人沉默了好久,还是没有算出合适的结果来。
请你利用计算机的优势,找到破解的答案。
把ABCDE 所代表的数字写出来。
答案写在“解答.txt”中,不要写在这里!*/#include <stdio.h>const int TRUE = 1;const int FALSE = 0;int main(void){for (int i = 10000;i < 1000000; i++){int a[5] = {0};a[4] = i % 10;a[3] = i /10 %10;a[2] = i /100 % 10;a[1] = i / 1000 % 10;a[0] = i / 10000 % 10;bool Flag = TRUE;for (int j = 0; j < 5 && Flag; j++){for(int k = 0; k < 5 && Flag; k++){if (j != k && a[j] == a[k] ){Flag = FALSE;}}}if (!Flag)continue;int num = 10000 * a[4] + 1000 * a[3] + 100 * a[2] + 10 * a[1] + a[0];for (int j = 2; j < 10; j++){if ( i * j == num){printf("%d * %d = %d\n", i, j, num);}}}return 0;}答案:21978 * 4 = 87912第三题:/*/*比酒量有一群海盗(不多于20人),在船上比拼酒量。
2012年3月全国计算机等级考试二级笔试真题试卷及答案 Access数据库程序设计-推荐下载
D)UPDATE STUDENT 年龄 WITH 年龄 + 1
(25)已知学生表如下:
执行下列命令后,得到的记录数是
SELECT 班级,MAX(年龄) FROM 学生表 GROUP BY 班级
A)4
B)3
C)2
D)1
(26)数据库中可以被另存为数据访问页的对象( )
是( )
A)姓名
B)学号 C)专业
பைடு நூலகம்
(14)下列关于索引的叙述中,错误的是(
A)可以为所有的数据类型建立索引
B)可以提高对表中记录的查询速度
C)可以加快对表中记录的排序速度
D)可以基于单个字段或多个字段建立索引
(15)若查找某个字段中以字母 A 开头且以字母 Z 结尾的所有记录,则条件表达式应设置为(
A)SELECT * FROM 教师表 WHERE ( InStr([职称], “教授”) <> 0);
B)SELECT * FROM 教师表 WHERE ( Right([职称], 2) = “教授” );
C)SELECT * FROM 教师表 WHERE ([职称] = “教授” );
D)SELECT * FROM 教师表 WHERE ( InStr([职称], “教授”) = 1 Or InStr([职称], “教授”) = 2 );
)
对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料电试力卷保相护互装作置用调与试相技互术通关,1系电过,力管根保线据护敷生高设产中技工资术0艺料不高试仅中卷可资配以料置解试技决卷术吊要是顶求指层,机配对组置电在不气进规设行范备继高进电中行保资空护料载高试与中卷带资问负料题荷试22下卷,高总而中体且资配可料置保试时障卷,各调需类控要管试在路验最习;大题对限到设度位备内。进来在行确管调保路整机敷使组设其高过在中程正资1常料中工试,况卷要下安加与全强过,看2度并22工且22作尽22下可22都能2可地护1以缩关正小于常故管工障路作高高;中中对资资于料料继试试电卷卷保破连护坏接进范管行围口整,处核或理对者高定对中值某资,些料审异试核常卷与高弯校中扁对资度图料固纸试定,卷盒编工位写况置复进.杂行保设自护备动层与处防装理腐置,跨高尤接中其地资要线料避弯试免曲卷错半调误径试高标方中高案资等,料,编5试要写、卷求重电保技要气护术设设装交备备4置底高调、动。中试电作管资高气,线料中课并3敷试资件且、设卷料中拒管技试试调绝路术验卷试动敷中方技作设包案术,技含以来术线及避槽系免、统不管启必架动要等方高多案中项;资方对料式整试,套卷为启突解动然决过停高程机中中。语高因文中此电资,气料电课试力件卷高中电中管气资壁设料薄备试、进卷接行保口调护不试装严工置等作调问并试题且技,进术合行,理过要利关求用运电管行力线高保敷中护设资装技料置术试做。卷到线技准缆术确敷指灵设导活原。。则对对:于于在调差分试动线过保盒程护处中装,高置当中高不资中同料资电试料压卷试回技卷路术调交问试叉题技时,术,作是应为指采调发用试电金人机属员一隔,变板需压进要器行在组隔事在开前发处掌生理握内;图部同纸故一资障线料时槽、,内设需,备要强制进电造行回厂外路家部须出电同具源时高高切中中断资资习料料题试试电卷卷源试切,验除线报从缆告而敷与采设相用完关高毕技中,术资要资料进料试行,卷检并主查且要和了保检解护测现装处场置理设。备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。
ACM程序设计试题及参考答案
ACM程序设计试题及参考答案猪的安家Andy和Mary养了很多猪。
他们想要给猪安家。
但是Andy没有足够的猪圈,很多猪只能够在一个猪圈安家。
举个例子,假如有16头猪,Andy建了3个猪圈,为了保证公平,剩下1头猪就没有地方安家了。
Mary生气了,骂Andy没有脑子,并让他重新建立猪圈。
这回Andy建造了5个猪圈,但是仍然有1头猪没有地方去,然后Andy又建造了7个猪圈,但是还有2头没有地方去。
Andy都快疯了。
你对这个事情感兴趣起来,你想通过Andy建造猪圈的过程,知道Andy家至少养了多少头猪。
输入输入包含多组测试数据。
每组数据第一行包含一个整数n (n <= 10) – Andy 建立猪圈的次数,解下来n行,每行两个整数ai, bi( bi <= ai <= 1000), 表示Andy建立了ai个猪圈,有bi头猪没有去处。
你可以假定(ai, aj) = 1.输出输出包含一个正整数,即为Andy家至少养猪的数目。
样例输入33 15 17 2样例输出16答案:// 猪的安家.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream.h"void main(){int n;int s[10][2];bool r[10];char ch;cout<<"请输入次数:"<<endl;cin>>n;for (int i=0;i<n;i++){cout<<"请输入第"<<i+1<<"次的猪圈个数和剩下的猪:,用--分开,"<<endl;cin>>s[i][0]>>ch>>ch>>s[i][1];}for (i=0;i<10;i++)r[i]=true;for (int sum=1;;sum++){for (i=0;i<n;i++)r[i]=(sum%s[i][0]==s[i][1]);for (i=0;i<n;i++){if (r[i]==0)break;}if (i==n)break;}cout<<"猪至少有"<<sum<<"只。
四川省2012年信息技术一类高考样题含答案
四川省2012年普通高校职教师资和高职班对口招生统一考试信息技术一类专业综合样题本试卷分第一部分(选择题)和第二部分(非选择题),共两部分。
考生作答时,须将答案答在答题卡上,在本试卷、草稿纸上答题均无效。
满分300分。
考试时间150分钟。
考试结束后,将本试卷和答题卡一并交回。
第一部分(选择题共166分)注意事项:1.必须使用2B铅笔将答案标号填涂在答题卡上对应题目标号的位置上。
2.本部分共166分。
一、单项选择题(每小题2分,共90分。
每题所给的四个选项中,只有一个正确答案,请在答题卡上将该项涂黑)1.CPU 是由( )组成。
A.控制器和运算器B.内存储器与外存储器C.运算器和存储器D.输入设备和输出设备2.目前计算机最常见的接口是A.PS/2BC.串口D.并口3.Windows的文件夹完全展开后A.文件夹名前全部显示“+”B.文件夹名前全部显示“-”C.包含子文件夹的文件夹名前显示“+”D.包含子文件夹的文件夹名前显示“-”4.将文件放在回收站的方法中,以下不一定能实现的是A.拖动文件到回收站B.选中文件后,按Shift+Delete键C.选择文件后,选择“剪切”命令,在回收站中选择“粘帖”命令D.选择文件后,使用“文件”菜单“删除”命令5.BIOS的含义是A.基本输入输出系统B.系统集成C.互补金属氧化物半导体D.计算机输入输出系统6.按 +D键的作用是A.查找文件B.打开“我的电脑”窗口C.最小化所有窗口D.运行程序7.以下方法中,不能在Windows中打开DOS窗口的是A.在“运行”对话框中输入命令CMDB.在“运行”对话框中输入命令DOSC.在“运行”对话框中输入命令CommandD.在“开始”菜单选择“程序”→“附件”→“命令提示符”命令8.命令Mstsc的作用是A.设置系统的启动项B.远程桌面连接C.网络连接测试D.系统还原9.在Windows XP中,搜索文件时不能( )搜索。
A.指定文件名B.指定文件夹C.指定文件生成日期D.指定文件创建者10.Windows XP自带的媒体播放器是A.千千静听B.QQ音乐C.Windows Mdeia PlayerD.Windows Movie Maker11.Windows XP个性化设置不能实现的是A.设置自己的桌面B.设置自己的鼠标图标C.设置自己的系统安装磁盘D.设置自己的“我的文档”文件夹位置12.修改注册表命令是A.REGEDITB.MSCONFIGC.EVENTVWRD.GPEDIT.MSC13.Word 2003默认的保存格式为A..TXTB.DOCC.DOCXD.XLS14.在Word中,能全部选中某一段文字的方法是A.单击该段文字B.双击该段文字C.三击该段文字D.按Ctrl+A键15.Word 中,表格不能实现的功能是A.转换为文本B.排序与计算C.环绕设置D.数据筛选16.在Word中,要将若干个文档按顺序合并成一个文档,以下操作正确的是A.逐一打开需合并的文件,选中文本,复制后到新文档中粘贴B.在新文档中选择“插入”菜单“文件”命令,然后按文件名顺序选择文件,再点击“插入”按钮C.在新文档中选择“插入”菜单“文件”命令,然后按文件名顺序逆序选择文件,再点击“插入”按钮D.在新文档中选择“比较并合并文档”命令,然后选择需合并的文档17.在Excel中,默认的自动填充序列中不能填充的是A.星期一至星期日B.一月至十二月C.甲、乙、丙至壬、癸D.春季、夏季至冬季18.在Excel中,不用按住Ctrl键也能单击选中多个选未连续的单元格,需要先按( )键。
2012下半年程序员考试真题及答案-下午卷
2012下半年程序员考试真题及答案-下午卷试题一【说明】本流程图用于计算菲波那契数列{a1=1,a2=1,…,an=an-1+an-2!n=3,4,…}的前n项(n>=2) 之和S。
例如,菲波那契数列前6项之和为20。
计算过程中,当前项之前的两项分别动态地保存在变量A和B中。
【流程图】阅读说明和流程图,填补流程图中的空缺(1)〜(5)(1)2或A+B(2)n(3)A+B(4)B-A(5)S+B菲波那契数列的特点是首2项都是1,从第3项开始,每一项都是前两项之和。
该数列的前几项为1,1,2, 3,5,8,…。
在流程图中,送初始值1—A,2—B后,显然前2项的和S应等于2,所以(1)处应填2 (或A+B)。
此时2→i (i表示动态的项编号),说明已经计算出前2项之和。
接着判断循环的结束条件。
显然当i=n时表示已经计算出前n项之和,循环可以结束了。
因此(2)处填n。
判断框中用“>”或“≥”的效果是一样的,因为随着i的逐步增1,只要有i=n结束条件就不会遇到i>n的情况。
不过编程的习惯使循环结束条件扩大些,以防止逻辑出错时继续循环。
接下来i+1→i表示数列当前项的编号增1,继续往下计算。
原来的前两项值(分别在变量A 和B中)将变更成新的前两项再放到变量A和B中。
首先可以用A+B—B实现(原A) + (原B)—(新B),因此(3)处填A+B。
为了填新A值(原来的B值),不能用B—A,因为变量B的内容已经改变为(原A) + (原B),而B-A正是((原A) + (原B))-(原A)=(原B),因此可以用B-A—A来实现新A的赋值。
这样,(4)处填B-A。
最后应是前n项和值的累加(比原来的S值增加了新B值),所以(5)处应填S+B。
填完各个空后,最好再用具体的数值来模拟流程图走几个循环检查所填的结果(这是防止逻辑上出错的好办法)。
试题二【说明】如果矩阵A中的元素AW]满足条件:A[ij]是第i行中值最小的元素,且又是第j 列中值最大的元素,则称之为该矩阵的一个马鞍点。
2012程序设计C大赛及答案(修正)
C一、填空题(本大题两种题型,程序填空或写结果,程序填空要求每空仅填一条语句,即不能出现分号)(共40分)1、求17922和5394的最小公倍数。
(共5分)答案:答案:5555822、分解成质因数(如输出435234,251 17 17 3 2) (共5分)void prim(int m, int n){if(m>n){while(m%n != 0)n++;;;printf("%d ", n);}}void main(){int n = 435234;printf("%d,", n);prim(n, 2);}答案: m /= n; prim(m, n);3、从数字1开始向右顺时针方向移动,可以得到如下的5×5的螺旋:(共10分)21 22 23 24 2520 7 8 9 1019 6 1 2 1118 5 4 3 1217 16 15 14 13可以算出对角线上数字之和是101.1001×1001的螺旋中对角线上数字之和是?答案:6691710014、欧拉曾发表过一个著名的二次公式:n2+ n + 41。
这个公式对于0到39的连续数字能够产生40个质数。
但是当n=40时,402+40+41 = 40(40+1)+41能够被41整除。
当n=41时,412+41+41显然也能被41整除。
利用计算机,人们发现了一个惊人的公式:n2- 79n+1601,这个公式对于n=0到79能够产生80个质数。
这个公式的系数, -79和1601的乘积是-126479。
考虑如下形式的二次公式:n2+an+b, 其中|a|1000,|b|1000。
找出对于能够为从0开始的连续的n产生最多数量的质数的二次公式,写出该公式的系数a 和b的乘积。
答案:答案: -59231 (a = -61 b = 971 n = 70 )5、有一个整形数组a,长度为n,数组里有正数也有负数。
2012上半年程序员考试真题及答案-下午卷 (1)
2012上半年程序员考试真题及答案-下午卷试题一已知数组A[l:n]中各个元素的值都是非零整数,其中有些元素的值是相同的(重复)。
为删除其中重复的值,可先通过以下流程图找出所有的重复值,并对所有重复值赋0标记。
该流程图采用了双重循环。
处理思路:如果数组A某个元素的值在前面曾出现过,则该元素赋标记值0。
例如,假设数组A的各元素之值依次为2, 5, 5,1,2, 5, 3,则经过该流程图处理后,各元素之值依次为2,5,0, 1,0,0,3。
填补流程图中的空缺(1)〜(5)(1) n-1(2) A[i](3) i+1⑷ A[j](5) A[j]在处理大批数据记录时,删除重复记录(关键词重复的记录)是常见的操作。
本题源自这种应用。
刪除重复记录算法可分两步进行。
第一步将重复ai现的多余元素标记为0; 第二步再删除所有的0元素。
本题流程图只做第一步处理。
本流程图采用了对i和j的双重循环,对每个元素A[i],需要查看其后面的各个元素(用A[j]表示)是否与A[i]相同。
因此,外层循环应对i=l,n-1进行,从而在(1)处应填“n-1”。
内层循环应对j=i+l,n进行,从而在(3)处应填“i+1”。
在外循环处理中首先应判断A[i]是否已经标记为0,若是则无需进一步处理。
因此, (2)处应填“A[i]”。
而在内循环处理中首先应判断A[j]是否已经标记为0,若是则无需进一步处理。
因此,(4)处应填“A[j]”。
如果发现元素重复(即A[i]=A[j]),则需要再将 A[j]赋值为0 (标记),因此(5)处应填“A[j]”。
试题二设在某C系统中为每个字符型数据分配1个字节,为每个整型(int)数据分配4个字节,为每个指针分配4个字节,sizeof(x)用于计算为x分配的字节数。
【问题1】请写出以上C代码的运行结果。
4 4 201 114 1 10sizeof是C语言提供的一个关键字,sizeof(x)用于计算为x分配的字节数,其结果与系统或编译器相关。
2012年9月 全国计算机等级考试 二级C语言 笔试试卷、答案及解析
2012年9月22日网上发布的全国计算机等级考试二级C语言笔试答案一、选择题:(1)C、(2)B、(3)B、(4)D、(5)A(6)C、(7)C、(8)B、(9)A、(10)A(11)B、(12)A、(13)B、(14)A、(15)C(16)C、(17)C、(18)B、(19)D、(20)D(21)B、(22)D、(23)D、(24)B、(25)D(26)C、(27)A、(28)B、(29)C、(30)A(31)C、(32)A、(33)B、(34)A、(35)D(36)D、(37)B、(38)A、(39)B、(40)D二、填空题【1】6【2】20【3】逻辑独立【4】选择【5】系统软件【6】a>b【7】%lf%f【8】224【9】16【10】4321【11】7【12】22【13】2【14】6【15】p=p->next2012年9月22日评阅者注释的全国计算机等级考试二级C语言笔试答案一、选择题:(1)C、(2)B、(3)B、(4)D、(5)A(6)C、(7)C、(8)B、(9)A、(10)A(11)B、(12)A、(13)B、(14)A、(15)C(16)C、(17)C、(18)B、(19)D、(20)D(21)B?、(22)D、(23)D、(24)B、(25)D(26)C?、(27)A、(28)B、(29)C、(30)A(31)C、(32)A、(33)B、(34)A、(35)D(36)D、(37)B、(38)A、(39)B、(40)D二、填空题【1】6【2】20【3】逻辑独立性【4】选择【5】系统软件【6】a>b【7】%lf%f【8】224【9】16【10】4321【11】7【12】22【13】2【14】6【15】p=p->next2012年9月全国计算机等级考试二级笔试试卷C语言程序设计(考试时间90分钟,满分100分)一、选择题(⑴-(10)、(21)-(40)每题2分,(11)-(20)每题1分,共70分)下列各题A)、B)、C)、D)四个选项中,只有一个选项是正确的,请将正确选项填涂在答题卡相应位置上,答在试卷上不得分。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2012年四川理工学院“达内杯”大学生程序设计竞赛试题Problem 1:SortingThere are 16 random sorting numbers from 0 to 15, and they could be converted to different binary numbers, which have 4 digits. Please code algorithm to sort them by the order that the first there digits of the former number is same to the last there digits of the following. The first number of the sorted is always the first given number. Sample Input:1 3 5 7 9 11 13 15 02 4 6 8 10 12 14Sample Output:1 2 4 9 3 7 15 14 13 10 5 11 6 12 8 0Problem 2:Solution of EquationIn the interval [0,1], please programming to give the real root, of which error is less than 10-3, of equation ax3+bx2+cx+d=0, where a, b ,c and d are real number. And print the real root or the character “no solution”.Sample Input:1:a =1 b =-1 c =-2 d =12:a =1 b =1 c =1 d =1Sample Output:1:x =0.4443359372:no solutionProblem 3:The TriangleDescription73 88 1 02 7 4 44 5 2 6 5(Figure 1 Number Triangle)Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.InputYour program is to read from standard input. The first line contains one integer n: the number of rows in the triangle. The following n lines describe the data of the triangle. The number of rows in the triangle is >= 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99.OutputYour program is to write to standard output. The highest sum is written as an integer. Sample Input573 88 1 02 7 4 44 5 2 6 5Sample Output30Problem 4:Common SubsequenceDescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = {x1, x2, ..., x m }, another sequence Z = { z1, z2, ..., z k } is a subsequence of X if there exists a strictly increasing sequence { i1, i2, ..., i k } of indices of X such that for all j = 1,2,...,k, z j= x ij. For example, Z = { B, C, D,B } is a subsequence of X = { A, B, C, B, D, A, B } with index sequence { 2, 3, 5, 7 }. Given two sequences X and Y ,the problem is to find the length of the maximum-length common subsequence of X and Y.InputThe program input is from the std input. Each data set in the input contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct.OutputFor each set of data, the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line. Sample InputABCFBC ABFCABPROGRAMMING CONTESTABCD MNPSample Output42Problem 5:When Can We Meet?The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, the chairperson requested every member to send back a list of convenient dates by E-mail. Your mission is to help the chairperson, who is now dedicated to other issues of the contest, by writing a program that chooses the best date from the submitted lists. Your program should find the date convenient for the most members. If there is more than one such day, the earliest is the best.InputThe input has multiple data sets, each starting with a line containing the number of committee members and the quorum of the meeting.N QHere, N, meaning the size of the committee, and Q meaning the quorum, are positive integers. N is less than 50, and, of course, Q is less than or equal to N.N lines follow, each describing convenient dates for a committee member in the following format.M Date1 Date2 ... DateMHere, M means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 100, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces.A line containing two zeros indicates the end of the input.OutputFor each data set, print a single line containing the date number convenient for the largest number of committee members. If there is more than one such date, print the earliest. However, ifno dates are convenient for more than or equal to the quorum number of members, print 0 instead. Sample Input3 22 1 43 34 83 24 15 8 93 2 5 95 2 4 5 7 93 32 1 43 2 5 92 2 43 32 1 23 1 2 92 2 40 0Sample Output452Problem 6:Frame Polygonal LineYou are going to read a sequence of pairs of integer numbers. Each pair represents the Cartesian coordinates of a point in a 2-dimentional plane. The first number is the x coordinate, while the second is that of y. The sequence represents a polygonal line. Your task is to draw a rectangle with minimal length of sides that exactly surrounds the polygonal line. The sides of the rectangle are parallel to x- and y-axis, respectively.InputInput consists of several test cases. For each case, a sequence of coordinates is given. Each pair of x and y occupies a line, with |x| and |y| less than 2^31. The sequence is terminated with a pair of 0's. Note that (0, 0) will never be considered as a point on any of the polygonal lines. An empty polygonal line signals the end of input.OutputFor each test case, print in one line two pairs of numbers, which are the south-west and north-east corners of the surrounding rectangle. The numbers must be separated by one space as is indicated in the samples.Sample Input12 5623 5613 100 012 340 00 0Sample Output12 10 23 5612 34 12 34Problem 7:The Symbolic NumDescriptionWe represent a decimal numbers use the ten Arabic numeral 0~9 , but some people who live in a faraway tribe representing number use three marks …*‟,‟#‟,and …-… . The three marks represent the value 0, 1 and -1 respective. And In their system, every digital is three times larger than the digital on the right. So, the number ‘#*-‘ is 8 (because 8=1×9+0×3+-1×1),and the num‘-#’ is -2 ( -2= -1×3+1×1 ).Now you are request to program to read a number between -231~231-1 and output the form that used in the tribe.InputOne decimal number every lineOutputThe string that represent the number used in the tribe corresponding to the input Sample Input102-1742-2147483648Sample Output#*##--#*##---*-#*##*#***##---#-#--#----------------------------------------------------------------------------------------------------------------------#include<stdio.h>main(){int}Problem 8:Target numberYou get five integers as the operand, and another integer as the target number. Now you are required to perform proper arithmetic operation use the five numbers to let the result great than or equal the target number. And we need the optimalizing result which is the most close to the target number. You can use + - * / and ( ) to caculate, and all the intermediate result are required be integer , so some division is illegal. ( such as (2*2)/4 is legal , and 2*(2/4) is illegal. )InputThere is only one line which has 6 numbers in the input file. The front five numbers are operand Mi, 1<=Mi<=100, the last number is the target number T, 1<=T<=1000.OutputOnly one number, is the optimize targetSample input:1 2 3 7 100 573Sample output:573。