2008年ACM大学生程序设计竞赛题

合集下载

2008级C语言程序设计试卷_A带答案(2009.6)

2008级C语言程序设计试卷_A带答案(2009.6)

天津工业大学200 8 ~200 9 学年第 2 学期C 程序设计试卷(A)学院班级学号姓名注意事项:1、本试卷共13 页,满分为100 分,考试时间为110 分钟。

2、标准答题卡使用2B铅笔涂写;文字题答题时请使用蓝、黑钢笔或圆珠笔,不得使用红颜色墨水笔。

二、阅读程序题答题处:(每空3分,共30分)四、完善程序填空题答题处:(每空2分,共18分)一、单项单选题:(每题 1 分,共40 分)(说明:请将正确答案按照题干上【】内的序号涂写“标准答题卡”)1.以下标识符中,能够作为变量名使用的是【1】。

A) n_1 B) charC) x(2) D) 2_a2.若有定义语句char ch='\072'; 则变量ch 【2】。

A) 定义错误B) 包含1个字符C) 包含3个字符D) 包含4个字符3.已知字母B的ASCII码值为66,则运行下面程序段后,输出结果是【3】。

char ch1; ch1='B'+'5'-'3'; printf("%d,%c",ch1,ch1);A) D,D B) 68,DC) D,68 D) 68,684.若有如下语句:int x; float y;scanf("k=%d,f=%f",&x,&y);则能够正确的为变量x输入5、为变量y输入3.2的方法是【4】。

说明:备选答案中的<CR>表示回车符A) 5 3.2 <CR> B) 5 <CR> 3.2 <CR>C) k=5,f=3.2 <CR> D) x=5,y=3.2 <CR>int k=10; printf("%d,%o,%x",k,k,k);A) 12,a,10 B) 12,10,aC) 10,12,a D) 10,a,126.判断char 型变量ch 是否为小写字母的正确表达式是【6】。

大学ACM考试题目及作业答案整理

大学ACM考试题目及作业答案整理

ACM作业与答案整理1、平面分割方法:设有n条封闭曲线画在平面上,而任何两条封闭曲线恰好相交于两点,且任何三条封闭曲线不相交于同一点,问这些封闭曲线把平面分割成的区域个数。

#include <iostream.h>int f(int n){if(n==1) return 2;else return f(n-1)+2*(n-1);}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}2、LELE的RPG难题:有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.编程全部的满足要求的涂法.#include<iostream.h>int f(int n){if(n==1) return 3;else if(n==2) return 6;else return f(n-1)+f(n-2)*2;}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}3、北大ACM(1942)Paths on a GridTime Limit: 1000MS Memory Limit: 30000K DescriptionImagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b2). So you decide to waste your time with drawing modern art instead.Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left:Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?InputThe input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.OutputFor each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right orone unit up? You may safely assume that this number fits into a 32-bit unsigned integer.Sample Input5 41 10 0Sample Output1262#include<iostream>using namespace std;longlong f(long long m, long long n){if(n==0) return 1;else return f(m-1,n-1)*m/n;}int main(){longlongm,n;while(scanf("%I64d %I64d",&n,&m) &&n+m){printf("%I64d\n",f(m+n,min(m,n)));}return 0;}1、(并查集)若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系。

ACM软件大赛之编程大赛题目(附部分答案)

ACM软件大赛之编程大赛题目(附部分答案)

ACM 软件大赛之编程大赛比赛注意事项:l 比赛时间为3小时(小时(180180分钟);比赛分两个阶段:第一阶段限时30分钟,完成公示的3题,第二阶段限时150分钟(事先完成第一阶段题目的小组可提前进入第二阶段); l 比赛第一阶段的3道题目将在前期宣传中告知参赛选手,比赛第二阶段的题目将由赛事主席当场公布竞赛题目;主席当场公布竞赛题目;l 前两阶段题目分为三个分值(前两阶段题目分为三个分值(55分、分、1010分、分、1515分),第一阶段3道公示题都为5分;第二阶段总共15道题,根据不同的难度分值不同,分别为5道5分题,分题,55道10分题,分题,55道15分题;第一阶段参赛队员不可参考任何相关资料;第二阶段参赛队员可以携带诸如书,如书,手册,程序清单等参考资料。

手册,程序清单等参考资料。

手册,程序清单等参考资料。

比赛过程中队员不得携带任何电子媒质的资料;参比赛过程中队员不得携带任何电子媒质的资料;参赛者可以选择自己擅长的语言(赛者可以选择自己擅长的语言(C,C++,JAVA C,C++,JAVA 等等)进行编写等等)进行编写l 考虑到大一和大二学生的知识掌握程度,大一参加选手一开始就会有10分的分数,最后总分是由所做题目及初始的10分相加得到。

分相加得到。

l 每组队员根据安排使用电脑,小组人数为两人的使用一台电脑,超过两人的使用两台电脑,每台的电脑配置完全相同;脑,每台的电脑配置完全相同;l 各小组每做完一题或几题,必须交予评委老师运行,评委老师当场给分;各小组每做完一题或几题,必须交予评委老师运行,评委老师当场给分; l 如在比赛中发现作弊等行为,将取消比赛资格。

如在比赛中发现作弊等行为,将取消比赛资格。

第一阶段公示题目:题目一:(5分) 打印以下图形,纵遵从字母顺序,行字符数遵从斐波那契数列ABCCDDD EEEEEFFFFFFFFGGGGGGGGGGGGG#include<iostream>int f(int x){int a = 1 , b = 0;int max_ = x;int sum = 0; for(int i = 0; i < max_ ; i++){sum = a + b;a = b;b = sum;}return sum;}void loop_print(int num,char chr){for(int i = 0; i < num ;i++)std::cout<<chr;std::cout<<"\n";}int main(){int line_max = 7;char chr = 'A';for(int line = 0; line < line_max; line++){loop_print(f(line+1),chr);chr++;}return 0;}题目二:(5分)有个电子钟,12点显示为12:00(即12小时制),那么请问一天24时间内,出现连续3个相同数字的钟点有几个?#include<iostream>using namespace std;bool check(int me){int h= me/100;int m= me-100*h;return h<=12&&m<=59&&h>0?true:false;//12小时制小时制}int main(){int me=0;int j(0);//总计数器总计数器while( me<1270){//max 12:59int t= me;int n[4];for(int i=0;i<4;i++){n[i]=t%10;t /= 10;}if(n[1]==n[2]&&(n[0]==n[1]||n[3]==n[1])&&check( me)){//cout<<n[3]<<n[2]<<":"<<n[1]<<n[0]<<"\n";//testj++;me++;}cout<<"total: "<<j*2<<endl;}题目三:(5分)10进制的四位数中有几个符合如下特征:将其分别表示为16进制、10进制、12进制,在每种状态下,分别将各个位上的数相加,能得到3个相等10进制数。

acm编程比赛入门题目集

acm编程比赛入门题目集

程序设计比赛试题主办方:迅翔计算机协会最少钱币数:【问题描述】这是一个古老而又经典的问题。

用给定的几种钱币凑成某个钱数,一般而言有多种方式。

例如:给定了6种钱币面值为2、5、10、20、50、100,用来凑15元,可以用5个2元、1个5元,或者3个5元,或者1个5元、1个10元,等等。

显然,最少需要2个钱币才能凑成15元。

你的任务就是,给定若干个互不相同的钱币面值,编程计算,最少需要多少个钱币才能凑成某个给出的钱数。

【要求】【数据输入】输入可以有多个测试用例。

每个测试用例的第一行是待凑的钱数值M(1 <= M <= 2000,整数),接着的一行中,第一个整数K(1 <= K <= 10)表示币种个数,随后是K 个互不相同的钱币面值Ki(1 <= Ki <= 1000)。

输入M=0时结束。

【数据输出】每个测试用例输出一行,即凑成钱数值M最少需要的钱币个数。

如果凑钱失败,输出“Impossible”。

你可以假设,每种待凑钱币的数量是无限多的。

【样例输入】156 2 5 10 20 50 10011 2【样例输出】2ImpossibleFeli 的生日礼物【问题描述】Felicia 的生日是11月1日(和Kitty是同一天生的哦)。

于是Feli请来Kitty一起过生日。

Kitty带来了最新款的“Kitty猫”玩具准备送给Feli,不过她说,这份礼物可不是白送的。

Feli要帮她一个忙,才能够得到心仪已久的玩具。

Kitty说,“Kitty猫”玩具已经卖出了n!个,n<=10^100 *_*,Kitty想知道确切的数字,而不是无聊的“一个数加个感叹号”。

Feli 听了大吃一惊。

要知道,算出n!是一个无比艰巨的任务。

Feli告诉Kitty,就算Feli算出n!,Kitty也看不下去,因为当n=20 时,计算机的长整型已经存不下了(Kitty只能接受1-9之间的数字)。

C语言程序设计竞赛题及其答案

C语言程序设计竞赛题及其答案

C语言程序设计竞赛题及其答案数学与统计学院第三届计算机程序设计竞赛题竞赛需知:1、答案必须写在答题纸上。

2、程序采用C/JAVA/VB/VFP语言实现均可。

3、考虑到各种因素,程序的键盘输入和结果输出可以用伪代码或者自然语言表示。

但是必须说明输入变量和输出变量。

4、题目最好能用完整、正确的语言程序来解决问题,如确实无法编写完整语言程序的,可以写出程序主要框架和流程,必要时可以用伪代码或者自然语言描述算法(程序)。

一、玫瑰花数(20分)如果一个四位数等于它的每一位数的4次方之和,则称为玫瑰花数。

例如:++1634+=,4^44^34^64^1编程输出所有的玫瑰花数。

#includevoid main(){int i,j,k,l,m;for(i=999;i<=9999;i++){j=i/1000;k=i%10;l=i/100-10*j;m=i/10-100*j-10*l;if(i==j*j*j*j+k*k*k*k+l*l*l*l+m*m*m*m) printf("%d\n",i);}}二、菱形图案(20分)对给定的奇数n,编程打印菱形图案。

输入样例:7输出样例:*************************#include#includevoid main(){int i,j,k;int n;scanf("%d",&n);for(i=0;i<n;i++)< p="">{for(j=0;j<="" p="">printf("");for(k=0;k<n-2*j;k++)< p="">printf("*");printf("\n");}}三、钻石奖励(20分)海盗们决定用“投环套物”的方式来奖励最近一次行动中贡献最大的人。

2008年acm全球总决赛试题

2008年acm全球总决赛试题

ACM International Collegiate Programming Contest2008East Central Regional ContestMcMaster UniversityUniversity of CincinnatiUniversity of Michigan–Ann ArborYoungstown State UniversityNovember1,2008Sponsored by IBMRules:Problem A:Bordering on MadnessBob Roberts owns a design business which creates custom artwork for various corporations.One technique that his company likes to use is to take a simple rectilinearfigure(afigure where all sides meet at90or270degrees and which contains no holes)and draw one or more rectilinear borders around them.Each of these borders is drawn so that it is a set distance d away from the previously drawn border(or the originalfigure if it is thefirst border)and then the new area outlined by each border is painted a unique color.Some examples are shown below(without the coloring of the borders).The example on the left shows a simple rectilinearfigure(grey)with two borders drawn around it.The one on the right is a more complicatedfigure;note that the border may become disconnected.These pieces of art can get quite large,so Bob would like a program which can draw prototypes of the finished pieces in order to judge how aesthetically pleasing they are(and how much money they will cost to build).To simplify things,Bob never starts with afigure that results in a border where2horizontal (or vertical)sections intersect,even at a point.This disallows such cases as those shown below:InputInput will consist of multiple test cases.Thefirst line of the inputfile will contain a single integer indicating the number of test cases.Each test case will consist of two or more lines.Thefirst will contain three positive integers n,m and d indicating the number of sides of the rectlinearfigure,the number of borders to draw,and the distance between each border,where n≤100and m≤20. The remaining lines will contain the n vertices of thefigure,each represented by two positive integers indicating the x and y coordinates.The vertices will be listed in clockwise order starting with the vertex with the largest y value and(among those vertices)the smallest x value.OutputFor each test case,output three lines:thefirst will list the case number(as shown in the examples), the second will contain m integers indicating the length of each border,and the third will contain m integers indicating the additional area contributed to the artwork by each border.Both of these sets of numbers should be listed in order,starting from the border nearest the originalfigure.Lines two and three should be indented two spaces and labeled as shown in the examples.Separate test cases with a blank line.Sample Input26210 2030100301000000102010 10172050705070000030 20302010601060402040 Sample OutputCase1:Perimeters:340420Areas:30003800Case2:Perimeters:380Areas:2660Problem B:Jack of All TradesJack Barter is a wheeler-dealer of the highest sort.He’ll trade anything for anything,as long as he gets a good deal.Recently,he wanted to trade some red agate marbles for some goldfish.Jack’s friend Amanda was willing to trade him1goldfish for2red agate marbles.But Jack did some more digging and found another friend Chuck who was willing to trade him5plastic shovels for3marbles while Amanda was willing to trade1goldfish for3plastic shovels.Jack realized that he could get a better deal going through Chuck(1.8marbles per goldfish)than by trading his marbles directly to Amanda (2marbles per goldfish).Jack revels in transactions like these,but he limits the number of other people involved in a chain of transactions to9(otherwise things can get a bit out of hand).Normally Jack would use a little program he wrote to do all the necessary calculations tofind the optimal deal,but he recently traded away his computer for afine set of ivory-handled toothpicks.So Jack needs your help.InputInput will consist of multiple test cases.Thefirst line of thefile will contain an integer n indicating the number of test cases in thefile.Each test case will start with a line containing two strings and a positive integer m≤50.Thefirst string denotes the items that Jack wants,and the second string identifies the items Jack is willing to trade.After this will be m lines of the forma1name1a2name2indicating that some friend of Jack’s is willing to trade an amount a1of item name1for an amount a2 of item name2.(Note this does not imply the friend is also willing to trade a2of item name2for a1of item name1.)The values of a1and a2will be positive and≤20.No person will ever need more than 231−1items to complete a successful trade.OutputFor each test case,output the phrase Case i:(where i is the case number starting at1)followed by the best possible ratio that Jack can obtain.Output the ratio using5significant digits,rounded.Follow this by a single space and then the number of ways that Jack could obtain this ratio.Sample Input2goldfish marbles31goldfish2marbles5shovels3marbles1goldfish3shovelsthis that47this2that14this4that7this2theother1theother1thatSample OutputCase1:1.80001Case2:0.285713Problem C:LCRLCR is a simple game for three or more players.Each player starts with three chips and the object is to be the last person to have any chips.Starting with Player1,each person rolls a set of three dice.Each die has six faces,one face with an L,one with a C,one with an R and three with a dot.For each L rolled,the player must pass a chip to the player on their left(Player2is considered to be to the left of Player1);for each R rolled,the player passes a chip to the player on their right;and for each C rolled, the player puts a chip in a central pile which belongs to no player.No action is taken for any dot that is rolled.Play continues until only one player has any chips left.In addition,the following rules apply:1.A player with no chips is not out of the game,since they may later gain chips based on otherplayers’rolls.2.A player with only1or2chips left only rolls1or2dice,respectively.A player with no chips leftdoes not roll but just passes the dice to the next player.Your job is to simulate this game given a sequence of dice rolls.InputInput will consist of multiple test cases.Each test case will consist of one line containing an integer n (indicating the number of players in the game)and a string(specifying the dice rolls).There will be at most10players in any game,and the string will consist only of the characters‘L’,‘C’,‘R’and‘.’.In some test cases,there may be more dice rolls than are needed(i.e.,some player wins the game before you use all the dice rolls).If there are not enough dice rolls left to complete a turn(for example,only two dice rolls are left for a player with3or more chips)then those dice rolls should be ignored.A value of n=0will indicate end of input.OutputFor each test case,output the phrase“Game i:”on a single line(where i is the case number starting at1)followed by a description of the state of the game.This desciption will consist of n+1lines of the formPlayer1:c1Player2:c2...Player n:cnCenter:ctwhere c1, are the number of chips each player has at the time the simulation ended(either because some player has won or there are no more remaining dice rolls)and ct is the number of chips in the center pile.In addition,if some player has won,you should append the string“(W)”after their chip count;otherwise you should append the string“(*)”after the chip count of the player who is the next to roll.The only blank on any line should come before the game number or the player number. Use a single blank line to separate test cases.Sample InputR.L.RLLLCLR.LL..R...CLR. 5RL....C.LSample OutputGame1:Player1:0Player2:0Player3:6(W)Center:3Game2:Player1:1Player2:4Player3:1Player4:4(*)Player5:4Center:1Problem D:Party Party PartyEmma has just graduated high school and it is the custom for the new graduates to throw parties for themselves and invite everyone in school to attend.Naturally,Emma wishes to attend as many parties as possible.This is not such a problem on a weekday since usually there are only two or three parties in the evening.But,Saturdays are packed!Typically some parties start at8AM(breakfast is served) while others might end at midnight(much to the annoyance of the neighbors).Emma naturally wants to know how many parties she can attend.Each party has a starting and stopping time,which are on the hour.These are listed via a24-hour clock.For example,a party might start at10AM(10)and end at2PM(14).The earliest a party can start is8AM(8)and the latest it can end is midnight(24).In order not to be rude,Emma stays at each party at least one half hour and will consider traveling time between parties to be instantaneous. If there are times during the day when there are no parties to attend,she’ll simply go home and rest. InputThere will be multiple test cases.Each test case starts with a line containing an integer p(≤100) indicating the number of parties on the given day.(A value of p=0indicates end of input.)The following p lines are each of the form s e,both integers where8≤s<e≤24,indicating a party that starts at time s and ends at time e.Note there may be multiple parties with the same starting and ending time.OutputFor each input set output a line of the formOn day d Emma can attend as many as n parties.where you determine the value of n and d is the number of the test case starting at1.Sample Input8121313141213910910121312149113141514151415Sample OutputOn day1Emma can attend as many as7parties.On day2Emma can attend as many as2parties.Problem E:Su-Su-SudokuBy now,everyone has played Sudoku:you’re given a9-by-9grid of boxes which you are tofill in with the digits1through9so that1)every row has all nine digits,2)every column has all nine digits,and 3)all nine3-by-3subgrids have all nine digits.To start the game you are given a partially completed grid and are asked tofill in the remainder of the boxes.One such puzzle is shown below.415676985972453919853752472398187286231In this problem,you will be given Sudoku grids which you have nearly completed;indeed you’vefilled in every box exceptfive.You are asked to complete the grid,or determine that it’s impossible.(You might have already made an error!)InputThefirst line of input will contain a positive integer indicating the number of test cases to follow.Each test case will be a nearly completed Sudoku grid consisting of9lines,each containing9characters from the set of digits0through9.There will be exactlyfive0’s in each test case,indicating thefive unfilled boxes.OutputOutput for each test case should be eitherCould not complete this grid.if it is impossible to complete the grid according to the rules of the game,or the completed grid,in the form given below.(There are no blank spaces in the output.)If there is a way to complete the grid,it will be unique.Separate test cases with a blank line.Sample Input2481253697267948105539671204654389712908704563173562849702136958315897426896425371481253697267948105539671284654289710908704562173562849702136958315897426896425371Sample Output481253697267948135539671284654389712928714563173562849742136958315897426896425371Could not complete this grid.Problem F:Tanks a LotImagine you have a car with a very large gas tank-large enough to hold whatever amount you need. You are traveling on a circular route on which there are a number of gas stations.The total gas in all the stations is exactly the amount it takes to travel around the circuit once.When you arrive at a gas station,you add all of that station’s gas to your tank.Starting with an empty tank,it turns out there is at least one station to start,and a direction(clockwise or counter-clockwise)where you can make it around the circuit.(On the way home,you might ponder why this is the case-but trust us,it is.) Given the distance around the circuit,the locations of the gas stations,and the number of miles your car could go using just the gas at each station,find all the stations and directions you can start at and make it around the circuit.InputThere will be a sequence of test cases.Each test case begins with a line containing two positive integers c and s,representing the total circumference,in miles,of the circle and the total number of gas stations. Following this are s pairs of integers t and m.In each pair,t is an integer between0and c−1measuring the clockwise location(from some arbitraryfixed point on the circle)around the circumference of one of the gas stations and m is the number of miles that can be driven using all of the gas at the station. All of the locations are distinct and the maximum value of c is100,000.The last test case is followed by a pair of0’s.OutputFor each test case,print the test case number(in the format shown in the example below)followed by a list of pairs of values in the form i d,where i is the gas station location and d is either C,CC,or CCC, indicating that,when starting with an empty tank,it is possible to drive from location i around in a clockwise(C)direction,counterclockwise(CC)direction,or either direction(CCC),returning to location i.List the stations in order of increasing location.Sample Input1042343619355014121311100Sample OutputCase1:2C4CC9CCase2:0CCC1CCC2CCC3CCC4CCCProblem G:The Worm TurnsWinston the Worm just woke up in a fresh rectangular patch of earth.The rectangular patch is divided into cells,and each cell contains either food or a rock.Winston wanders aimlessly for a while until he gets hungry;then he immediately eats the food in his cell,chooses one of the four directions(north, south,east,or west)and crawls in a straight line for as long as he can see food in the cell in front of him.If he sees a rock directly ahead of him,or sees a cell where he has already eaten the food,or sees an edge of the rectangular patch,he turns left or right and once again travels as far as he can in a straight line,eating food.He never revisits a cell.After some time he reaches a point where he can go no further so Winston stops,burps and takes a nap.For instance,suppose Winston wakes up in the following patch of earth(X’s represent stones,all other cells contain food):01234X13XIf Winston starts eating in row0,column3,he might pursue the following path(numbers represent order of visitation):0123442X11816620143X2281012In this case,he chose his path very wisely:every piece of food got eaten.Your task is to help Winston determine where he should begin eating so that his path will visit as many food cells as possible. InputInput will consist of multiple test cases.Each test case begins with two positive integers,m and n, defining the number of rows and columns of the patch of earth.Rows and columns are numbered starting at0,as in thefigures above.Following these is a non-negative integer r indicating the number of rocks,followed by a list of2r integers denoting the row and column number of each rock.The last test case is followed by a pair of zeros.This should not be processed.The value m×n will not exceed 625.OutputFor each test case,print the test case number(beginning with1),followed by four values:amount row column directionwhere amount is the maximum number of pieces of food that Winston is able to eat,(row,column) is the starting location of a path that enables Winston to consume this much food,and direction isone of E,N,S,W,indicating the initial direction in which Winston starts to move along this path.If there is more than one starting location,choose the one that is lexicographically least in terms of row and column numbers.If there are optimal paths with the same starting location and different starting directions,choose thefirst valid one in the list E,N,S,W.Assume there is always at least one piece of food adjacent to Winston’s initial position.Sample Input55304313200Sample OutputCase1:2203WProblem H:You’ll be Working on the RailroadCongratulations!Your county has just won a state grant to install a rail system between the two largest towns in the county—Acmar and Ibmar.This rail system will be installed in sections,each section connecting two different towns in the county,with thefirst section starting at Acmar and the last ending at Ibmar.The provisions of the grant specify that the state will pay for the two largest sections of the rail system,and the county will pay for the rest(if the rail system consists of only two sections,the state will pay for just the larger section;if the rail system consists of only one section,the state will pay nothing).The state is no fool and will only consider simple paths;that is,paths where you visit a town no more than once.It is your job,as a recently elected county manager,to determine how to build the rail system so that the county pays as little as possible.You have at your disposal estimates for the cost of connecting various pairs of cities in the county,but you’re short one very important requirement—the brains to solve this problem.Fortunately,the lackeys in the computing services division will come up with something.InputInput will contain multiple test cases.Each case will start with a line containing a single positive integer n≤50,indicating the number of railway section estimates.(There may not be estimates for tracks between all pairs of towns.)Following this will be n lines each containing one estimate.Each estimate will consist of three integers s e c,where s and e are the starting and ending towns and c is the cost estimate between them.(Acmar will always be town0and Ibmar will always be town1.The remaining towns will be numbered using consecutive numbers.)The costs will be symmetric,i.e.,the cost to build a railway section from town s to town e is the same as the cost to go from town e to town s,and costs will always be positive and no greater than1000.It will always be possible to somehow travel from Acmar to Ibmar by rail using these sections.A value of n=0will signal the end of input.OutputFor each test case,output a single line of the formc1c2...cm costwhere each ci is a city on the cheapest path and cost is the cost to the county(note c1will always be0 and cm will always be1and ci and ci+1are connected on the path).In case of a tie,print the path with the shortest number of sections;if there is still a tie,pick the path that comesfirst lexicographically. Sample Input70210036245343354417518Sample Output03413。

2008年郑州大学ACM大赛题目

2008年郑州大学ACM大赛题目

Problem A:祝福【问题描述】得知Atlantis即将沉没的消息以后,King决定把他的人民送到安全的国外去。

但是码头已经废弃很多很多年了。

码头前有一个迷宫,国王的骑士只身闯入了这个迷宫……骑士在迷宫的出口遇到了不明生物的袭击!骑士因为是单独作战,所以很快便招架不住了,他的大马被打得奄奄一息(。

)这个时候,迷宫中的两座石像(一个是猫,一个是天使。

(!!!!!))里放出了无数锋利的刀片,把不明生物全部杀死,骑士当场晕倒在地。

等他醒来,发现马已经死了,手上多了一个戒指,上面写着:“这个戒指会帮助你逃脱。

它赋予了神奇的力量。

有了它,每次移动如果是只要|x-x1|+|y-y1|<=P(P在输入文件中给出),且(x1, y1)不是障碍物,你就能实现(x, y) -> (x1, y1)的移动!”(Angel暗自想:还有这么心黑的……)迷宫为n*m(0<n,m<=20)的矩阵。

骑士从(n, m)到(1, 1)。

问:在戒指的帮助下,骑士最少要多少步才能回到入口?在步数最少的前提下,总共有多少种办法到达入口?注意,骑士不会傻到一直停留在原地不动。

【输入文件】第1行3个整数,n, m, P,分别代表迷宫大小和移动范围以后n行,每行m个数,代表了迷宫,其中0代表可通,1代表不能通过。

【输出文件】两个整数,用空格分开,分别代表最少到达入口的步数和路径的数目。

假设一定能够达到入口。

【样例输入】2 2 10 01 0【样例输入】2 1Problem B:津津的储蓄计划【问题描述】津津的零花钱一直都是自己管理。

每个月的月初妈妈给津津300元钱,津津会预算这个月的花销,并且总能做到实际花销和预算的相同。

为了让津津学习如何储蓄,妈妈提出,津津可以随时把整百的钱存在她那里,到了年末她会加上20%还给津津。

因此津津制定了一个储蓄计划:每个月的月初,在得到妈妈给的零花钱后,如果她预计到这个月的月末手中还会有多于100元或恰好100元,她就会把整百的钱存在妈妈那里,剩余的钱留在自己手中。

第八届程序设计大赛初赛试题及答案

第八届程序设计大赛初赛试题及答案

第八届程序设计大赛初赛试题说明:请将所有答案写到试卷第1页及第2页。

一、读程序写结果(40分)1、(5分)2、(5分)3、(10分)结果:结果:结果:4、(10分)5、(5分)6、(5分)结果:结果:结果:二、代码填空(30分)1、(5分)2、(5分)空一:____acm / lg (5分)空一:if(begin>end) return (5分)3、(12分)4、(8分)空一:siruan /= 10 (3分)空一:s[i] - '0' (4分)空二:hm - lg (3分)空二:siruan[sum % 11] (4分)空三:lghm = acm(lghm) (6分)三、思维题(15分)数据1:T1=1,T2=2,T3=3,T4 = 4 数据2:T1=1,T2=2,T3=5,T4 = 10 答案:(acm)1 2->(siruan) 2min 答案:(acm)1 2->(siruan) 2min (acm) <-1 (siruan) 1min (acm) <-1 (siruan) 1min(acm) 1 3->(siruan) 3min (acm) 5 10->(siruan) 10min(acm) <-1 (siruan) 1min (acm) <-2 (siruan) 2min(acm) 1 4-> (siruan) 4min (acm) 1 2-> (siruan) 2min最短时间:2+1+3+1+4 = 11min 最短时间:2+1+10+2+2 = 17min数据3:T1 = 5,T2 = 2,T3=1,T4=10,T5=8 答案:(acm)1 2->(siruan) 2min(acm) <-1 (siruan) 1min(acm) 8 10->(siruan) 10min(acm) <-2 (siruan) 2min(acm) 1 2-> (siruan) 2min(acm) <-1 (siruan) 1min(acm) 1 5 ->(siruan) 5min最短时间:2+1+10+2+2+1+5 = 23min四、编程题(15分)程序代码:#include<stdio.h>#include<string.h>int s[110];int main(){int i;int a, n, m;while (scanf("%d%d", &a, &n)!=EOF){memset(s, 0x00, sizeof(s));m = n;for (i=0; i<m; i++){s[i] += a * (n--);s[i+1] = s[i] / 10;s[i] %= 10;}if (s[m]) printf("%d", s[i]);for (i=m-1; i>=0; i--)printf("%d", s[i]);printf("\n");}return 0;}一、读程序写结果(40分)1、(5分)#include <stdio.h>int main(){char acm[] = "I love acm!";char siruan[] = "I love siruan!";char def[] = "Welcome to join us!";int chose = 0;switch (chose){case 0: printf("%s\n", acm);case 1: printf("%s\n", siruan);default : printf("%s", def);}return 0;}输出结果:2.(5分)#include <stdio.h>int main(){int acm = 0, siruan = 1;if (acm = siruan) printf("%s", "May you success!");else printf("%s", "May you success,too!");return 0;}输出结果:3.(10分)#include <stdio.h>#include <math.h>int main(){int i,j,k,n;char lghm[14]="ILOVEACMSIRUAN";n = 3;for (i=0; i<n-1; i++) printf(" ");printf("%c\n",lghm[0]);for (i=1; i<n; i++){for (j=abs(n-i-1); j>0; j--) //abs(n)返回值为整形n的绝对值printf(" ");printf("%c",lghm[2*i-1]);for (k=1; k<=2*i-1; k++) printf(" ");printf("%c\n",lghm[2*i]);}for (i=n; i<=2*n-3; i++){for (j=abs(n-i-1); j>0; j--) printf(" ");printf("%c",lghm[2*i-1]);for (k=1; k<=4*n-5-2*i; k++) printf(" ");printf("%c\n",lghm[2*i]);}for (i=0; i<n-1; i++) printf(" ");printf("%c\n",lghm[4*n-5]);return 0;}输出结果:4.(10分)#include <stdio.h>#include <string.h>struct Student{char name[20];int num;} stu[5];{stu[0].num = 521; strcpy(stu[0].name, "sichuan wenchuan");stu[1].num = 521; strcpy(stu[1].name, "bless");stu[2].num = 420; strcpy(stu[2].name, "sichuan yaan");stu[3].num = 420; strcpy(stu[3].name, "love");stu[4].num = 420; strcpy(stu[4].name, "god");}void swap(int a, int b){struct Student tmp;tmp.num = stu[a].num;stu[a].num = stu[b].num;stu[b].num = tmp.num;strcpy(, stu[a].name);strcpy(stu[a].name, stu[b].name);strcpy(stu[b].name, );}void bubble_sort(int n){int i,j,flag,temp;for(i = 0; i < n-1; i++){flag = 1;for(j = 0; j < n-i-1; j++){if(stu[j].num > stu[j+1].num){swap(j, j+1);flag = 0;}else if (stu[j].num == stu[j+1].num && strcmp(stu[j].name,stu[j+1].name)<0){ swap(j, j+1);}}if(flag) break;}}int main(){init();bubble_sort(5);for (i=0; i<5; i++)printf("%-4d%s\n", stu[i].num, stu[i].name);return 0;}输出结果:6.(5分)#include <stdio.h>int acm(){int lg = 1314520;int hm = 0;while(lg > 0){hm = hm * 10 + lg % 10;lg /= 10;}return hm;}int main(){int siruan = acm();printf("%d", siruan);return 0;}输出结果:二、代码填空(30分)1.(5)如果没有计算器,我们如何求3的平方根?可以先猜测一个数,比如1.5,然后用3除以这个数字。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

计算机科学系第二届大学生程序设计竞赛试题题目一 大数乘法
问题描述(Problem Description):
编程实现位数不超过300位的任意大的两个整数相乘。

输入(Input):
提示用户输入第一个大数乘数和第二个大数乘数。

输出(Output):
输出两个大数的乘积。

输入示例(Sample Input):
请输入第一个乘数:123456789123456
请输入第二个乘数:123456789123456
输出示例(Sample Output):
两数的乘积是:15230578580673373689799383936
四三二五六一题目二 排球队员站位问题
问题描述(Problem Description):
左图为排球场的平面图,其中一、二、三、
四、五、六为位置编号,二、三、四号位置为前排,一、六、五号位为后排。

某队比赛时,一、四号位放主攻手,二、五号位放二
传手,三、六号位放副攻手。

队员所穿球衣分别为1,2,3,4,5,6号,但每个队员的球衣都与他们的站位号不同。

已知1号、6号队员不在后排,2号、3号队员不是二传手,3号、4号队员不在同一排,5号、6号队员不是副攻手。

编程求每个队员的站位情况。

输入(Input):
输出(Output):
输出每个队员球衣号码和所站的位置编号。

输入示例(Sample Input):
输出示例(Sample Output):
球衣号码:1 2 3 4 5 6
位置编号:一 二 三 四 五 六
题目三文件读写
问题描述(Problem Description):
INI文件为一种广泛应用的储存程序配置的文件格式。

要求不使用操作系统自带INI文件处理功能,用c++编写一个INI文件读取程序,并把结果输出到显示器及文件result.txt中。

说明:
INI文件的结构:
[区名字] # 区名注释
键名=键值 # 键值注释
一个区里可以有几个不同键名的键值,例如:
测试用INI文件test.ini:
[section] #this is a section comment
key=value #this is a key comment
[section2]
key2=value2
要求程序能读取section2区中键名为key2的值,以及section区中的键名为key的注释。

输入(Input):
在Windows命令窗口里输入程序名称来运行程序,注意程序所带参数。

输出(Output):
第一行输出section2区中键名为key2的值。

第二行输出section区中的键名为key的注释。

同时要把此结果输出到显示器和文件result.txt中。

输入示例(Sample Input):
CppFileRW Test.ini
输出示例(Sample Output):
section2区中键名为key2的值是:value2
section区中的键名为key的注释是:this is a key comment
题目四入栈出栈
问题描述(Problem Description):
N个不同的数字依次入栈,求所有的出栈可能性。

输入(Input):
第一行输入数字的个数N。

第二行输入N个不同的数字。

输出(Output):
输出这N个数字所有可能的出栈序列,一行输出一个序列。

输入示例(Sample Input):
请输入数字个数:3
请输入3个不同是数字:1 2 3
输出示例(Sample Output):
出栈序列为:1 2 3
1 3 2
2 1 3
2 3 1
3 2 1
题目五人类记数方式与外星人记数方式的转换
问题描述(Problem Description):
2036年,人类探测器猎豹X到达了木星的第二颗卫星——木卫二。

探测器上的防生学智能机器人传达给科学家一个重要情报——它们发现了智能生命...智能生命与人类有着不同的数学计数法,他们用几个数字的排列就可以表达出丰富的数字世界。

其计数的规律如下:
1 代表1
1 2 代表2
2 1 代表3
1 2 3 代表4
1 3
2 代表5
2 1
3 代表6
2 3 1 代表7
3 1 2 代表8
3 2 1 代表9
1 2 3 4 代表10
..............
编程实现人类记数方式与外星人记数方式的转换。

输入(Input):
提示输入人类数字。

输出(Output):
输出转换后对应的外星人数字。

输入示例(Sample Input):
人类计数数字:234
输出示例(Sample Output):
外星人计数数字:153426
题目六农夫过河
问题描述(Problem Description):
一个农夫带着一只狼,一只羊和一些菜过河。

河边只有一条一船,由于船太小,只能装下农夫和他的一样东西。

在无人看管的情况下,狼要吃羊,羊要吃菜,请问农夫如何才能使三样东西平安过河。

输入(Input):
输出(Output):
输出度河的次数序列和每次度河时农夫携带的物体以及左岸和右岸的物体。

输入示例(Sample Input):
输出示例(Sample Output):
度河次数序列 左岸物体 农夫携带的物体 右岸物体
0 狼 羊 菜
1 狼菜羊
2 狼菜羊
3 狼菜羊
4 狼羊菜
…… …… …… ……
n 狼羊菜。

相关文档
最新文档