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;

ACM程序设计竞赛例题

ACM程序设计竞赛例题

ACM程序设计竞赛例题备战ACM资料习题1. 0-1背包问题在0 / 1背包问题中,需对容量为c 的背包进行装载。

从n 个物品中选取装入背包的物品,每件物品i 的重量为wi ,价值为pi 。

对于可行的背包装载,背包中物品的总重量不能超过背包的容量,最佳装载是指所装入的物品价值最高。

程序如下:#includevoid readdata();void search(int);void checkmax();void printresult();int c=35, n=10; //c:背包容量;n:物品数int w[10], v[10]; //w[i]、v[i]:第i件物品的重量和价值int a[10], max; //a数组存放当前解各物品选取情况;max:记录最大价值//a[i]=0表示不选第i件物品,a[i]=1表示选第i件物品int main() {readdata(); //读入数据search(0); //递归搜索printresult();}void search(int m){if(m>=n)checkmax(); //检查当前解是否是可行解,若是则把它的价值与max 比较else{a[m]=0; //不选第m件物品search(m+1); //递归搜索下一件物品a[m]=1; //不选第m件物品search(m+1); //递归搜索下一件物品}}void checkmax(){int i, weight=0, value=0;for(i=0;i<n;i++)< p="">{if(a[i]==1) //如果选取了该物品{weight = weight + w[i]; //累加重量value = value + v[i]; //累加价值}}if(weight<=c) //若为可行解if(value>max) //且价值大于maxmax=value; //替换max}void readdata(){int i;for(i=0;i<n;i++)< p="">scanf("%d%d",&w[i],&v[i]); //读入第i件物品重量和价值}void printresult(){printf("%d",max);}2.装载问题有两艘船,载重量分别是c1、c2,n个集装箱,重量是wi (i=1…n),且所有集装箱的总重量不超过c1+c2。

2021年第十三届四川省ACM-ICPC大学生程序设计竞赛

2021年第十三届四川省ACM-ICPC大学生程序设计竞赛

2021年第⼗三届四川省ACM-ICPC⼤学⽣程序设计竞赛⽬录反思:这场⽐赛是在21/10/16队内赛下午打的,总的来说还是没状态,全靠队友了,⾃⼰题也看不懂,k题还没做完,队友就ac了两道题,雀⽒是该多打打cf了直接copy我的补题报告了,毕竟要给⽼师看的会写的更详细A-Chuanpiao这句话让我们猜了半天,实在想不出来跟题⼲有啥关系,后来直接忽略了,发现ac了(其实是个废话)题意:就是给出数,让求出两组(1,6)有多少组合能加出这个数,打个表就⾏了// 打表就⾏ 0 1 1 2 2 3 3 3 2 2 1 1# include <iostream>using namespace std;int main(){int t,k;cin >> t;while (t --){cin >> k;if (k >= 1 &&k <= 7) printf("%d\n",k/2);else if (k == 8) printf("3\n");else if (k >=9 && k <= 10) printf("2\n");else if (k >= 11 && k <= 12) printf("1\n");else printf("0\n");}return 0;}K-skip Permutation题意:⼀开始想错存个数组,⽤过了就归零,但想想还是太⿇烦了,仔细想想这不就是个等差数列题解:从1到n写出公差为k的等差数列,⽐如k=3,那么就是1,4,7...... 我们就在1~4这个k、区间for循环写出公差为k且⼩于等于n的等差数列就⾏,注意末尾⽆空格# include <iostream>using namespace std;int a[1000];int main(){int n , k;cin >> n >> k;int cnt = 0;// for (int i = 1; i <= n; i ++)// a[i] = i;// 等差数列for (int i = 1; i <= k; i ++){for (int j = 0; j * k + i <= n;j ++){if (cnt < n){cout << j * k + i << " ";}else cout << j * k + i;cnt ++;}}return 0;}D-Rock Paper Scissors题意:⽯头剪⼑布,注意开long long题解:要想分值最⼤,就让他先赢,后平,再输,这题坑了我很久,⾸先每⾃⼰看谁赢,所以写1赢,错了,之后每次做min运算更新rock,scissor,paper时这三个数值也会变化,因此不能直接加减,还要设置⼀个中间变量# include <iostream># include <cmath># include <algorithm>typedef long long ll;using namespace std;int main(){int t;ll r1, p1, s1, r2, p2, s2;cin >> t;while(t --){cin >> r1 >> p1 >> s1;cin >> r2 >> p2 >> s2;ll sum = 0;ll mi = 0;// win// 2 出⽯头,1出剪⼑mi = min (r2,s1);sum += mi;r2 -= mi;s1 -= mi;// 2 出剪⼑,1出布mi = min (s2,p1);sum += mi;s2 -= mi;p1 -= mi;// 2 出布, 1出⽯头mi = min (p2,r1);sum += mi;p2 -= mi;r1 -= mi;// 平局// rockmi = min (r1,r2);r1 -= mi;r2 -= mi;// scissorsmi = min (s1,s2);s1 -= mi;s2 -= mi;// papermi = min (p1,p2);p1 -= mi;p2 -= mi;// failsum -= (p2 + r2 + s2);cout << sum << endl;}return 0;}H-Nihongo wa Muzukashii D字符串替换,暴⼒写就可,但要注意字符为k的细节// verb -> end with masu, te or de/*if end with imaus,chimaus or rimaus change to tteif end with imaus,chimaus or rimaus change to tteif end with mimaus, bimaus or nimaus, change to ndeif end with kimasu, change to ite but if s is "ikimaus",change to "itte"if end with gimasu, change to ideif end with shimasu, change to shite*/#include <iostream>#include <algorithm>#include <cstring>#include <string>using namespace std;typedef long long ll;const int N = 1e5 + 10;int main(){int t;cin >> t;while (t --){string s;cin >> s;ll n = s.length();if (s[n-1] == 'e' && s[n-2] == 't' || s[n-1] == 'e' && s[n-2] == 'd')cout << s << endl;else {if (s[n-6] == 'm' || s[n-6] == 'b' || s[n-6] == 'n'){for (int i = 0; i < n - 6; i ++)cout << s[i];cout << "nde" << endl;}else if (s[n-6] == 'k'){if (s == "ikimasu")cout << "itte" << endl;else {for (int i = 0; i < n - 6; i ++)cout << s[i];cout << "ite" << endl;}}else if (s[n-6] == 'g'){for (int i = 0; i < n - 6; i ++)cout << s[i];cout << "ide"<< endl;}else if (s[n-6] == 'h' && s[n-7] == 's'){for (int i = 0; i < n - 7; i ++)cout << s[i];cout << "shite" << endl;}else if (s[n-6] == 'h' && s[n-7] == 'c'){for (int i = 0; i < n - 7; i ++)cout << s[i];cout << "tte" << endl;}else if (s[n-6] == 'r'){for (int i = 0; i < n - 6; i ++)cout << s[i];cout << "tte" << endl;}else {for (int i = 0; i < n - 5; i ++)cout << s[i];cout << "tte" << endl;}}}return 0;}B-Hotpot题意:n个⼈围着⽕锅转,他想吃什么,要是没有这个⾷材,就放,要是有,就吃了,并且幸福度+1题解:看到这个题,直接想到了奇偶性,若是偶数倍的⼈喜欢吃⼀种⾷材,那么偶数倍的奇数位肯定吃不到,偶数倍的偶数位⼀定能吃到前⼀个⼈放的⾷材,如果是奇数倍的⼈喜欢⼀个⾷材,那n个⼈⼀圈下来吃到的⾷物就要反转了,第⼀圈能吃到,那么第⼆圈就吃不到了,偶数倍容易解决,但是奇数倍每⼀圈都要变化,在⽐赛过程中没有想到直接合成2*n的做法,最后还是靠队友ac了这个题,赛后看了队友代码和相关题解,感觉并不是很好理解,⽽且写的相对复杂,后来翻到⼀个很直观的写法,⾃⼰重现写了⼀遍ac代码代码:# include <iostream># include <algorithm># include <string.h>using namespace std;typedef long long ll;const int N = 1e5 + 10;int eat[N*2];// 纪录喜欢吃的int idx[N*2];// ⽤作标记int num[N*2];// 记录是奇数位还是偶数位int ans[N*2];// 记录满意度int main(){int t;cin >> t;while (t --){int n, k;ll m;cin >> n >> k >> m;memset(eat,0,sizeof(eat));memset(idx,0,sizeof(idx));memset(num,0,sizeof(num));memset(ans,0,sizeof(ans));for (int i = 0; i < n; i ++){cin >> eat[i];eat[n+i] = eat[i];}//⽤round记录圈数,res纪录不⾜2n的圈数int round = m / (2*n);int res = m % (2*n);// 先处理round*2n圈for (int i = 0; i < 2*n; i ++){num[eat[i]] ++;if (num[eat[i]] % 2 == 0)idx[i] = 1;else idx[i] = 0;ans[i] += idx[i];// 这⾥直接乘上圈数ans[i] *= round;}// 处理剩下的不⾜2*n的情况for (int i = 0; i < res; i ++){num[eat[i]] ++;if (num[eat[i]] % 2 == 0)if (num[eat[i]] % 2 == 0)idx[i] = 1;else idx[i] = 0;ans[i] += idx[i];}// 求sumfor (int i = 0; i < n; i ++){ans[i] += ans[i+n];cout << ans[i] << " ";}cout << endl;}return 0;}M-True Story这题看了好久也没看懂这题说些什么话,找孙中远总算是翻译过来了qwq题意:n个⼈有各⾃的速度s[i],到机场的距离都为x,原本是从0时出发,p0时登机,但是飞机会有k次延迟登机,这k次宣布延迟登机的时刻t[i],都会宣布会推迟到某⼀个时刻p[i],倒是这n个⼈有⼀个特点,就是只会在宣布推迟的那⼀时刻开始⾏动,⽐如说⼀开始从0时刻出发,5点登机,3点通知推迟到7点登机,那么这⼈就会从3点出发,即使他可能会延误飞机,也不会从⼀开始的0时刻出发,努⼒不⼀定会成功,但放弃⼀定会失败。

第36届ACMICPC网络赛试题(大连、上海、成都)

第36届ACMICPC网络赛试题(大连、上海、成都)

2011ACM/ICPC 网络赛试题(大连站)1001问题描述你们记得我们儿时的时光吗?当我们还是孩子的时候,我们对我们周围的一切事物都感兴趣。

一件小事或一个简单的游戏会使我们愉悦很长时间。

LLL是个淘气的小男孩。

现在,他长大了。

深夜,他经常忘记一些事情,包括他儿时的一个令他非常惬意的简单游戏。

游戏规则如下:在地上放置有很多砖块,小LLL 需要使用这些砖块来盖“摩天大楼”。

砖块分为三种类型,每种类型的砖块都用一个整数d标记。

我们用4个整数ai,bi,ci,di来描述每个砖块的形状。

其中,ai、bi分别表示砖块的长和宽,ci表示砖块的厚度。

我们知道ci必须与地面垂直。

di表示砖块的类型。

①当di=0时,砖块的长和宽一定要大于等于压在它下面砖块的长和宽;②当di=1时,砖块的长和宽不仅要大于等于压在它下面砖块的长和宽,而且砖块的面积一定要大于压在它下面的砖块面积;③当di=2时,砖块的长和宽一定要大于压在它下面砖块的长和宽。

现有一些砖块,你知道怎样用它们来盖最高的“摩天大楼”吗?输入输入有很多测试实例。

在每个测试实例中,第一行是一个整数n(0<n≤1000),表示砖块的数量。

从第二行至第n+1行,每行表示第i-1块砖块的a,b,c,d(1≤a,b,c≤108,d=0或1或2)。

输入结束标志为n=0。

输出输出一行一个整数表示使用n个砖块构建的最高“摩天大楼”的高度。

样例输入样例输出3241010 12 01010 12 11010 11 22111010 11 11010 11 11002问题描述φ(有时称为φ函数)是用于求小于n且与n互素的数的个数。

欧拉函数:)(nφ。

例如:小于9且与9互素的数是1,2,4,5,7和8,即6)9(=HG是XY的主人。

一天,HG想通过一个数学游戏教给XY一些关于欧拉函数的知识。

即HG给出一个正整数N,XY告诉他的主人在不小于2,且不大φ具有最大值。

很快,HG发现这对于XY似于N的范围内的数n的值,使得)(n乎是一件易事,因为XY很快就用一段小程序给出了正确答案。

2010ACMICPC亚洲赛区 成都预选赛题目Ensure

2010ACMICPC亚洲赛区 成都预选赛题目Ensure

Problem E.Ensure No AbsenceTime limit:1secondMemory limit:256megabytesIn the year2022,the scu acmers decide to hold a party,and most of the old scu acmers have recieved the invitation,including onmylove,tanlinghang,and zsasuke(the original members of the scu isap team). As they graduated from scu ten years ago,they live in different cities currently.They are all very arrogant, and each believes himself to be the best runner among all the scu acmers.To prove this,they all decide to spend days running to the destination(the city where the party is to be held),and to save energy, they each will choose the shortest route for himself(there may exist more than one shortest routes,in such cases,they would choose one of them at random).But this lead to a series of problems:they may stop to rest occasionally,and once they meet each other on one same road,they will stop running and begin to argue for days who is the best runner,entirely forgetting the party.The scu leaders are all very considerate,they don’t want the absence of anyone,so they will select a suitable city to hold the party to guarantee that the isap team members will not meet each other on their way to the party.But they are all very busy,so the task is assigned to you,brilliant icpcer!InputProcess till EOF.Each case contains two positive integers n,m(3≤n≤3000,1≤m≤200000)in thefirst line.Indicating the number of cities to choose from,and the number of the edges(onmylove lives in city1,tanlinghang lives in city2,and zsasuke,city3),then m lines follow,each line contains3positive integers a,b,c (1≤a,b≤n,1≤c≤10,b=a,there is at most one edege between two distinct cities)indicating that it takes each of them(onmylove,tanlinghang,or zasuke)c days to get to city b from city a,or c days to get to city a from city b if running at full speed(from this,you know they all run at the same speed,so there is no point in arguing at all,but they are all very unreasonable!)OutputFor each case,if there are no cities satisfying the conditions above,you should puts“impossible”in a single line,otherwise,you should print a number n(the number of cities satisfying the conditions)in a line,the second line contains n integers,meaning the ids of the cities satisfying the conditions,and besides,sort them in increasing order.Sample input and outputinput output32 121 231 43 142 241 343 55 152 452 523 245 3411 2 1 4 1 5HintIn thefirst case,we could not choose city3to hold the party,since tanlinghang may rest on the roadbetween2and3,so onmylove may meet tanlinghang on the same road and fall into arguing.so we choose city2to hold the party.In the third case,we could not choose city4for the same reason.suppose we choose city4,the shortest route for onmylove is1–5–4,and the shortest route for tanlinghang is2—5—4or2—4,if tanlinghang choose the route2—5—4,he may meet onmylove on the road between5and4,and arguing is inevitable. Problemsetterzsasuke。

icpc题目简析

icpc题目简析

Page 4
ACM数学题特点分析:
题意容易理解 算法相对简单(有些很难的!!)
编程比较容易
ACM/ICPC入门练习的好选择 下面,分类介绍:
Page 5
hdoj2006
#include <cstdio> int main() { int n, a, res; while(scanf("%d", &n)==1) { res = 1; while(n--) { scanf("%d", &a); if(a%2) res*=a; } printf("%d\n", res); } return 0; }
Page 30
hdoj1071
#include<stdio.h> #include<math.h> struct point { double x; double y; };
hdoj1071
int main() { int t; point p1,p2,p3; double k,h,a,b,c; double out; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y); k=(p3.y-p2.y)/(p3.x-p2.x); h=p2.y-k*p2.x; a=( (p3.y-p2.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p2.x) ) / ( (p3.x-p2.x)*(p2.xp1.x)*(p3.x-p1.x) ); b= -2*a*p1.x; c=p1.y-a*p1.x*p1.x-b*p1.x; out=a/3*( pow(p3.x,3)-pow(p2.x,3) )+(b-k)/2* (pow (p3.x,2)-pow(p2.x,2) )+(ch)*(p3.x-p2.x); printf("%.2f\n",out); } return 0; }

蓝桥杯ACM决赛经典试题及其详解

蓝桥杯ACM决赛经典试题及其详解

/*入门训练A+B问题问题描述输入A、B,输出A+B。

说明:在“问题描述”这部分,会给出试题的意思,以及所要求的目标。

输入格式输入的第一行包括两个整数,由空格分隔,分别表示A、B。

说明:“输入格式”是描述在测试你的程序时,所给的输入一定满足的格式。

做题时你应该假设所给的输入是一定满足输入格式的要求的,所以你不需要对输入的格式进行检查。

多余的格式检查可能会适得其反,使用你的程序错误。

在测试的时候,系统会自动将输入数据输入到你的程序中,你不能给任何提示。

比如,你在输入的时候提示“请输入A、B”之类的话是不需要的,这些多余的输出会使得你的程序被判定为错误。

输出格式输出一行,包括一个整数,表示A+B的值。

说明:“输出格式”是要求你的程序在输出结果的时候必须满足的格式。

在输出时,你的程序必须满足这个格式的要求,不能少任何内容,也不能多任何内容。

如果你的内容和输出格式要求的不一样,你的程序会被判断为错误,包括你输出了提示信息、中间调试信息、计时或者统计的信息等。

样例输入12 45说明:“样例输入”给出了一组满足“输入格式”要求的输入的例子。

这里给出的输入只是可能用来测试你的程序的一个输入,在测试的时候,还会有更多的输入用来测试你的程序。

样例输出57说明:“样例输出”给出了一组满足“输出格式”要求的输出的例子。

样例输出中的结果是和样例输入中的是对应的,因此,你可以使用样例的输入输出简单的检查你的程序。

要特别指出的是,能够通过样例输入输出的程序并不一定是正确的程序,在测试的时候,会用很多组数据进行测试,而不局限于样例数据。

有可能一个程序通过了样例数据,但测试的时候仍只能得0分,可能因为这个程序只在一些类似样例的特例中正确,而不具有通用性,再测试更多数据时会出现错误。

比如,对于本题,如果你写一个程序不管输入是什么都输入57,则样例数据是对的,但是测试其他数据,哪怕输入是1和2,这个程序也输出57,则对于其他数据这个程序都不正确。

acm大赛历年程序题

acm大赛历年程序题

acm大赛历年程序题ACM国际大学生程序设计竞赛(The ACM International Collegiate Programming Contest)是全球范围内最具声誉的大学生程序设计竞赛之一。

每年都有来自世界各地的顶尖大学参加这一比赛,他们将在规定的时间内解决一系列编程问题,以展示他们的算法和编程技巧。

历年来,ACM大赛的程序题目一直是各个大学的计算机科学学生学习和训练的重要素材。

ACM大赛历年程序题的设计旨在考察参赛者的算法设计与实现能力。

这些问题通常具有一定的难度,涵盖了多种算法和数据结构。

在ACM大赛中,选手需要在规定的时间内,根据给定的输入数据,编写程序解决问题,并输出正确的结果。

ACM大赛历年程序题通常分为多个分类,下面将列举几个常见的分类及其特点:1. 图论问题:图论是ACM大赛中常见的题目类型之一。

这类问题涉及到对图的建模和算法设计。

参赛者需要熟悉常见的图观念和算法,如图的遍历、最短路径、最小生成树等。

2. 动态规划问题:动态规划是ACM大赛中常用的解决问题的方法之一。

动态规划问题通常需要设计状态转移方程,并根据之前已经计算过的结果来推导最优解。

这类问题要求选手具备良好的逻辑思维和数学推导能力。

3. 贪心算法问题:贪心算法是一种简单而高效的算法思想。

贪心算法问题一般需要选手根据问题的特性,每次都选择当前情况下最优的解决方案。

这类问题在实际应用中非常常见,选手需要能够灵活地运用贪心策略解决问题。

4. 字符串处理问题:字符串处理问题涉及到对字符串进行各种操作,如匹配、查找、替换等。

选手需要熟练掌握字符串的各种操作和常见算法,如KMP算法、Boyer-Moore算法等。

5. 数学问题:数学问题在ACM大赛中也是常见的题目类型。

这类问题通常涉及到各种数学公式和算法,如排列组合、素数判定、快速幂等。

选手需要具备扎实的数学知识和计算能力。

ACM大赛历年程序题的学习对于计算机科学学生来说是非常重要的。

国际大学生程序设计大赛(ACMICPC)简介及竞赛样题

国际大学生程序设计大赛(ACMICPC)简介及竞赛样题

附件二国际大学生程序设计大赛(ACM/ICPC)简介相关情况简介一>、历届ACM-ICPC亚洲预选赛中国内地部分赛区参赛情况二>、历届ACM-ICPC全球总决赛中国内地高校获奖情况注:***金牌,**银牌,*铜牌;--表示未参加上一年的地区预赛, / 表示上一年的地区预赛未能出线。

ACM/ICPC大赛简介ACM/ICPC (ACM International Collegiate Programming Contest, 国际大学生程序设计竞赛)是由国际计算机界历史悠久、颇具权威性的组织ACM(Association for Computing Machinery,国际计算机协会)主办的,是世界上公认的规模最大、水平最高的国际大学生程序设计竞赛,是一项旨在展示大学生创新能力、团队精神和在压力下编写程序、分析和解决问题能力的年度竞赛。

其目的旨在使大学生运用计算机来充分展示自己分析问题和解决问题的能力。

该项竞赛从1970年至今已举办了34届,受到国际各知名大学的普遍重视,并受到全世界各著名计算机公司的高度关注,是信息企业与世界顶尖计算机人才对话的最好机会。

ACM国际大学生程序设计竞赛已成为世界各国大学生最具影响力的国际计算机类的赛事,是广大爱好计算机编程的大学生展示才华的舞台,是各个大学计算机教育成果的直接体现。

在过去十几年中,世界著名信息企业APPLE、AT&T、MICROSOFT和IBM分别担任了竞赛的赞助商。

中国大陆高校从1996年开始参加ACM/ICPC亚洲预赛,主要是各个重点院校。

该项竞赛分为区域预赛和国际决赛两个阶段进行,各预赛区第一名自动获得参加世界决赛的资格,世界决赛安排在每年的3~4月举行,而区域预赛安排在上一年的9~12月在各大洲举行。

ACM/ICPC的区域预赛是规模很大、范围很广的赛事,但历届河南省各高校却极少组队参加,为了提升和检验河南省计算机教育水平,河南省计算机学会从2008年开始,在河南省推广开展ACM国际大学生程序设计竞赛,为广大的爱好计算机编程的大学生提供展示才华的舞台,为河南省各高校组队参加ACM/ICPC的区域预赛的提供实战的场地,并以此为契机推动河南省计算机教育水平的提高。

2018ACM-ICPC南京区域赛题解

2018ACM-ICPC南京区域赛题解

2018ACM-ICPC南京区域赛题解解题过程开场开A,A题shl看错题意,被制⽌。

然后开始⼿推A,此时byf看错E题题意,开始上机。

推出A的规律后,shl看了E题,发现题意读错。

写完A题,忘记判断N=0的情况,WA+1。

过了A后,shl重新写E,lfw开始开J题,E题过不了样例,lfw多次起⽴让shl调试,然后shl拿到E的⼀⾎,lfw之后过了J。

byf开始开I题,shl⼝胡出M做法,然后lfw和shl⼀起推G题。

byf过了I题后,shl推出G题,byf去写。

然后lfw开始计算⼏何,经过查错后过掉,然后shl开始开M题,过掉后还剩最后半⼩时,⽆题可做。

最后罚时很多,因为前期签到题过得太慢,A题40+分钟才过,J题1⼩时40分钟才过。

题解A - Adrien and Austin题解:给你n给⽯头,下标依次为1~n,然后两个⼈轮流取⽯头,每次取1~k个连续下标的⽯头,最后不能取得输掉⽐赛。

问你谁会获胜。

找规律,⾸先,n==0时,第⼀个⼈必败。

k==1时,n为奇数时先⼿必胜。

k>1时,先⼿必胜.参考代码:1 #include<bits/stdc++.h>2using namespace std;3 typedef long long LL;4const int mod=1e9+7;5 LL quick_pow(LL a,LL b)6 {7 LL ans=1;8while(b)9 {10if(b&1) ans=ans*a%mod;11 a=a*a%mod;12 b>>=1;13 }14return ans;15 }16int main()17 {18int t;19 scanf("%d",&t);20int l24=quick_pow(24,mod-2);21while(t--)22 {23int n;24 scanf("%d",&n);25 LL ans=1;26 ans=ans*n%mod;27 ans=ans*(n+1)%mod;28 ans=ans*(n+2)%mod;29 ans=ans*(n+3)%mod;30 ans=ans*l24%mod;31 printf("%lld\n",ans);32 }33 }View CodeB - TournamentUnsolved.C - Cherry and ChocolateUnsolved.D - Country Meow队友写的.题解:https:///liufengwei1/article/details/89303612参考代码:1 #include<bits/stdc++.h>2#define maxl 1103#define eps 1e-84struct point5 {6double x,y,z;7 point(double a=0,double b=0,double c=0)9 x=a;y=b;z=c;10 }11 };1213int npoint,nouter;14 point pt[maxl],outer[4],res;15double radius,tmp,ans;1617 inline double dist(point p1,point p2)18 {19double dx=p1.x-p2.x,dy=p1.y-p2.y,dz=p1.z-p2.z; 20return (dx*dx+dy*dy+dz*dz);21 }2223 inline double dot(point p1,point p2)24 {25return p1.x*p2.x+p1.y*p2.y+p1.z*p2.z;26 }2728 inline void ball()29 {30 point q[3];double m[3][3],sol[3],L[3],det;31int i,j;32 res.x=res.y=res.z=radius=0;33switch(nouter)34 {35case1: res=outer[0];break;36case2:37 res.x=(outer[0].x+outer[1].x)/2;38 res.y=(outer[0].y+outer[1].y)/2;39 res.z=(outer[0].z+outer[1].z)/2;40 radius=dist(res,outer[0]);41break;42case3:43for(int i=0;i<2;i++)44 {45 q[i].x=outer[i+1].x-outer[0].x;46 q[i].y=outer[i+1].y-outer[0].y;47 q[i].z=outer[i+1].z-outer[0].z;48 }49for(int i=0;i<2;i++)50for(int j=0;j<2;j++)51 m[i][j]=dot(q[i],q[j])*2;52for(int i=0;i<2;i++)53 sol[i]=dot(q[i],q[i]);54if(fabs(det=m[0][0]*m[1][1]-m[0][1]*m[1][0])<eps) 55return;56 L[0]=(sol[0]*m[1][1]-sol[1]*m[0][1])/det;57 L[1]=(sol[1]*m[0][0]-sol[0]*m[1][0])/det;58 res.x=outer[0].x+q[0].x*L[0]+q[1].x*L[1];59 res.y=outer[0].y+q[0].y*L[0]+q[1].y*L[1];60 res.z=outer[0].z+q[0].z*L[0]+q[1].z*L[1];61 radius=dist(res,outer[0]);62break;63case4:64for(int i=0;i<3;i++)65 {66 q[i].x=outer[i+1].x-outer[0].x;67 q[i].y=outer[i+1].y-outer[0].y;68 q[i].z=outer[i+1].z-outer[0].z;69 sol[i]=dot(q[i],q[i]);70 }71for(int i=0;i<3;i++)72for(int j=0;j<3;j++)73 m[i][j]=dot(q[i],q[j])*2;74 det=m[0][0]*m[1][1]*m[2][2]75 + m[0][1]*m[1][2]*m[2][0]76 + m[0][2]*m[2][1]*m[1][0]77 - m[0][2]*m[1][1]*m[2][0]78 - m[0][1]*m[1][0]*m[2][2]79 - m[0][0]*m[1][2]*m[2][1];80if(fabs(det)<eps) return;81for(int j=0;j<3;j++)82 {83for(int i=0;i<3;i++)84 m[i][j]=sol[i];85 L[j]=(m[0][0]*m[1][1]*m[2][2]86 +m[0][1]*m[1][2]*m[2][0]87 +m[0][2]*m[2][1]*m[1][0]88 -m[0][2]*m[1][1]*m[2][0]89 -m[0][1]*m[1][0]*m[2][2]90 -m[0][0]*m[1][2]*m[2][1])/det;91for(int i=0;i<3;i++)92 m[i][j]=dot(q[i],q[j])*2;93 }94 res=outer[0];95for(int i=0;i<3;i++)96 {98 res.y+=q[i].y*L[i];99 res.z+=q[i].z*L[i];100 }101 radius=dist(res,outer[0]);102 }103 }104105 inline void minball(int n)106 {107 ball();108if(nouter<4)109for(int i=0;i<n;i++)110if(dist(res,pt[i])-radius>eps)111 {112 outer[nouter]=pt[i];113 ++nouter;114 minball(i);115 --nouter;116if(i>0)117 {118 point Tt=pt[i];119 memmove(&pt[1],&pt[0],sizeof(point)*i);120 pt[0]=Tt;121 }122 }123 }124125 inline double smallest_ball()126 {127 radius=-1;128for(int i=0;i<npoint;i++)129if(dist(res,pt[i])-radius>eps)130 {131 nouter=1;132 outer[0]=pt[i];133 minball(i);134 }135return sqrt(radius);136 }137138 inline void prework()139 {140for(int i=0;i<npoint;i++)141 scanf("%lf%lf%lf",&pt[i].x,&pt[i].y,&pt[i].z);142 }143144 inline void mainwork()145 {146 ans=smallest_ball();147 }148149 inline void print()150 {151 printf("%.5f\n",ans);152 }153154int main()155 {156while(~scanf("%d",&npoint))157 {158 prework();159 mainwork();160 print();161 }162return0;163 }View CodeE - Eva and Euro coins题解:给你两个01串,然后连续k个0可以翻转为1,连续k个1可以翻转为0.问你这两个01串是否可以变成相同的串。

  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
相关文档
最新文档