acmicpc练习题

合集下载

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进制数。

信息学奥赛试题精选33题(附带题解)

信息学奥赛试题精选33题(附带题解)

第1~10题为基础题,第11~20题为提高题,第21~33为综合题注:因为在本文档中需要用到一些特殊的数学符号(如:求和号、分数等),所以当您在百度文库中浏览时,一些数学符号可能会显示不出来,不过当您把本文档下载下来在本地浏览时,所有的符号即可全部都显示出来。

^_^基础题:【1 Prime Frequency】【问题描述】给出一个仅包含字母和数字(0-9, A-Z 以及a-z)的字符串,请您计算频率(字符出现的次数),并仅报告哪些字符的频率是素数。

输入:输入的第一行给出一个整数T( 0<T<201),表示测试用例个数。

后面的T行每行给出一个测试用例:一个字母-数字组成的字符串。

字符串的长度是小于2001的一个正整数。

输出:对输入的每个测试用例输出一行,给出一个输出序列号,然后给出在输入的字符串中频率是素数的字符。

这些字符按字母升序排列。

所谓“字母升序”意谓按ASCII 值升序排列。

如果没有字符的频率是素数,输出“empty”(没有引号)。

注:试题来源:Bangladesh National Computer Programming Contest在线测试:UV A 10789提示先离线计算出[2‥2200]的素数筛u[]。

然后每输入一个测试串,以ASCLL码为下标统计各字符的频率p[],并按照ASCLL码递增的顺序(0≤i≤299)输出频率为素数的字符(即u [p[i]]=1且ASCLL码值为i的字符)。

若没有频率为素数的字符,则输出失败信息。

【2 Twin Primes】【问题描述】双素数(Twin Primes)是形式为(p, p+2),术语“双素数”由Paul Stäckel (1892-1919)给出,前几个双素数是(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43)。

在本题中请你给出第S对双素数,其中S是输入中给出的整数。

算法竞赛入门经典训练指南题单

算法竞赛入门经典训练指南题单

算法竞赛入门经典训练指南题单全文共四篇示例,供读者参考第一篇示例:算法竞赛作为计算机科学领域中的重要领域之一,一直备受关注和推崇。

参加算法竞赛可以帮助我们提高编程能力、思维灵活性和解决问题的能力。

而且,通过算法竞赛,我们还可以结识来自各个国家的优秀程序员,开阔自己的视野,提高自己的竞争力。

而要在算法竞赛中取得好成绩,就需要有一定的训练和积累。

本文将为大家推荐一些经典的算法竞赛训练题单,希望能帮助大家快速入门和提升自己的算法竞赛水平。

1. ACM-ICPC题单ACM国际大学生程序设计竞赛(ACM-ICPC)是全球规模最大、最具影响的大学生程序设计竞赛,被誉为程序设计界的“奥林匹克”。

ACM-ICPC赛题难度较高,对参赛者的编程能力、算法设计能力和团队协作能力等方面都有严格的要求。

参加ACM-ICPC的同学们需要有一定的训练和备战。

以下是一些经典的ACM-ICPC训练题单,推荐给大家:1、CodeforcesCodeforces是一个国际知名的在线编程比赛和训练平台,其比赛难度较高,同时也有很大的影响力。

在Codeforces上,你可以找到各种难度的题目,从入门级到专家级都有覆盖。

推荐大家在Codeforces 上刷题,提高自己的编程能力和解题能力。

3、洛谷洛谷是国内著名的在线题库和训练平台,里面汇集了大量的ACM 竞赛题目和OJ题目,适合广大程序员练习和提升编程能力。

洛谷上的题目分类清晰,难度适中,非常适合新手入门和提高。

2. Google Code Jam题单Google Code Jam是由谷歌主办的一项全球性的编程大赛,是程序员们展示自己编程才华的绝佳舞台。

Google Code Jam的题目设计独特,难度适中,涵盖了很多经典的算法问题,非常适合有一定编程基础的程序员练习和挑战。

以下是一些推荐的Google Code Jam题单:LeetCode是一个在线的编程练习平台,里面包含了大量的算法和数据结构问题,适合练习和提升自己的编程能力。

acm-icpc-neerc-southern-2014

acm-icpc-neerc-southern-2014

Problem A.Nasta RabbaraSasha justfinished watching yet another season of the infamous TV series“Nasta Rabbara”,the best show in Berland.The action takes place in a city called Nasta Rabbara that has a population of n people.In the beginning of the season,all residents of the city were friendly to each other and lived in peace.But as the season developed,people would start getting angry at each other.Specifically,in each of m series, one pair of people quarreled.Note that a pair of people may have quarreled several times throughout the season.Obviously,Sasha is quite concerned about the situation in Nasta Rabbara.He picked q segments of the season and now wants to analyze them.For convenience,the segments are numbered with integers from 1to q.The i-th segment contains episodes from the l i-th to the r i-th,inclusively.Note that the different segments may overlap,i.e.have common episodes.When analyzing a given segment,Sasha watches all its episodes and decides which people are good and which are bad(only taking into account the episodes that belong to the segment).Sasha believes that during the segment,good guys should never quarrel with each other,as well as bad guys should never quarrel with each other.I.e.he would accept only a quarrel between a good and a bad guy.Though, sometimes the storyline of a segment can become very complicated,so it’s not even possible to classify all characters as either good or bad.Your task is to help Sasha understand the situation in Nasta Rabbara.For each segment of the season, Sasha needs to determine whether there exists a way to classify all its people as either good or bad,so that:•no two good guys quarreled over this segment of the season;•no two bad guys quarreled over this segment of the season.InputThefirst line contains three space-separated integers n,m and q(2≤n≤105;1≤m,q≤105), denoting the number of people,the number of episodes,and the number of segments Sasha is interested in correspondingly.The i-th of the next m lines contains a pair of space-separated integers x i,y i(1≤x i<y i≤n),denoting that in the i-th episode person x i and person y i quarrel with each other.Assume that all characters of the season are numbered by consecutive integers from1to n.The j-th of the next q lines contains a pair of space-separated integers l j,r j(1≤l j≤r j≤m),denoting the boundaries of the j-th segment.OutputPrint q lines.In the j-th line print the word“Possible”if there is a way to classify people as either good or bad considering only the episodes from the l j-th to the r j-th inclusive.If there is no such a way,print the word“Impossible”.All words should be printed without quotes.Examplesstandard input standard output436 12 23 13 11 22 33 12 23 13Possible Possible Possible Possible Possible Impossible456 12 23 13 14 12 11 12 13 24 25 15Possible Possible Impossible Possible Impossible ImpossibleNoteIn thefirst example the answer is“Possible”for all segments,except for the segment that forms a quarrel triangle between people1,2and3.Problem B.Colored BlanketsRecently Polycarp has opened a blankets store and he faced with many challenges.He has got k blankets.A blanket has two sides,each of k blankets has at most one colored side.So either both sides are uncolored or one side is colored and the other one is not.If a side is colored,one of n possible colors is used.It is known that k is divisible by n.Polycarp wants to color all uncolored sides in such a way that:•each blanket will have both sides colored(one color per side),the colors can be the same or different, all the used colors are from n possible colors;•it will be possible to compose n kits with kn blankets in each kit that blankets in each kit areidentically colored.It is allowed to turn over blankets to determine that they are identically colored:for example,red-blue and blue-red blankets are identically colored.Blankets in different kits can be identically colored.InputThefirst line contains two integer numbers k and n(1≤n≤k≤1000)—number of blankets and colors. It is guaranteed that k is divisible by n.The second line contains a sequence of integers c1,c2,...,c k (1≤c i≤n or c i=−1),where c i stands for the color of the colored side of the i-th blanket or−1if it is uncolored.OutputIf there is no solution for the problem,print“No”in thefirst line.Otherwise print a line containing“Yes”and k lines describing each blanket.The i-th line should contain a pair of colors(integers in the range 1,2,...,n)used for the i-th blanket.You may print colors in pairs in any order.If there are multiple solutions,print any of them.Examplesstandard input standard output621122-12Yes 12 21 22 22 21 22844-11-143-1-1Yes 41 21 21 31 14 31 41 41Problem ponent TreeThis problem is a little bit unusual.Here you are to write a program to process queries in online mode. That means that your program will be allowed to read a query only after writing answer for the previous query.Please be sure to use the streamflushing operation after each query’s output in order not to leave part of your output in some buffer.For example,inС++you’ve got to use the fflush(stdout)function, in Java—call System.out.flush(),and in Pascal—flush(output).Imagine a complex application that consists of n components(the application itself is not essential in this problem,so we omit its description).All components form a tree-like hierarchy:each component except one(let’s call this special component a main component)is contained in exactly one other component (let’s call it a parent component).For the sake of convenience,let’s assume that the components are numbered with integers from1to n with the main component having the number1.Each component has a set of properties associated with it.Each property is given in the form“KEY=VALUE”. All property keys within a single component are distinct.You are given the component tree together with all properties.Your task is to handle several queries for finding the property of a component.Each query is given as a pair(c,key),which means that you have tofind the value of the property key for the component number c.To answer the query,you have to follow this algorithm:1.If the value of the property is defined for the component c,report this value as an answer.Otherwise,go to step2.2.If the component number c is not main,continue search in the parent component(set c equal tothe number of parent component)and go to the step1.Otherwise,the value of the property is not defined and considered to be“N/A”.InputThefirst line of the input contains an integer n(1≤n≤3·105)—the number of components.Then the input contains the descriptions of components1,2,...,n.Each description starts with a line containing two space-separated integers p i and k i(0≤p i≤n,k i≥0)—the number of parent component and the number of properties.For thefirst component p i is equal to 0.Each of the following k i lines contains a single property in the form KEY=VALUE,where both KEY and VALUE are strings of Latin letters and digits with length between1and10characters each.All keys for a given component are distinct.The keys are case-sensitive,so,for example,properties with keys“Length”and“length”are considered distinct.The values are also case-sensitive.The next line contains an integer q(1≤q≤3·105)—the number of queries you have to answer.Each of the following q lines contains an integer c j(1≤c j≤n)and a string key j,separated by a single space, where key j is a string of Latin letters and digits with length between1and10characters.Note that for each query,starting from the second,you will be able to read it only when you print the answer for the previous query and make aflush operation.It is guaranteed that the total number of properties does not exceed3·105.OutputFor each query,print a line with the value of the required property.You should make aflush operation after each line.Examplesstandard input standard output402enabled=true foreground=white 12enabled=false fontSize=1223enabled=true foreground=black caption=OK21fontSize=1053enabled4enabled3fontSize4foreground2caption true false 12 white N/A102width=300 height=500 21width1Width 300 N/AProblem D.Data CenterThe startup“Booble”has shown explosive growth and now it needs a new data center with the capacity of m petabytes.Booble can buy servers,there are n servers available for purchase:they have equal price but different capacities.The i-th server can store a i petabytes of data.Also they have different energy consumption—some servers are low voltage and other servers are not.Booble wants to buy the minimum number of servers with the total capacity of at least m petabytes.If there are many ways to do it Booble wants to choose a way to maximize the number of low voltage servers. Booble doesn’t care about exact total capacity,the only requirement is to make it at least m petabytes. InputThefirst line contains two integer numbers n and m(1≤n≤2·105,1≤m≤2·1015)—the number of servers and the required total capacity.The following n lines describe the servers,one server per line.The i-th line contains two integers a i,l i (1≤a i≤1010,0≤l i≤1),where a i is the capacity,l i=1if server is low voltage and l i=0in the opposite case.It is guaranteed that the sum of all a i is at least m.OutputPrint two integers r and w on thefirst line—the minimum number of servers needed to satisfy the capacity requirement and maximum number of low voltage servers that can be bought in an optimal r servers set.Print on the second line r distinct integers between1and n—the indices of servers to buy.You may print the indices in any order.If there are many solutions,print any of them.Examplesstandard input standard output410 31 70 51 4121 42313 61 61 6133 123NoteIn thefirst example any pair of servers which includes the server2is a correct output.Problem E.Election of a MayorThe Berland capital is preparing for mayoral election.There are two candidates for the position:the current mayor and his rival.The rival is a serious competitor,and it’s not easy for current mayor to win the election.The candidate will be declared the winner if he wins at more than a half of all polling stations.The results of the polling stations are supplied independently.The station winner is the candidate who gets more than a half of the votes of this station.No candidate is declared a winner of a polling station if both candidates have got the same number of votes at this station.Similarly,no candidate is declared a winner of the election if both candidates won at the same number of polling stations.All eligible voters are going to take part in the election and have already decided whom to give their vote to.The campaign headquarters of the current mayor has collected data from all n stations of the city, and now for every station it is known how many people will vote for the current mayor and how many people will vote for his opponent.The results have been disappointing for the current mayor,but his staffcame up with a way to win the election.It was suggested to merge some pairs of polling stations in such a way that the current mayor will become the election winner.However,(for the sake of credibility),the proposed plan must comply with two conditions.Firstly,it is possible to merge only the pairs of stations with adjacent numbers(i.e., station j may be merged with either station j−1,or with station j+1).The resulting station cannot be merged again.Secondly,the number of such mergers for obvious reasons must be as few as possible. Your task is to help the current mayor’s campaign headquarters and produce such plan.InputThefirst line contains single integer n(2≤n≤2·105)—the number of the polling stations.Each of the following n lines contains two integers m j and r j(0≤m j,r j≤105)—the number of voters at station j who plan to vote for the current mayor and his rival correspondingly.OutputIf current mayor cannot win the election at any condition,print a single number−1to thefirst line. Otherwise,to thefirst line print an integer u—the minimum number of polling station mergers the current mayor needs to perform in order to win.To each of the next u lines print a pair of integers—the numbers of the merged stations.The pairs as well as the numbers within each pair can be printed in any order.If there are multiple solutions,print any of them.Examplesstandard input standard output7 158 810 1414 1213 1312 2110 20302 12 6721551-12109157Problem F.Ilya MurometsСилачомслывунедаром—семерыходнимударом!From the Russian cartoon on the Germanfairy tale. Ilya Muromets is a legendary bogatyr.Right now he is struggling against Zmej Gorynych,a dragon with n heads numbered from1to n from left to right.Making one sweep of sword Ilya Muromets can cut at most k contiguous heads of Zmej Gorynych. Thereafter heads collapse getting rid of empty space between heads.So in a moment before the second sweep all the heads form a contiguous sequence again.As we all know,dragons can breathefire.And so does Zmej Gorynych.Each his head has afirepower. Thefirepower of the i-th head is f i.Ilya Muromets has time for at most two sword sweeps.The bogatyr wants to reduce dragon’sfirepower as much as possible.What is the maximum totalfirepower of heads which Ilya can cut with at most two sword sweeps?InputThefirst line contains a pair of integer numbers n and k(1≤n,k≤2·105)—the number of Gorynych’s heads and the maximum number of heads Ilya can cut with a single sword sweep.The second line contains the sequence of integer numbers f1,f2,...,f n(1≤f i≤2000),where f i is thefirepower of the i-th head. OutputPrint the required maximum total headfirepower that Ilya can cut.Examplesstandard input standard output2082133123111100410010203040Problem G.FacePalm AccountingAn owner of a small company FacePalm has recently learned that the city authorities plan to offer to small businesses to participate in improving parks and garden squares.However,credible sources informed the FacePalm owner that the loss-making companies will not get such an offer.Moreover,the sources have also told how loss-making companies will be determined.A company will be considered loss-making if for every k contiguous days the total income of the company is negative.The FacePalm owner discussed the situation with his chief accountant,and they decided to change the report so that the company would look loss-making.The company report for n days can be represented as a sequence of integers a1,a2,...,a n,where a i is the company income in the day i(negative values correspond to losses).The accountant can change any values in this sequence,but no updated value can become less than the smallest value in the original report—otherwise the updated report will look absolutely implausible. Besides,the accountant wants the total change of the values to be as small as possible.We will assume that the total change of the values isn∑i=1|˜a i−a i|,where˜a i is the i-th value in the updatedreport.Your task is to calculate the minimum required total change of the values and provide the updated report. InputThefirst line contains integers n and k(1≤k≤n≤2·105)—the number of days in the report and the number of days in the definition of loss-making company.The second line contains n space-separated integers a1,a2,...,a n(−10000≤a i≤10000),where a i is the company income in day i.It is guaranteed that at least one value of a i is negative.OutputIn thefirst line print the required minimum total change.In the second line print the corresponding updated report.No value in the updated report can be less than the minimum value of the original report.If there are multiple solutions,print any of them.Examplesstandard input standard output543-3-11212-3-1128321-3-24-302311-3-22-30242-21-210-21-2133-561012-5-59Problem H.Minimal Agapov CodeTriangulation is a decomposition of a polygon into a set of triangles that the triangle vertices are in the vertices of the polygon.The triangles in a triangulation can’t have internal common points,and they should cover all the polygon.It is easy to see that triangulation of n-gon always consists of n−2triangles. You are given a regular polygon with n vertices.The vertices are labeled with integer numbers.Agapov code of its triangulation is constructed as follows:•write a code for each triangle:a sequence of labels of a triangle vertices in non-decreasing order;•concatenate all triangle codes in such order that the resulting sequence is lexicographically minimal.A sequence a=⟨a1,a2,...,a m⟩is lexicographically less than b=⟨b1,b2,...,b m⟩if there is such index i (1≤i≤m)that a i<b i and a j=b j for all j(1≤j<i).Triangle codes are written in triangles,the Agapov code is⟨4,4,5,4,4,8,4,5,5,4,5,6,4,5,8,5,6,8⟩.Given a labeled regular polygon write a program tofind the triangulation with lexicographically minimal Agapov code.InputThefirst line contains integer n(3≤n≤5·105).The second line contains n space-separated integers: c1,c2,...,c n(1≤c i≤n),where c i denotes the label on the i-th vertex.Vertices are indexed clockwise. OutputPrint n−2lines describing the required triangulation,one line per triangle.In each line print three integers:indices of triangle vertices in order of non-decreasing of their labels.Lines should be ordered in such a way that concatenation of triangle codes in order of output will give the required lexicographically minimal Agapov code.If there are multiple solutions,print any of them.Examplesstandard input standard output858648485461 645 681 413 687 132Problem I.Sale in GameStoreA well-known Berland online games store has announced a great sale!Buy any game today,and you can download more games for free!The only constraint is that the total price of the games downloaded for free can’t exceed the price of the bought game.When Polycarp found out about the sale,he remembered that his friends promised him to cover any single purchase in GameStore.They presented their promise as a gift for Polycarp’s birthday.There are n games in GameStore,the price of the i-th game is p i.What is the maximum number of games Polycarp can get today,if his friends agree to cover the expenses for any single purchase in GameStore?InputThefirst line of the input contains a single integer number n(1≤n≤2000)—the number of games in GameStore.The second line contains n integer numbers p1,p2,...,p n(1≤p i≤105),where p i is the price of the i-th game.OutputPrint the maximum number of games Polycarp can get today.Examplesstandard input standard output35531562277NoteIn thefirst example Polycarp can buy any game of price5or6and download games of prices1and3for free.So he can get at most3games.In the second example Polycarp can buy any game and download the other one for free.Problem J.Getting Ready for VIPCEulampius is preparing himself to the Very Important Programming Contest(VIPC).There is a lot of time before the contest,and Eulampius hopes to make headway in his problem solving skills.Eulampius decided to train by taking part in practice contests.He made a list of n contests that will take place before VIPC.Each contest in the list is characterized by three parameters:the day d i of the contest, the minimum skill l i required to take part in the contest and the maximum skill h i that the participant can reach after taking part in the contest.The participant skill becomes equal to h i if he starts taking part in the contest when he’s fully rested. If his fatigue equals t by the beginning of the contest,then the participant skill becomes equal to h i−t after the contest,even if h i−t is negative or less than his skill before the contest.Participating in a contest takes much energy,that’s why Eulampius can take part in at most one contest during a day.Participating in a contest increases Eulampius’fatigue by∆t(same for all contests). Each day Eulampius doesn’t participate in any contest,his fatigue t becomes equal to⌊t/2⌋(divided by two rounded down).Initially,Eulampius’skill is s,and his fatigue t equals zero.Your task is to determine the maximum skill Eulampius can reach before VIPC,no matter what his fatigue will be.InputThefirst line contains three integers n,s,∆t(1≤n≤2·105,0≤s≤106,0≤∆t≤104)—the number of contests,Eulampius’initial skill,the amount of fatigue added after a contest.Each of the next n lines contains three integers d i,l i,h i(1≤d i≤106,0≤l i<h i≤106)—the day of the i-th contest,the minimum skill needed to take part in the i-th contest and the maximum skill that can be reached after taking part in the i-th contest.The contests are ordered by their dates,so d i≤d i+1(i=1,2,...,n−1).OutputIn thefirst line print two integers c and m—the maximum skill Eulampius can reach and the number of contests he needs to take part in.In the second line print m space-separated integers—the indices of the contests in the order of participation.The contests are indexed starting from1in order of their appearance in the input.If there are multiple solutions,print any of them.Examplesstandard input standard output6123 5822 62243 74065 84065 1063100 116297964 1246453 1510 2515 31546 41042432 23456 1510 2515 31546 41042412 14NoteIn thefirst example the maximum skill that Eulampius can reach is96:1.Eulampius’initial skill is12and his fatigue is0.2.On the day5he participates in thefirst contest.Now his skill is22−0=22and his fatigue is0+3=3.3.On the day6he participates in the second contest.Now his skill is43−3=40and his fatigue is3+3=6.4.On the day7he does not participate in any contest.His skill is still40and his fatigue is⌊62⌋=3.5.On the day8he participates in the fourth contest.Now his skill is65−3=62and his fatigue is3+3=6.6.On the day9he does not participate in any contest.His skill is still62and his fatigue is⌊62⌋=3.7.On the day10he does not participate in any contest.His skill is still62and his fatigue is⌊32⌋=1.8.On the day11he participates in the sixth contest.Now his skill is97−1=96and his fatigue is1+3=4.Problem K.TreelandTreeland is an ancient country located on the territory of the modern Berland many many years ago.It is a well-known fact that Treeland consisted of n cities connected with n−1bidirectional roads.It was possible to travel from any city to any other one along the roads.The cities were numbered from1to n.Nowadays we do not know what cities were connected by roads directly,but recently archaeologists have found new information that can help to reconstruct the road network of Treeland.They found an ancient library with the diaries of a well-known traveler Biklouho-Baclay.The diaries contain interesting information:for each city i there is a list of all cities in the order of non-decreasing distance from i.The distances are calculated assuming that each road has length1,so a distance between cities is the minimum number of roads to travel between them.Formally,for each city i there is a list C i=⟨c i,1,c i,2,...,c i,n⟩containing a permutation of cities(numbers from1to n)in such order that d(i,c i,j)≤d(i,c i,j+1)for every j=1...n−1,where d(x,y)is a distance between cities x and y.Obviously,c i,1=i for each i.The cities that are equidistant from i can be listed in any order.Your task is to restore a possible road network consistent with the found lists.InputThe input consists of several test cases.Thefirst line contains integer number t(1≤t≤1000)—the number of test cases.Then t blocks follow,each describing a single test case.Thefirst line of a block contains integer number n(2≤n≤2000)—the number of cities.The following n lines contain lists C i,one list per line.It is guaranteed that the required road network exists for each test case.The sum of n over all test cases doesn’t exceed2000.OutputFor each test case print n−1lines describing roads.Each line should contain a pair of cities connected with a road.You may print the roads and cities in a pair in any order.Print a blank line after the output of a test case.If there are many solutions,print any of them.Examplesstandard input standard output321221514532 23415 34251 43152 54312 3132 213 3122123 34 54 4121 31Problem eful RoadsBerland capital contains n junctions and m roads connecting pairs of junctions.All roads are one-way. As you probably know Berland has two misfortunes:fools and roads.It is one month before mayoral election.So it is time for current government to make the city better. To show that they care both about the infrastructure and about the budget,the government decided to repair only useful roads.Current mayor thinks that a road from a junction u to a junction v is useful if there exists a simple path from City Hall to some junction containing the road(u,v).A path is called simple if it does not have any repeated junctions,i.e.contains each junction at most once.The City Hall is located at the junction1. Help Ministry of Road Transport and Highways tofind all useful roads in the city.InputThe input contains several test cases.Each test case starts with a line containing two integers n,m (2≤n≤2·105;1≤m≤2·105)—the number of junctions and the number of roads in the city.The following m lines contain road descriptions,one description per line.A description consists of a pair of space-separated integers u i,v i(1≤u i,v i≤n;u i=v i)meaning that the i-th road leads from the junction u i to the junction v i.The junctions are numbered from1to n.The City Hall is located at the junction1.It is guaranteed that there is at most one road between a pair of junctions in each direction.There is a blank line after each test case.The sum of n over all test cases in the input doesn’t exceed 2·105.The same is true for m:the sum of m over all test cases in the input doesn’t exceed2·105. OutputPrint two lines for each test case.On thefirst line print the number of useful roads.The second line should contain the indices of useful roads in ascending order.The roads are indexed from1to m in order of appearance in the input.Leave the second line empty if there are no useful roads in the city. Examplesstandard input standard output57 12 52 23 34 45 24 42 21 12513456 11Problem M.Variable ShadowingIn computer programming,variable shadowing occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope.The outer variable is said to be shadowed by the inner variable,and this can lead to a confusion.If multiple outer scopes contain variables with the same name,the variable in the nearest scope will be shadowed.Formally,a declared variable shadows another declared variable if the following conditions are met simultaneously:•the other variable is declared in outer scope and before(in terms of position in program source code)the declaration of thefirst variable,•the other variable is nearest among all variables satisfying the condition above.Here is an example containing exactly one variable shadowing:/*Prints a+max(b,c)*/int main(){int a,b,c;cin>>a>>b>>c;if(b>c){int a=b;//<--variable’a’shadows outer’a’int x=c;b=x;c=a;}int x=a+c;//<--no shadowing herecout<<x<<endl;}Variable shadowing is permitted in many modern programming languages including C++,but compilers can warn a programmer about variable shadowing to avoid possible mistakes in a code.Consider a trivial programming language that consists only of scopes and variable declarations.The program consists of lines,each line contains only characters‘{’,‘}’,‘a’...‘z’separated by one or more spaces.•Scopes.A scope(excluding global)is bounded with a pair of matching curly brackets‘{’and‘}’.A scope is an inner scope relative to another scope if brackets of thefirst scope are enclosed bybrackets of the second scope.•Variables.A variable declaration in this language is written just as a name of the variable.In addition all variables are lowercase Latin letters from‘a’to‘z’inclusive(so there are at most26 variable names).A variable is declared in each scope at most once.Given a syntactically correct program(i.e.curly brackets form a regular bracket sequence),write an analyzer to warn about each fact of variable shadowing.Warnings should include exact positions of shadowing and shadowed variables.Your output should follow the format shown in the examples below. InputThefirst line contains integer n(1≤n≤50)—the number of lines in the program.The following n lines contain the program.Each program line consists of tokens‘{’,‘}’,‘a’...‘z’separated by one or more spaces.The length of each line is between1and50characters.Each program line contains at least one non-space character.。

HUNAN UNIVERSITY ACMICPC Judge Online题目分类

HUNAN UNIVERSITY ACMICPC Judge Online题目分类

HOJ题目分类整合HOJ discussboard上的几个分类:hoj稍有难度题目分类(数论篇)hft777 2008-11-16 20:35:43.0在做这些题目前请学会在线性时间内筛选素数建议在Search Problem里1输入:prime2输入:number把这些题目练练10007Miller-Rabin + Pollard10070RSA,Pollard10174数的质数表示10195扩展欧几里德10297数的素数分解+ Euler定理10247欧拉函数10544数的素数分解10621中国剩余定理10694数的原根10853LCM10977梅森数11099RSA ,扩展欧几里德11103数的素数分解11126广义GCD11134欧拉函数11145RSA , 扩展欧几里德+ Pollard11181中国剩余定理11262欧拉函数hoj稍有难度题目分类(搜索与图论篇)reason 2008-11-07 23:39:33.0 Hoj稍有难度题目分类1.搜索,最短路:IDA*即迭代加深A*搜索,个人认为IDA*是对迭代加深搜索的一个强剪枝在此给出迭代加深搜索框架,大家有兴趣的可研究其与dfs的区别int max_depth;void dfs( int depth ){if ( depth > max_depth )return;操作}10020状态广搜,可用位运算以及A*加速10034 同余类的应用,可说是最短路变形102058数码问题,A*或者双向广搜或者IDA*10321bfs10466 bfs10901IDA*11016同上,得有比较好的剪枝函数11168状态bfs11108状态bfs11240找出规律就简单了11284应该是个很简单的bfs,但比赛时犯傻了。

11159bfs+2分枚举答案,zfy有3次bfs的解法,参见解题报告11227有点意思的,不太难,想不到再看解题报告11072优先队列bfs11207 同上11244双向bfs10183dfs,最优性剪枝11019最短路+dp,应该也可直接用dijkstra做搜索还有不少好题的,大家有兴趣可在poj在找些好题做做Hoj应该也还有不少,限于篇幅,只写以上这些2.图论以及博弈109802分图最大权匹配,km算法110682分图最大匹配112232分图最大匹配10128 博弈,SG函数应用11117博弈,SG函数应用10187强连通分支应用10537割点10929割边10801拓扑排序10420差分约束系统10035最小费用最大流10465最小费用最大流10284最小度限制生成树图论题建议多去poj做,hoj比较少hoj题目分类reason 2008-09-09 21:51:16.0入门题,旨在熟悉OJ环境10000 10005 10006简单模拟,还有些数学题包括(基本的筛法求素数,简单递推,辗转相除求GCD,基本位操作,排序)10010 10015 10017 10022 1003810039 10042 10045 10047 1004810049 10050 10051 10052 1005810062 10067 10072 10073 1007410082 10141 10144 10146 1014810149 10150 10151 10160 1017310178 10182 10184 10185 1018910190 10225 10238 10281 1030710337 10360 10373 10378 1039510400 10404 10406 10475 1047710483 10485 10493 10509 1051210556 10558 10562 10568 1060610624 10675 10724 10735 1074710759 10797 10809 10826 1084010880 10952 10981 11069 1108411116 11148 1115011172 10013经典贪心,一般还得用到排序,经典动态规划,二分的应用10001 10003 10014 10063 1010210106 10179 10181 10192 1023310279 10290 10023 11018 1076110768 10145 10011 10089 10019基本的搜索,dfs,bfs10109 10166 10250 10265 1064110147 11017 10844 10865 11159下面是较难的题目,有些也不太难,:)10009catalan数,要用大数10020较难的bfs,需要用位表示状态10018dp,递推公式出来应该不太难100212分图最小覆盖,最小覆盖= 最大匹配10024算是dp吧10053可用随机算法10068归并排序求逆序10071TSP问题10080递推,大数100812分法解方程10088树形dp10096利用2次函数的性质10128博弈问题,SG函数求解10163可分治,快速求幂,复杂度O( logn )10205A*搜索10233可用2叉搜索树10247数论,费马小定理10280并查集入门103442维凸包问题,Graphm扫描算法10372建议用堆10374prim算法应用10457可以看作是joseph问题,线段树求解,好像有递归的方法104952维背包问题10497可参考discuss的解题报告10508递归应用10534置换群10680欧拉函数的应用10696线段树入门,也可用树状数组10733dp10758基本栈应用10790数论好题10801拓扑排序10850bfs好题,虽然暴力能过,建议用状态dp10929无向图割边10935很好的一道数学题109802分图最小权匹配,也可用最小费用最大流11016IDA*搜索11067trie树应用11120扩展欧几里德应用11121矩阵快速乘法11134polya计数定理11151dijkstra求最短路112232分图最大匹配10153floyd求最短路10284最小度限制生成树此较难分类旨在让大学了解些算法,拓宽视野因此较难的分类我大概就是每类大概找了1个题,有时间我再把相关的分类补上HOJ题目分类给选修课的同学huicpc11 2006-03-21 01:59:59.010000 弱10001 DP 讨论版里有解题报告10002 费马点难10003 拆分成两个过程DP O(n)10004 fft 快速傅立叶变换10005 弱10006 弱10007 miller_robin pollar_rho分解10008 递归的画图一般10009 组合数学好像是卡特兰数10010 简单,一个数组存状态一个存数值纯暴力10011 数学题有规律10012 纯暴力10013 一般难度算个万年历10014 简单DP,每次向下加最大的10015 弱10016 弱10017 贪心+回溯好像暴扫也出结果1001810019 简单贪心100201002110022 简单读题和格式很讨厌10023 贪心我在讨论版里有解题报告100241002510026 弱10027 同10001 最长递增子序列不过用二分查当前递增的子序列100281002910030 纯编译原理也算基础题了1003110032100331003410035100361003710038 弱10039 弱10040 一般从后向前扫好像奇数层取最大偶数层取最小10041 纯代码量的题10042100431004410045 简单Joseph Ring 考试的经典题目1004610047 简单字符串模拟加法10048 简单两个字符串比较公共字符10049 简单10050 简单开个状态数组hash10051 简单10052 简单有规律10053 稍难随机和两层循环降解状态都可以出结果10054 贪心+递增子序列100551005610057 讨厌读题简单的计算题10058 弱1005910060 稍难模拟1006110062 简单10进制转9进制10063 稍难的贪心10064100651006610067 简单有点递归交换的意味10068 稍难必须归并排序才能过bubble TLE 老大给了16M测试数据,哭吧10069 稍难好像还是归并100701007110072 弱10073 弱10074 DP 加f[1],f[2],f[3]100751007610077100781007910080 一般大数加法10081 简单推出一个超越方程只好二分了其实应该归到数值算法10082 简单贪心,不过有公式可推数学题10083100841008510086100871008810089 一般DP 定义一个maxa[251][251]的数组query 只需要O(N*K)的时间复杂度1009010091 一般排序以后暴搜4种可能组合1009210093 极其恶心的题目居然抛随机种子1009410095 暴搜我在讨论版里有解题报告1009610097 简单题一个qsort,写的暴痛苦10098 纯代码量题排序然后扫完9种情况10099 推公式1010010101 烂题10102 DP 二维的最大加和子段10103101041010510106 一般用匹配和离散化都可以把区间扫出来10107 一般DP1010810109 floodfill 种子染色法101101011110112 不是太复杂的模拟不过不好想1011310114 编译原理表达式的计算10115 一般7进制10116101171011810119101201012110122 贪心暴搜我在讨论版有解题报告101231012410125 简单的贪心1012610127 DP1012810129101301013110132101331013410135 简单10136 简单10137 一般并查集10138 简单的排序101391014010141 简单strtok函数的使用10142 简单前缀表达式的计算10143 简单模拟位操作10144 简单9进制加法10145 一般赤裸裸的背包10146 高精度乘法1014710148 一般空间换时间找素数10149 简单暴搜和位操作10150 高精度乘法10151 简单101521015310154 简单高精度乘法10155 贪心+回溯10156 稍难吧找重复单词DP和二叉查找树都可以不过推荐后者1015710158 简单暴力题10159 简单表达式计算10160 弱1016110162 讨厌的模拟10163 简单看讨论版解题报告10164101651016610167 简单搜索101681016910170101711017210173 弱10174 简单开个素数表方便些1017510176 简单表达式计算1017710178 弱10179 做了n遍了以前做过就归为简单101801018110182 简单两个数组匹配1018310184 简单用__int6410185 简单推出等差公式暴搜101861018710188 稍难模拟一个队列10189 弱10190 简单模拟1019110192 简单DP O(Nlog(N))和暴搜O(N^2))都可以出来101931019410195101961019710198101991020010201 一般英文转数字模拟题102021020310204 简单10205102061020710208102091021010211 简单10212 简单暴搜过102131021410215 简单排序然后搜索10216 弱排序102171021810219102201022110222 一般高精度乘法1022310224 一般状态机10225 简单01状态转换1022610227102281022910230102311023210233 这题数据太弱了让你们都过了10234 简单暴搜10235102361023710238 简单找规律注意精度真不行__int64 1023910240 简单注意汉字编码方式10241 一般表达式编译10242 一般表达式编译10243 一般KMP匹配1024410245 一般队列的模拟10246 一般暴搜1024710248102491025010251102521025310254 一般最长递增子序列1025510256102571025810259102601026110262 简单压栈模拟10263102641026510266102671026810269102701027110272102731027410275102761027710278re ACM200408103252006-03-21 11:20:41.0感谢,这样好找自己需要针对的题进行练习也拉点人气,最后一页补几个xnby2006-03-21 13:32:24.010252 一般搜索+剪枝10272 一般看懂题就可以模拟了10275 简单暴力10277 一般二分图匹配(男女匹配)10278 一般模拟找规律题这么庞大的工作,一定很辛苦呢。

算法练习题

算法练习题

算法练习题一、基础算法1. 编写一个程序,实现一个冒泡排序算法。

2. 实现一个选择排序算法。

3. 实现一个插入排序算法。

4. 编写一个函数,计算一个整数数组中的最大值和最小值。

5. 编写一个函数,实现二分查找算法。

6. 编写一个函数,实现快速排序算法。

7. 编写一个函数,判断一个整数是否为素数。

8. 编写一个函数,实现反转一个整数数组。

9. 编写一个函数,计算两个整数数组的交集。

10. 编写一个函数,判断一个字符串是否为回文。

二、数据结构11. 实现一个单链表的基本操作,包括插入、删除、查找。

12. 实现一个双向链表的基本操作,包括插入、删除、查找。

13. 实现一个栈的基本操作,包括压栈、出栈、查看栈顶元素。

14. 实现一个队列的基本操作,包括入队、出队、查看队首元素。

15. 实现一个二叉树的基本操作,包括插入、删除、查找。

16. 实现一个二叉搜索树的基本操作,包括插入、删除、查找。

17. 实现一个哈希表的基本操作,包括插入、删除、查找。

三、搜索与图论18. 编写一个程序,实现深度优先搜索(DFS)算法。

19. 编写一个程序,实现广度优先搜索(BFS)算法。

20. 编写一个程序,求解迷宫问题。

21. 编写一个程序,计算一个有向图的拓扑排序。

22. 编写一个程序,计算一个无向图的欧拉回路。

23. 编写一个程序,计算一个加权无向图的最小树(Prim算法)。

24. 编写一个程序,计算一个加权有向图的最短路径(Dijkstra算法)。

25. 编写一个程序,计算一个加权有向图的所有顶点对的最短路径(Floyd算法)。

四、动态规划26. 编写一个程序,实现背包问题。

27. 编写一个程序,计算最长公共子序列(LCS)。

28. 编写一个程序,计算最长递增子序列(LIS)。

29. 编写一个程序,实现编辑距离(Levenshtein距离)。

30. 编写一个程序,实现硬币找零问题。

31. 编写一个程序,实现矩阵链乘问题。

第三十届ACMICPC 世界总决赛题目解析

第三十届ACMICPC 世界总决赛题目解析

第三十届ACM/ICPC 世界总决赛题目解析斯坦福大学王颖本次比赛的题目请见/icpc/Finals/2006WorldFinalProblemSet.pdf Problem A本题的大意是,给出一些机票,每个机票都是一条路线,比如城市A->城市B->城市K->…->城市N,并且每张机票有一个价格。

我们可以只用一张机票的一部分,比如城市A->城市B->城市K,然后就丢弃这张机票。

但有两个条件,第一,必须在机票的起始城市才能使用机票,也就是说,我们不能用上面的机票从城市B到城市K;第二,如果使用了一张机票的部分,以后就不能使用剩下的部分。

现在给出一条路线,我们要按顺序访问一系列的城市。

给出所有可以购买的机票,每种机票可以买无限张,问怎样可以用最少的花费完成整个旅途。

本题的数据规模颇小,机票最多20种,而每个机票最多经过10个城市。

由于机票可以重复购买,城市必须按顺序经过,很容易想到要用动态规划。

但从比赛过程中可以发现,无数的队伍被这题卡住了,而且很少的队伍能够一次通过。

问题就在于,并不是只能访问指定路径上的城市,而是可以访问一些辅助的城市来减小花费。

所以,我们要用一个二元组(i,j)来表示一个状态。

其中i表示指定路径上已经按顺序访问了的城市数量,j表示当前所在城市。

通过机票的信息,不难得到状态之间的一个有向图,而我们要求的其实就是一个最短路径。

注意到这个图是有圈的,所以我们不能直接用动态规划,而是需要用最短路算法。

本题初看觉得规模甚小,此时则可以发现最多能有20*10=200个城市,共可以有10*200=2000个状态,还是颇有规模的。

总结:想清楚后此题并不复杂。

但比赛时必须保持头脑清醒,分析清楚题意,才可能顺利解决此题。

比赛中虽然很多队伍做出此题,但很少有队伍一次做对,更有一些队伍一直困在这题,可见比赛中队伍普遍紧张,没能仔细的去考虑。

Problem B典型的最小费用最大流,不多说了。

ACM必做50题的解题-模拟

ACM必做50题的解题-模拟
break;
}
return 1;
}
int main(){
int i,j,n;
char c;
scanf("%d",&n);
while(n--){
for(i=1; i<=3; i++)
scanf("%s %s %s",left[i],right[i],result[i]);
for(c='A'; c<='L'; c++){
1)选择合适的算法
对于每一枚硬币x逐个试探:
x比真币轻的猜测是否成立?猜测成立则进行输出。
x比真币重的猜测是否成立?猜测成立则进行输出。
2)选择合适的数据结构
以字符串数组存储称量的结果。每次称量时,天平左右最多有6枚硬币。因此,字
符串的长度需要为7,最后一位存储字符串的结束符’\0’,便于程序代码中使用字符串
{
int t,n;
cin>>t;
while(t--){
cin>>n;
int x,y;
int cross[SIZE];
memset(cross,0,sizeof(cross));
for(int i=0;i<n;++i){
cin>>x>>y;
int start,end;
if(x>y){
swapnum(x,y);
case 'u': if( strchr(left[i], x) == NULL) return 0;
break;
case 'e': if(strchr(right[i], x) != NULL || strchr(left[i], x) != NULL) return 0;
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Input:输入数据的第一行是四个实数;
D1 C D2 P分别表示两个城市之间的距离,汽车油箱的容量,每升汽油能行驶的距离,出发点每升汽油价格;
第二行是一个整数N,沿途的油站数。
第三行到第N+2,每一行是一个油站的基本信息描述,包括该油站离出发点的距离,该油站每升汽油的价格。
Output:输出到达目的城市的最小费用(四舍五入到两位小数),若不能到达目的城市则输出: No solution.
Input:The input contains severaltest cases(测试例子). For each test case, only line contains eight integer numbers , describing the coordinates of the triangle and the point. All the integer is in range of [-100 , 100]. The end of the input is indicated by a line containing eight zeros separated by spaces.
6、阿长最近迷上了一种矩阵,他认为通过分析这种图形可以参悟人的生死轮回。这个图形由1到n*n这些数字组成。n表示一个人的年龄。比如,当一个人的年龄为4的时候,那么对于他的轮回矩阵就是如下的一个图形:
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
从左上角的1开始,以顺时针的方向进行旋涡式的伸展。这样的一个图形我们称它为4岁的轮回矩阵。为了更好的研究这些矩阵,阿长不得不再次求助于你,希望你能编写一个程序,当我们输入一个人的年龄的时候(年龄小于50),你的程序能 4 0 0 4 3 1
0 0 4 0 0 4 1 2
0 0 4 0 0 4 -1 -1
0 0 0 0 0 0 0 0
Sample Output:
NO
YES
NO
4.Longest Ordered Subsequence
Problem description:Anumeric sequence(数字序列)ofaiis ordered ifa1<a2< ... <aN. Let the subsequence of the given numeric sequence (a1,a2, ...,aN) be any sequence (ai1,ai2, ...,aiK), where 1 <=i1<i2< … <iK<=N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
Output:Output must contain a single integer—the length of the longest ordered subsequence of the given sequence.
Sample Input:
7
1 7 3 5 9 4 8
Sample Output:
Output:For each test case , if the point is inside of the triangle ,please output the string ”YES”, else output the string “NO”. You just need to follow the following examples.
1、坚持不懈的蜗牛
Problem description:现在有一只蜗牛,掉入一个 6米深的井底,它想爬到井口上面去。蜗牛在第一天的白天能爬 3 米,但在每天夜晚由于睡觉,它会滑落 1 米。又由于疲劳因素,以后每个白天它所能爬的高度以 10% 递减,也就是说,下一天比前一天要少爬 0.3 米。那么蜗牛哪一天才能爬到井口上去呢?在下表中你会看到,蜗牛在第三天爬到井口。
7、一本书的页码从自然数1开始顺序编码直到自然数n。书的页码按照通常的习惯编排,每个页码都不含多余的前导数字0。例如,第6页用数字6表示,而不是06或006等。数字计数问题要求编写程序对给定书的总页码n,计算出书的全部页码中分别用到多少次数字0,1,2,3,4,……9.
8、用给定的几种钱币凑成某个钱数,一般而言有多种方式。例如:给定了6种钱币面值为2、5、10、20、50、100,用来凑15元,可以用5个2元、1个5元,或者3个5元,或者1个5元、1个10元,等等。显然,最少需要2个钱币才能凑成15元。,给定若干个互不相同的钱币面值,编程计算,最少需要多少个钱币才能凑成某个给出的钱数。
Output:对于输入中的每个事件(每一行),程序输出一行与之对应。输出结果包括蜗牛是否成功超过要求高度,以及到达该高度的天数。
Sample Input:
6 3 1 10
10 2 1 50
50 5 3 14
0 0 0 0
Sample Output:
SUCCESS ON DAY 3
FAILURE ON DAY 4
Sample Input:
275.6 11.9 27.4 2.8
2
102.0 2.9
220.0 2.2
Sample Output:
26.95
3.Triangle
Problem description:Given thecoordinates(坐标)of thevertices(顶点)of a triangle,And a point. You just need to judge whether the point is in the Triangle.
天数
每天初始高度
每天所爬高度
白天到达高度
夜间滑落后高度
1
0
3
3
2
2
2
2.7
4.7
3.7
3
3.7
2.4
6.1
--
你现在要将这个问题一般化。给定不同的参数,最后的结果可能有两种:爬到井口或滑落井底。你需要计算的是,最终结果如何,以及这个结果发生在哪一天。
Input:输入文件中可包含多个事件,每一行中输入一次事件的 4 个参数。这四个数分别是: H 、 U 、 D 、 F ,参数之间用空格隔开。其中 H 为井的深度, U 是蜗牛在第一天的白天能爬的高度, D 是蜗牛每天晚上要滑落的高度, F 是疲劳因子(用百分数的形式表示,如 30 表示为 30% )。蜗牛所爬的高度不能为负数,假若由于疲劳因素,我们算出蜗牛该天到达的高度为负,那么认为蜗牛当天根本没有爬。不管蜗牛白天爬多高,它每天晚上都会滑落 D 米。如果一行四个数都为 0 ,则表示结束。
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input:The first line of input contains the length of sequence N. The second line contains the elements of sequence—N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000
4 2 1 3 5
7 10 6 9 8
(注意:输入第一行为1/2数组a的大小,第二行为数组a中的元素,输出时b、c数组中元素顺序不一定与示例一致)
4、令A为元素是0和1的N行N列矩阵。A的子矩阵S由形成方阵的任意一组相邻项组成。设计一种O(n2)算法,确定A中的全为1的最大子矩阵的阶数。
输入:(可以程序中初始化)
例如,如果输入是8,5,2,7而K是12,则答案为yes(5和7)。
输入:
8 5 2 7
12
输出:
yes
3、已知有2n个元素的无序数组a,试用O(n)算法将这2n个元素分别放入大小均为n的数组b和c。使得数组b中的所有元素均小于数组c中的任意元素。
输入:
5
7 10 4 2 6 9 1 8 3 5
输出:
5、输入一批数据{34,27,56,12,25,78,94,36,58,90,66,77},从这批数中找出最大值和第二大的值以及它们所在的位置。要求在同一个循环中既找出最大值又找出第二大值(只能使用一层循环)。不允许用排序的方法。
6、编写一个万年历程序。输入1900年后的某一年,要求显示该年份的日历,日历以月份顺序排列,每月以星期顺序排列,类似于一般挂历上的格式。
4
1 0 1 1 1 0 0 0
0 0 0 1 0 1 0 0
0 0 1 1 1 0 0 0
0 0 1 1 1 0 1 0
0 0 1 1 1 1 1 1
0 1 0 1 1 1 1 0
0 1 0 1 1 1 1 0
0 0 0 1 1 1 1 0
输出:
4
(输入:一个矩阵,输出:全为1的最大子矩阵阶数)
(提示:动态规划解题。)
1、装箱问题:给定大小为S1,…,Sn的n个物件,其中0<Si≤1,寻找能够装进所有这些物件的最少数量的箱盒,每个箱盒容量为1。(提示:贪心法求解。)
2、已知一个包含n个元素的整型数组和一个整数K。试用O(NlogN)算法解决这样的问题:确定数组中是否存在两个数,它们的和等于给定的数K。一个数可以被使用两次。
FAILURE ON DAY 7
相关文档
最新文档