NOIP2009高中复赛试题

合集下载

金华一中信息学奥林匹克联赛(NOIP2009)复赛模拟试题(汇总

金华一中信息学奥林匹克联赛(NOIP2009)复赛模拟试题(汇总

金华一中信息学奥林匹克联赛(NOIP2009)复赛模拟试题(三)一、题目概览中文题目名称遥控车车展拉力赛舞台设置英文题目名称car exhibit rally stage 可执行文件名car exhibit rally stage 输入文件名car.in exhibit.in rally.in stage.in 输出文件名car.out exhibit.out rally.out stage.out1秒1秒1秒1秒每个测试点时限测试点数目10 10 10 1010 10 10 10每个测试点分值比较方式全文比较全文比较全文比较全文比较二、运行内存限制运行内存上限512 M512 M512 M512 M第一题:遥控车【题目描述】平平带着韵韵来到了游乐园,看到了n辆漂亮的遥控车,每辆车上都有一个唯一的名字name[i]。

韵韵早就迫不及待地想玩名字是s的遥控车。

可是韵韵毕竟还小,她想象的名字可能是一辆车名字的前缀(也就是说能确定一个i,使s是name[i]的前缀),这时她就能玩第i辆车;或者是一个无中生有的名字,即s不是任何一辆车名字的前缀,这时候她什么也不能玩。

你需要完成下面的任务:1.韵韵想了m个她想要的名字,请告诉她能玩多少次。

2.由于管理员粗心的操作,导致每辆车的摆放位置都可能出现微小的差错,原来第i辆车现在的位置可能是i-1、i、i+1中的任意一个(第1辆车的位置不可能是0,第n辆车的位置不可能是n+1)。

请你计算出共有多少种可能的排列。

注:数据保证当s是name[i]的前缀时,i是唯一确定的。

一辆车可以玩多次。

【输入格式】第一行是2个正整数n、m。

接下来n行,每行1个字符串name[i],表示第i辆车的名字。

接下来m行,每行1个字符串s,表示韵韵想要的名字。

【输出格式】第一行输出韵韵能玩的次数。

第二行输出共有多少种可能的排列。

【输入样例】4 4AbcdDeFAAaaBcccAbAAAbCaBcc【输出样例】35对于题目涉及到的字符串严格区分大小写,且长度小于255。

2009年第26届全国中学生高中物理竞赛复赛试题(Word版,含答案)

2009年第26届全国中学生高中物理竞赛复赛试题(Word版,含答案)

第26届全国中学生物理竞赛复赛试卷一、填空(问答)题(每题5分,共25分)1.有人设想了一种静电场:电场的方向都垂直于纸面并指向纸里,电场强度的大小自左向右逐渐增大,如图所示。

这种分布的静电场是否可能存在?试述理由。

2.海尔-波普彗星轨道是长轴非常大的椭圆,近日点到太阳中心的距离为0.914天文单位(1天文单位等于地日间的平均距离),则其近日点速率的上限与地球公转(轨道可视为圆周)速率之比约为(保留2位有效数字) 。

3.用测电笔接触市电相线,即使赤脚站在地上也不会触电,原因是 ;另一方面,即使穿绝缘性能良好的电工鞋操作,测电笔仍会发亮,原因是。

4.在图示的复杂络中,所有电源的电动势均为E 0,所有电阻器的电阻值均为R 0,所有电容器的电容均为C 0,则图示电容器A 极板上的电荷量为 。

5.如图,给静止在水平粗糙地面上的木块一初速度,使之开始运动。

一学生利用角动量定理来考察此木块以后的运动过程:“把参考点设于如图所示的地面上一点O ,此时摩擦力f 的力矩为0,从而地面木块的角动量将守恒,这样木块将不减速而作匀速运动。

”请指出上述推理的错误,并给出正确的解释:。

二、(20分)图示正方形轻质刚性水平桌面由四条完全相同的轻质细桌腿1、2、3、4支撑于桌角A 、B、C 、D 处,桌腿竖直立在水平粗糙刚性地面上。

已知桌腿受力后将产生弹性微小形变。

现于桌面中心点O 至角A 的连线OA 上某点P 施加一竖直向下的力F ,令c OAOP=,求桌面对桌腿1的压力F 1。

三、(15分)1.一质量为m 的小球与一劲度系数为k 的弹簧相连组成一体系,置于光滑水平桌面上,弹簧的另一端与固定墙面相连,小球做一维自由振动。

试问在一沿此弹簧长度方向以速度u 作匀速运动的参考系里观察,此体系的机械能是否守恒,并说明理由。

2.若不考虑太阳和其他星体的作用,则地球-月球系统可看成孤立系统。

若把地球和月球都看作是质量均匀分布的球体,它们的质量分别为M 和m ,月心-地心间的距离为R ,万有引力恒量为G 。

Noip2009复赛普及组

Noip2009复赛普及组

Noip2009复赛普及组1.多项式输出(poly.pas/c/cpp)【问题描述】给出一个一元多项式各项的次数和系数,请按照如下规定的格式要求输出该多项式:1. 多项式中自变量为x,从左到右按照次数递减顺序给出多项式。

2. 多项式中只包含系数不为0 的项。

3. 如果多项式n 次项系数为正,则多项式开头不出现“+”号,如果多项式n 次项系数为负,则多项式以“-”号开头。

4. 对于不是最高次的项,以“+”号或者“-”号连接此项与前一项,分别表示此项系数为正或者系数为负。

紧跟一个正整数,表示此项系数的绝对值(如果一个高于0 次的项,其系数的绝对值为1,则无需输出1)。

如果x 的指数大于1,则接下来紧跟的指数部分的形式为“x^b”,其中b 为x 的指数;如果x 的指数为1,则接下来紧跟的指数部分形式为“x”;如果x 的指数为0,则仅需输出系数即可。

5. 多项式中,多项式的开头、结尾不含多余的空格。

【输入】输入文件名为poly.in,共有2 行第一行1 个整数,n,表示一元多项式的次数。

第二行有n+1 个整数,其中第i 个整数表示第n-i+1 次项的系数,每两个整数之间用空格隔开。

【输出】输出文件poly.out 共1 行,按题目所述格式输出多项式。

【输入输出样例1】poly.in5100 -1 1 -3 0 10poly.out100x^5-x^4+x^3-3x^2+10【输入输出样例2】poly.in3-50 0 0 1poly.out-50x^3+1【数据范围】1 ≤n ≤100,多项式各次项系数的绝对值均不超过100。

(score.pas/c/cpp)【问题描述】世博会志愿者的选拔工作正在A 市如火如荼的进行。

为了选拔最合适的人才,A 市对所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试。

面试分数线根据计划录取人数的150%划定,即如果计划录取m名志愿者,则面试分数线为排名第m*150% (向下取整)名的选手的分数,而最终进入面试的选手为笔试成绩不低于面试分数线的所有选手。

ioi2009

ioi2009

21-st International Olympiad In Informatics TASKS AND SOLUTIONSAugust8-15,2009Plovdiv,Bulgaria221-st International Olympiad In Informatics Day0Task0.1AREAA large agricultural corporation is undertaking an audit of its N land proper-ties.As afirst step,they would like to know the total area of their properties. Each property has a rectangular shape,and no two properties overlap.You realize that this is a trivial calculation,but you understand that you need to solve this problem in order to test your ability to properly handle large amounts of data and large numbers under the IOI2009contest system.TASKWrite a program that,given the dimensions of the N land properties,deter-mines the sum of their areas.CONSTRAINTS1≤N≤500000–The number of land properties1≤A k,B k≤20000–The lengths of the sides of property kINPUTYour program should read from the standard input the following data:•Thefirst line contains a single integer:the number of properties N.•The next N lines describe the properties,one property per line.The k th of these lines describes property number k and it contains two integers separated by a single space:the lengths of the sides of the property A k and B k measured in meters.OUTPUTYour program should write to the standard output a single line containing a single integer:the total area of all properties,measured in square meters.IMPORTANT NOTEThefinal answer may notfit in32bits.You have to use a64-bit data type, such as long long in C/C++or int64in Pascal,in order to compute and store the answer in a single variable.Please see the technical info sheet for details.2009August8-15,Plovdiv,Bulgaria3 EXAMPLESample Input Sample Output408315255631Task0.2HILL(proposed by Iskren Chernev)An extraterrestrial team of contestants,known as the aliens,is coming to Plov-div for the IOI.They would like to land theirflying saucer on one of Plovdivs hills, but they have no map of the city,so they need to use their laser scanner tofind a hill.The aliens have divided the city into a grid of N by M cells,and each time they use the scanner they can determine the altitude of a single cell.Their scanner is so precise that no two cells would ever have the same altitude.The aliens define a hill as a cell that has higher altitude than all of its adjacent cells.Two cells are considered adjacent if they share a side.Thus typically each cell has four adjacent ones,with the cells on the border of the grid being the exception(they have less than four adjacent cells).The aliens have time for only3050scans before their saucer hits the ground. Help the aliensfind a hill before they run out of time.TASKWrite a program that,given the dimensions of the grid,interactively uses the scanner to determine the location of a hill,while doing no more than3050scans in total.CONSTRAINTS1≤N,M≤1000–The dimensions of the grid1≤A x,y≤2000000000–The altitude of cell<x,y>INPUTYour program should read from the standard input a single line with two integers N and M,separated by a single space.421-st International Olympiad In InformaticsINTERACTIONAfter reading the input data,your program should start using the laser scanner. Each time you want to use the scanner for a cell with coordinates x and y(1≤x≤N,1≤y≤M),you should print a single line on the standard output,containing three integers separated by single spaces:0(a literal zero),x and y,in this order.After submitting your request to the scanner,you should read a single line on the standard input.It will contain a single integer:the altitude of the cell with coordinates x and y in some alien units.OUTPUTWhen your program has determined the location of a hill<a,b>(1≤a≤N, 1≤b≤M),you should report your answer by printing a single line on the standard output,containing three integers separated by single spaces:1(a literal one),a and b,in this order.IMPORTANT NOTE:In order to interact properly with the scanner,your program needs toflush the standard output after every line that you print on the standard output.Please see the technical info sheet for instructions on how to do this properly.EXAMPLESample Input Sample Output323 4 1 7 6011[flush stdout/output] 021[flush stdout/output] 031[flush stdout/output] 012[flush stdout/output] 022[flush stdout/output] 112[flush stdout/output]2009August8-15,Plovdiv,Bulgaria50.3MUSEUM(proposed by Boyko Bantchev)The Plovdiv Museum of Modern Art has an exhibition of ancient Thracian vases.There are N vases total.Thefirst one is a miniature of height1centimeter. The second one is of height2centimeters;the third one is3centimeters tall and so on until the N th vase,which is N centimeters tall.Since this a modern art museum and the vases are ancient,the organizers of the exhibition would like to add a modern,chaotic twist to the presentation of the vases.They have decided to arrange the vases in a line that satisfies the following condition:For any three vases A,B and C,such that B s height is exactly the average of the heights of A and C,either B must be positioned to the left of bothA and C,orB must be positioned to the right of both A and C(in other words,B may not be positioned between A andC on the line).TASKWrite a program that,given the number of vases,determines a linear arrange-ment of the vases that satisfies the condition of the exhibition organizers.CONSTRAINTS1≤N≤2000–The number of vasesINPUTYou are givenfive problem instances in thefiles museum.1.in to museum.5.in. Eachfile contains a single line,which in turn contains a single integer:the number of vases N.OUTPUTYou are to submitfive outputfiles,named museum.1.out to museum.5.out, each corresponding to one of the inputfiles.Thefiles should be in the following format:There should be N lines,each representing the N positions in the arrangement, in order from left to right.Line k should contain a single integer H k,the height of the vase you decided to place on position k.All N heights should be distinct integers between1and N inclusive.621-st International Olympiad In InformaticsEXAMPLESample Input Sample Outputmuseum.0.in museum.0.out531254In the above arrangement,3is neither between2and4,nor is it between1 and5.Also,2is not between1and3,and4is not between3and5.Thus,it satisfies the condition of the exhibition organizers.TECHNICAL INFO SHEET(day0)These pages contain helpful information on how to avoid slow input/output performance with C++streams(cin/cout),how to use64-bit data types(vari-ables)and how toflush the output for interactive tasks.Slow Input/Output with C++StreamsWhen solving tasks with very large amounts of input/output data,you may notice that C++programs using the cin and cout streams are much slower than equivalent programs that use the scanf and printf functions for input and output processing.Thus,if you are using the cin/cout streams we strongly recommend that you switch to using scanf/printf instead.However,if you still want to use cin /cout,we recommend adding the following line at the beginning of your program: ios::sync_with_stdio(false);and also making sure that you never use endl,but use\n instead.Please note,however,that including ios::sync_with_stdio(false)breaks the synchrony between cin/cout and scanf/printf,so if you are using this,you should never mix usage of cin and scanf,nor mix cout and printf.64-bit Data TypesFor some tasks you may need to deal with numbers too large tofit in32bits. In these cases,you would have to use a64-bit integer data type,such as long long2009August8-15,Plovdiv,Bulgaria7 in C/C++or int64in Pascal.Here is some sample code that illustrates the usage of these data types:C/C++int main(void){long long varname;scanf("%lld",&varname);//Do something with the varname variableprintf("%lld\n",varname);return0;}Pascalvarvarname:Int64;beginread(varname);{Do something with the varname variable}writeln(varname);end.Flushing the OutputWhenever you solve an interactive task,you always need toflush the buffer of your output after every new line printed on the output.Here is some code to illustrate how to do this under C,C++and Pascal:C or C++with scanf/printffflush(stdout);C++with cin/coutcout<<flush;Pascalflush(output);821-st International Olympiad In Informatics Task Overview Sheet(Day0)Area Hill Museum Type Batch Interactive Output-onlyDetailed Feedback Full Partial NoneTime Limit(per test case)2seconds1second Not ApplicableMemory Limit(per test case)32MB64MB Not ApplicablePoints100100100NOTE:On the actual competition there will be four problems on each day.We have only three problems here because the practice contest is shorter in duration and because there are only three possible task types.2009August8-15,Plovdiv,Bulgaria9 Day11.1ARCHERY(proposed by Velin Tzanov)An archery tournament is held according to the following rules.There are N targets arranged in a line and numbered from1to N inclusive according to their place on the line(the leftmost target being target1,and the rightmost target being target N).There are also2∗N archers.At any time during the tournament,there are two archers on each target.Every round of the tournament goes according to the following procedure:The two archers on each target compete with each other and determine a winner and a loser between them.Then all archers are rearranged as follows: The winners on targets2to N inclusive move to the target on their left(i.e., targets1to N−1respectively).The losers on targets2to N inclusive,as well as the winner on target1,remain on the same target.The loser on target1moves to target N.The tournament continues for R rounds,with the number of rounds being at least as many as the number of archers(i.e.,R≥2∗N).You are the only archer to arrive for the tournament exactly on time.All other 2∗N−1archers have arrived early and are already standing in a line.What you have to do now is to insert yourself somewhere into the line amongst them.You know that after you take your position,the two leftmost archers in the line will start the tournament on target1,the next two will start on target2and so on, with the two rightmost archers starting on target N.All the2∗N archers in the tournament(including yourself)are ranked by skill,where a smaller rank corresponds to better skill.No two archers have the same rank.Also,whenever two archers compete,the one with the smaller rank will always win.Knowing how skilled each of your competitors is,you want to insert yourself in such a way as to ensure that you willfinish the tournament on a target with as small a number as possible.If there are multiple ways to do this,you prefer the one that starts at a target with as large a number as possible.TASKWrite a program that,given the ranks of all archers,including yourself,as well as your competitors arrangement on the line,determines on which target you1021-st International Olympiad In Informaticsshould start the tournament,so that you can achieve your goals as defined above.CONSTRAINTS1≤N≤200000–The number of targets;also equal to half the number of archers2∗N≤R≤1000000000–The number of tournament rounds1≤S k≤2∗N–The rank of archer kINPUTYour program must read from standard input the following data:Thefirst line contains the integers N and R,separated by a space.The next2∗N lines list the ranks of the archers.Thefirst of these lines contains your rank.The rest of these lines contain the ranks of the other archers, one archer per line,in the order in which they have arranged themselves(from left to right).Each of these2∗N lines contains a single integer between1and2∗N inclusive.A rank of1is the best and a rank of2∗N is the worst.No two archers have the same rank.OUTPUTYour program must write to standard output a single line containing a single integer between1and N inclusive:the number of the target on which you will start the tournament.GRADINGFor a number of tests,worth a total of60points,N will not exceed5000. Also,for some of these tests,worth a total of20points,N will not exceed200.EXAMPLESSample Input Smaple Output348742658132009August8-15,Plovdiv,Bulgaria11 You are the second worst archer.If you start on target1,you will then go to target4and stay there until the end.If you start on target2or4,you will just stay there for the whole tournament.If you start on target3,you will beat the worst archer and then move to target2and stay there.Sample Input Smaple Output24921583476You are the second best archer.The best one is already on target1and will stay there for the whole duration of the tournament.Thus,no matter where you start,you will always move from your target,going through all targets from4to 1over and over again.In order for you to end on target1after9transitions,you have to start on target2.1.2HIRING(proposed by Velin Tzanov)You have to hire workers for a construction project.There are N candidates applying for the job,numbered from1to N inclusive.Each candidate k requires that if he is hired,he must be paid at least S k dollars.Also,each candidate k has a qualification level Q k.The regulations of the construction industry require that you pay your workers in proportion to their qualification level,relative to each other.For example,if you hire two workers A and B,and Q A=3∗Q B,then you have to pay worker A exactly three times as much as you pay worker B.You are allowed to pay your workers non-integer amounts of money.This even includes quantities that cannot be written with afinite number of digits in decimal form, such as a third or a sixth of a dollar.You have W dollars at hand and you want to hire as many workers as possible. You decide whom to hire and how much to pay them,but you have to meet the minimum salary requirements of those you choose to hire,and you have to obey the industry regulations.You also have tofit within your budget of W dollars.1221-st International Olympiad In Informatics The nature of your project is such that the qualification level is completely irrelevant,so you are only interested in maximizing the number of workers without regard to their qualification level.However,if there is more than one way to achieve this,then you want to select the one where the total amount of money you have to pay your workers is as small as possible.In case there is more than one way to achieve this,then you are indifferent among these ways and you would be satisfied with any one of them.TASKWrite a program that,given the different salary requirements and qualification levels of the candidates,as well as the amount of money you have,determines which candidates you should hire.You must hire as many of them as possible and you must do so with as little money as possible,while complying with the industry regulations specified above.CONSTRAINTS1≤N≤500000–The number of candidates1≤S k≤20000–The minimum salary requirement of candidate k1≤Q k≤20000–The qualification level of candidate k1≤W≤10000000000–The amount of money available to youIMPORTANT NOTEThe maximum value of W does notfit in32bits.You have to use a64-bit data type,such as long long in C/C++or int64in Pascal,in order to store the value of W in a single variable.Please see the technical info sheet for details.INPUTYour program must read from standard input the following data:•Thefirst line contains the integers N and W,separated by a space.•The next N lines describe the candidates,one candidate per line.The k th of these lines describes candidate number k and it contains the integers S k and Q k, separated by a space.OUTPUTYour program must write to standard output the following data:•Thefirst line must contain a single integer H,the number of workers that you hire.•The next H lines must list the identifying numbers of the candidates you choose to hire(each of them a different number between1and N),one per line, in any order.2009August8-15,Plovdiv,Bulgaria13GRADINGFor any given test case,you will receive full points if your choice of candidates enables you to achieve all of your goals,while satisfying all constraints.If you produce an outputfile with a correctfirst line(i.e.,a correct value of H),but which does not meet the above description,you will receive50%of the points for that test case.The latter will be the case even if the outputfile is not properly formatted,as long as thefirst line is correct.For a number of tests,worth a total of50points,N will not exceed5000.EXAMPLESSample Input Sample Output4100 51000 10100 810 2012 2 3The only combination for which you can afford to hire two workers and still meet all the constraints is if you select workers2and3.You can pay them80and 8dollars respectively and thusfit in your budget of100.Sample Input Sample Output34 12 13 133 1 2 3Here you can afford to hire all three workers.You pay1dollar to worker1and 1.50dollars each to workers2and3,and you manage to hire everyone with the4 dollars that you have.Sample Input Sample Output340 101 102 1032 2 3Here you cannot afford to hire all three workers,as it would cost you60dollars, but you can afford to hire any two of them.You choose to hire workers2and31421-st International Olympiad In Informatics because they would cost you the smallest sum of money,compared to the other two-worker combinations.You can pay10dollars to worker2and15dollars to worker3for a total of25dollars.If you were to hire workers1and2you would have to pay them at least10and20dollars respectively.If you were to hire1and 3,then you would have to pay them at least10and30dollars respectively.Task1.3POI(proposed by Carl Hultquist)The local Plovdiv Olympiad in Informatics(POI)was held according to the following unusual rules.There were N contestants and T tasks.Each task was graded with only one test case,therefore for every task and every contestant there were only two possibilities:either the contestant solved the task,or the contestant did not solve the task.There was no partial scoring on any task.The number of points assigned to each task was determined after the contest and was equal to the number of contestants that did not solve the task.The score of each contestant was equal to the sum of points assigned to the tasks solved by that contestant.Philip participated in the contest,but he is confused by the complicated scoring rules,and now he is staring at the results,unable to determine his place in the final standings.Help Philip by writing a program that calculates his score and his ranking.Before the contest,the contestants were assigned unique IDs from1to N inclu-sive.Philips ID was P.Thefinal standings of the competition list the contestants in descending order of their scores.In case of a tie,among the tied contestants, those who have solved more tasks will be listed ahead of those who have solved fewer tasks.In case of a tie by this criterion as well,the contestants with equal results will be listed in ascending order of their IDs.TASKWrite a program that,given which problems were solved by which contestant, determines Philips score and his rank in thefinal standings.CONSTRAINTS1≤N≤2000–The number of contestants1≤T≤2000–The number of tasks1≤P≤N–Philips ID2009August8-15,Plovdiv,Bulgaria15INPUTYour program must read from standard input the following data:•Thefirst line contains the integers N,T and P,separated by individual spaces.•The next N lines describe which tasks were solved by which contestant.The k th of these lines describes which tasks were solved by the contestant with ID k.Each such line contains T integers,separated by spaces.Thefirst of these numbers denotes whether or not contestant k solved thefirst task.The second number denotes the same for the second task and so on.These T numbers are all either0or1,where1means that contestant k solved the corresponding task,and 0means that he or she did not solve it.OUTPUTYour program must write to standard output a single line with two integers separated by a single space.First,the score that Philip got on the POI competi-tion.Second,Philips rank in thefinal standings.The rank is an integer between1 and N inclusive,with1denoting the contestant listed at the top(i.e.,a contestant who has the highest score)and N to the one listed at the bottom(i.e.,a contestant with the lowest score).GRADINGFor a number of tests,worth a total of35points,no other contestant will have the same score as Philip.EXAMPLESample Input Sample Output32532001110100110110Thefirst problem was unsolved by only one contestant,so it is worth1point. The second problem was unsolved by two contestants,so it is worth2points.The third problem was unsolved by four contestants,so it is worth4points.Thus the first contestant has a score of4;the second contestant(Philip),the fourth and the1621-st International Olympiad In Informatics fifth contestants all have a score of3;and the third contestant has a score of1. Contestants2,4and5are all tied according to thefirst tie-break rule(number of problems solved),and according to the second tie-break rule(smaller ID)Philip ranks before the others.Thus Philips rank in thefinal standings is2.He is only behind the contestant with ID1.Task1.4RAISINS(proposed by Emil Kelevedjiev)Plovdiv’s famous master chocolatier Bonny needs to cut a slab of chocolate with raisins.The chocolate is a rectangular block of identical square pieces.The pieces are aligned with the edges of the chocolate,and they are arranged in N rows and M columns,for a total of N∗M pieces.Each piece has one or more raisins on it,and no raisins lie between or across pieces.Initially,the chocolate is one single,monolithic block.Bonny needs to cut it into smaller and smaller blocks untilfinally she has cut the chocolate down to its N∗M individual pieces.As Bonny is very busy,she needs the help of her assistant, Sly Peter,to do the cutting.Peter only makes straight line,end-to-end cuts and he wants to be paid for every single cut he makes.Bonny has no money at hand, but she has plenty of raisins left over,so she offers to pay Peter in raisins.Sly Peter agrees to this arrangement,but under the following condition:every time he cuts a given block of chocolate into two smaller blocks,he has to be paid as many raisins as there are on the block he was given.2009August8-15,Plovdiv,Bulgaria17 Bonny wants to pay Peter as little as possible.She knows how many raisins there are on each of the N∗M pieces.She can choose the order in which she gives Peter any remaining blocks,and she can also tell Peter what cuts to make (horizontal or vertical)and where exactly to make them.Help Bonny decide how to cut the chocolate into individual pieces,so that she pays Sly Peter as few raisins as possible.TASKWrite a program that,given the number of raisins on each of the individual pieces,determines the minimum number of raisins that Bonny will have to pay Sly Peter.CONSTRAINTS1≤N,M≤50–The number of pieces on each side of the chocolate1≤R k,p≤1000–The number of raisins on the piece in the k th row andthe p th columnINPUTYour program must read from standard input the following data:•Thefirst line contains the integers N and M,separated by a single space.•The next N lines describe how many raisins there are on each piece of the chocolate.The k th of these N lines describes the k th row of the chocolate.Each such line contains M integers separated by single spaces.The integers describe the pieces on the corresponding row in order from left to right.The p th integer on the k th line(among these N lines)tells you how many raisins are on the piece in the k th row and the p th column.OUTPUTYour program must write to standard output a single line containing a single integer:the minimum possible number of raisins that Bonny would have to pay Sly PeterGRADINGFor a number of tests,worth a total of25points,N and M will not exceed7.1821-st International Olympiad In Informatics EXAMPLESample Input Sample Output2327577195One possible way(out of many)to achieve a cost of77is as follows:Thefirst cut that Bonny asks Peter to make separates the third column from the rest of the chocolate.Bonny needs to pay Peter29raisins for this.Then Bonny gives Peter the smaller of the two blocks:the one that has two pieces with5raisins each,and asks Peter to cut the block in two in exchange for 10raisins.After this,Bonny gives Peter the largest remaining block:the one having pieces with2,7,1and9raisins respectively.Bonny asks Peter to cut it horizontally, separating thefirst and the second row and pays him19raisins.Following this,Bonny gives Peter the top-left block,paying9raisins.Finally, Bonny asks Peter to split the bottom-left block,paying10raisins.The total cost to Bonny is29+10+19+9+10=77raisins.No other cutting arrangement can get the chocolate cut into its6pieces at a smaller cost.2009August8-15,Plovdiv,Bulgaria19 TECHNICAL INFO SHEET(day1)These pages contain helpful information on how to avoid slow input/output performance with C++streams(cin/cout),how to use64-bit data types(vari-ables)and how toflush the output for interactive tasks.They also include reference for what options are given to the compilers and what stack limitations are in place.Slow Input/Output with C++StreamsWhen solving tasks with very large amounts of input/output data,you may notice that C++programs using the cin and cout streams are much slower than equivalent programs that use the scanf and printf functions for input and output processing.Thus,if you are using the cin/cout streams we strongly recommend that you switch to using scanf/printf instead.However,if you still want to use cin /cout,we recommend adding the following line at the beginning of your program:ios::sync_with_stdio(false);and also making sure that you never use endl,but use\n instead.Please note,however,that including ios::sync_with_stdio(false)breaks the synchrony between cin/cout and scanf/printf,so if you are using this,you should never mix usage of cin and scanf,nor mix cout and printf.64-bit Data TypesFor some tasks you may need to deal with numbers too large tofit in32bits. In these cases,you would have to use a64-bit integer data type,such as long long in C/C++or int64in Pascal.Here is some sample code that illustrates the usage of these data types:C/C++int main(void){long long varname;scanf("%lld",&varname);//Do something with the varname variableprintf("%lld\n",varname);return0;}2021-st International Olympiad In Informatics Pascalvarvarname:Int64;beginread(varname);{Do something with the varname variable}writeln(varname);end.Flushing the OutputWhenever you solve an interactive task,you always need toflush the buffer of your output after every new line printed on the output.Here is some code to illustrate how to do this under C,C++and Pascal:C or C++with scanf/printffflush(stdout);C++with cin/coutcout<<flush;Pascalflush(output);Compiler OptionsThe following commands will be used to compile solutions of batch and inter-active tasks(say the task name is abc):Cgcc-o abc abc.c-std=gnu99-O2-s-static-lm-x cC++g++-o abc abc.cpp-O2-s-static-lm-x c++Pascalfpc-O2-XS-Sg abc.pas。

2009noip提高组复赛题解

2009noip提高组复赛题解

NOIP2009提高組複賽試題解題報告NOIP2009提高組複賽試題解題報告一、潛伏者(spy)問題描述:給出密文及對應明文,求字母的對應關係並破譯密文。

解題思路:水題。

只需把字符串掃描一遍,邊掃邊增加對應關係。

並判斷既有之對應關係是否正確。

最後判斷是否每一個字母都有其對應字母。

需要注意不僅要判斷是否每一個密文字母都存在惟一對應的明文字母,還要判斷是否每一個明文字母都存在惟一對應的密文字母。

(去年我沒判斷這個,所以測試點三WA了,九十分)最後若失敗輸出“Failed”,否則按照對應字母輸出即可。

建議時間:15-25分鐘題很簡單,就是要考慮全面一些,第一題的分不能錯過。

盡量多調試一下。

二、Hankson的趣味題題目描述:已知x和a0的最大公約數是a1,x和b0的最小公倍數是b1。

求x的解的個數。

解題思路:算法一:最簡單的方式是枚舉,x從a1取到b1,然後判斷x是否為解。

這種方法能得到一少半分數,因為數很大。

優化:由於x必是a1的倍數,亦必是b1的約數,所以枚舉時可以枚舉a1的倍數,判斷是否為b1的約數,然後再輾轉相除驗證解。

另外b1/2至(b1-1)之間沒必要枚舉,可去除這段區間。

(我去年這樣得到了五十分)算法二:考慮素因數的性質:若gcd(x,a0)=a1,x、a0和a1含有某一素因數p的個數分別為r、s和t,則必有t=min(r,s)。

故x含有p的個數滿足:若s=t則r>=s;若s>t則r=s;由最小公倍數亦可得到(設u、v分別為b0、b1含p的個數):若u=v則r<=v;若u<v則r=v;如此便得到了r的取值範圍,進而得到r可取值的個數。

這樣的話,就可以將a0和b1分解質因數,並對每個質因數都計算一次r的解數。

依乘法原理,將它們相乘即可得到答案。

這種方法可得到80分左右。

為了減少分解時的冗餘判斷,加快分解的速度,可以預處理出五萬以內的素數表(約五千多個)。

這樣就可以拿到滿分。

NOIP2009提高组复赛题解

NOIP2009提高组复赛题解

1、潜伏者program spy;varv: array['A'..'Z'] of boolean; p, q: array['A'..'Z'] of char; a, b: string;j: char;i: integer;procedure stop;beginwriteln('Failed');close(input);close(output);halt;end;beginassign(input, 'spy.in');reset(input);assign(output, 'spy.out'); rewrite(output);readln(a);readln(b);fillchar(v, sizeof(v), 0);for i := 1 to length(a) do beginv[a[i]] := true;p[a[i]] := b[i];q[b[i]] := a[i];end;for j := 'A' to 'Z' doif not v[j] then stop;for i := 1 to length(a) do beginif p[a[i]] <> b[i] then stop; if q[b[i]] <> a[i] then stop; end;readln(a);for i := 1 to length(a) do write(p[a[i]]);writeln;close(input);close(output);end.2、Hankson的趣味题思路1:根据最大公约数的定义,X必定为最大公约数的倍数,那么我们可以去枚举a1的倍数,然后去验证最大公约数和最小公倍数是否符合条件。

期待分数:50。

程序1:vara0,a1,b0,b1,i,j,n,k,x,tot:longint;function gcd(a,b:longint):longint;beginif b=0 then exit(a) else exit(gcd(b,a mod b));end;beginreadln(n);for k:=1 to n dobegintot:=0;readln(a0,a1,b0,b1);for i:=1 to (b1 div a1) dobeginx:=i*a1;if b1 mod x=0 thenif gcd(a0,x)=a1 thenif (b0*x) div (gcd(b0,x))=b1 then begin inc(tot); end;end;writeln(tot);end;end.思路2:根据最小公倍数和最大公约数分解质因数指数的特殊关系进行优化。

NOIP2009复赛模拟-普及组3(常州一中)

NOIP2009复赛模拟-普及组3(常州一中)

NOIP2009复赛模拟-普及组3(常州一中)3小时,400分一、游戏[问题描述]Atlantis Island沉没以前,传说中的猫老大和King是好朋友……King很喜欢赌博,这次King和老朋友猫老大多年不见,于是便邀请猫老大来玩一个游戏,猫老大应邀参加了。

King 拿出了n块黄金(0<n<10^1000002),猫老大暗自想:咋来这么多钱的……,现在King和猫老大轮流从黄金中拿走一些,每人每次拿走的块数是2的次方(例如1,2,4,8,16……)谁能拿走最后一个黄金,谁就获胜。

现在King让猫老大先拿,双方都使用最好的策略来玩的话,谁能取得胜利呢?现在请你来帮助猫老大,他能胜利吗?[输入]一行一个数n(0<n<10^1000002)。

[输出]第一行:如果King必胜则输出“King will win.”;否则输出“MaoLaoDa will win.”。

如果是猫老大必胜的话,则再在第二行输出他第一次拿的数量,输出最小值。

[样例1]atlantis.in8atlantis.outMaoLaoDa will win.2[样例2]atlantis.in3atlantis.outKing will win.二、储蓄[问题描述]光光的手上有n元钱。

光光想利用这n 元钱去储蓄,以得到更多的钱。

光光于是就每天出入银行存取款。

光光每天需要做两件事情:存款与取款。

光光先取款(如果有到期的定期),然后给出存款额与存期、利率。

存期的单位是天,利率表示总共能得到的利率,也就是取的钱=存款额*(1+利率),每次都去尾取整。

利率单位是百分之一。

如果定期到帐,则随时还到光光手中。

光光每天必须去且只能去一趟银行。

但由于光光乱来,所以有时候会出现存款没钱。

这时候需要你输出一行“ERROR”,并且省略掉这一行。

否则输出一行“OK”。

光光想要知道,他到第k天存钱之后还有多少现金在自己手中。

[输入]输入文件bank.in,包含:第1行:n和k,其中k代表光光总共跑银行的天数。

NOIP历年复赛提高组试题(2004-2013)

NOIP历年复赛提高组试题(2004-2013)

第十届全国信息学奥林匹克分区联赛(NOIP2004)复赛试题(提高组竞赛用时:3小时)1、津津的储蓄计划(Save.pas/dpr/c/cpp)【问题描述】津津的零花钱一直都是自己管理。

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

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

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

例如11月初津津手中还有83元,妈妈给了津津300元。

津津预计11月的花销是180元,那么她就会在妈妈那里存200元,自己留下183元。

到了11月月末,津津手中会剩下3元钱。

津津发现这个储蓄计划的主要风险是,存在妈妈那里的钱在年末之前不能取出。

有可能在某个月的月初,津津手中的钱加上这个月妈妈给的钱,不够这个月的原定预算。

如果出现这种情况,津津将不得不在这个月省吃俭用,压缩预算。

现在请你根据2004年1月到12月每个月津津的预算,判断会不会出现这种情况。

如果不会,计算到2004年年末,妈妈将津津平常存的钱加上20%还给津津之后,津津手中会有多少钱。

【输入文件】输入文件save.in包括12行数据,每行包含一个小于350的非负整数,分别表示1月到12月津津的预算。

【输出文件】输出文件save.out包括一行,这一行只包含一个整数。

如果储蓄计划实施过程中出现某个月钱不够用的情况,输出-X,X表示出现这种情况的第一个月;否则输出到2004年年末津津手中会有多少钱。

【样例输入1】29023028020030017034050908020060【样例输出1】-7【样例输入2】29023028020030017033050908020060【样例输出2】1580【问题描述】在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
得的内容均由大写字母‘A’-‘Z’构成(无空格等其他字符)。 2. S 国对于每个字母规定了对应的“密字”。加密的过程就是将原信息中的所有字母替
换为其对应的“密字”。 3. 每个字母只对应一个唯一的“密字”,不同的字母对应不同的“密字”。“密字”可以
和原字母相同。 例如,若规定‘A’的密字为‘A’,‘B’的密字为‘C’(其他字母及密字略),则原信 息“ABA”被加密为“ACA”。 现在,小 C 通过内线掌握了 S 国网络上发送的一条加密信息及其对应的原信息。小 C 希望能通过这条信息,破译 S 国的军用密码。小 C 的破译过程是这样的:扫描原信息,对 于原信息中的字母 x(代表任一大写字母),找到其在加密信息中的对应大写字母 y,并认为 在密码里 y 是 x 的密字。如此进行下去直到停止于如下的某个状态: 1. 所有信息扫描完毕,‘A’-‘Z’ 所有 26 个字母在原信息中均出现过并获得了相应
DSLIEWO
【输入输出样例 2 说明】 字母‘Z’在原信息中没有出现,输出“Failed”。
【输入输出样例 3】 spy.in MSRTZCJKPFLQYVAWBINXUEDGHOOILSMIJFRCOPPQCEUNYDUMPP YIZSDWAHLNOVFUCERKJXQMGTBPPKOIYKANZWPLLVWMQJFGQYLL FLSO
C 国幅员辽阔,各地的资源分布情况各不相同,这就导致了同一种商品在不同城市的价 格不一定相同。但是,同一种商品在同一个城市的买入价和卖出价始终是相同的。
商人阿龙来到 C 国旅游。当他得知同一种商品在不同城市的价格可能会不同这一信息 之后,便决定在旅游的同时,利用商品在不同城市中的差价赚回一点旅费。设 C 国 n 个城 市的标号从 1~ n,阿龙决定从 1 号城市出发,并最终在 n 号城市结束自己的旅行。在旅游的 过程中,任何城市可以重复经过多次,但不要求经过所有 n 个城市。阿龙通过这样的贸易方 式赚取旅费:他会选择一个经过的城市买入他最喜欢的商品——水晶球,并在之后经过的另 一个城市卖出这个水晶球,用赚取的差价当做旅费。由于阿龙主要是来 C 国旅游,他决定 这个贸易只进行最多一次,当然,在赚不到差价的情况下他就无需进行贸易。
【输入】 输入文件名为 spy.in,共 3 行,每行为一个长度在 1 到 100 之间的字符串。 第 1 行为小 C 掌握的一条加密信息。 第 2 行为第 1 行的加密信息所对应的原信息。 第 3 行为 R 国司令部要求小 C 翻译的加密信息。 输入数据保证所有字符串仅由大写字母‘A’-‘Z’构成,且第 1 行长度与第 2 行相等。
sudoku.pas sudoku.c sudoku.cpp
三.编译命令(不包含任何优化开关)
对于 pascal 语言
fpc spy.pas
fpc son.pas
对于 C 语言 gcc -o spy spy.c gcc -o son
-lm
son.c -lm
对于 C++语言
g++ -o spy
g++ -o son
假设 C 国有 5 个大城市,城市的编号和道路连接情况如下图,单向箭头表示这条道路 为单向通行,双向箭头表示这条道路为双向通行。
假设 1~n 号城市的水晶球价格分别为 4,3,5,6,1。 阿龙可以选择如下一条线路:1->2->3->5,并在 2 号城市以 3 的价格买入水晶球,在 3 号城市以 5 的价格卖出水晶球,赚取的旅费数为 2。 阿龙也可以选择如下一条线路 1->4->5->4->5,并在第 1 次到达 5 号城市时以 1 的价格 买入水晶球,在第 2 次到达 4 号城市时以 6 的价格卖出水晶球,赚取的旅费数为 5。
水晶球价格≤100。
4.靶形数独
(sudoku.pas/c/cpp) 【问题描述】
小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他 们想用数独来一比高低。但普通的数独对他们来说都过于简单了,于是他们向 Z 博士请教, Z 博士拿出了他最近发明的“靶形数独”,作为这两个孩子比试的题目。
【输出】 输出文件 trade.out 共 1 行,包含 1 个整数,表示最多能赚取的旅费。如果没有进行贸易,
则输出 0。
【输入输出样例】 trade.in 55 43561 121 141 232 351 452
trade.out 5
【数据范围】 输入数据保证 1 号城市可以到达 n 号城市。 对于 10%的数据,1≤n≤6。 对于 30%的数据,1≤n≤100。 对于 50%的数据,不存在一条旅游路线,可以从一个城市出发,再回到这个城市。 对于 100%的数据,1≤n≤100000,1≤m≤500000,1≤x,y≤n,1≤z≤2,1≤各城市
第3页共7页
全国信息学奥林匹克联赛(NOIP2009)复赛
【输入输出样例】
son.in
son.out
2
6
41 1 96 288
2
95 1 37 1776
【说明】 第一组输入数据,x 可以是 9、18、36、72、144、288,共有 6 个。 第二组输入数据,x 可以是 48、1776,共有 2 个。
【数据范围】 对于 50%的数据,保证有 1≤a0,a1,b0,b1≤10000 且 n≤100。 对于 100%的数据,保证有 1≤a0,a1,b0,b1≤2,000,000,000 且 n≤2000。
提高组
3.最优贸易
(trade.pas/c/cpp) 【问题描述】
C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市。任意两个 城市之间最多只有一条道路直接相连。这 m 条道路中有一部分为单向通行的道路,一部分 为双向通行的道路,双向通行的道路在统计条数时也计为 1 条。
靶形数独 sudoku sudoku
sudoku.in sudoku.out
2秒 20 5 有 全文比较 过滤行末空格 及文末回车 传统
二.提交源程序文件名
对于 pascal 语言
spy.pas
对于 C 语言
spy.c
对于 C++语言
spy.cpp
son.pas son.c son.cpp
trade.pas trade.c trade.cpp
靶形数独的方格同普通数独一样,在 9 格宽×9 格高的大九宫格中有 9 个 3 格宽×3 格 高的小九宫格(用粗黑色线隔开的)。在这个大九宫格中,有一些数字是已知的,根据这些
第5页共7页
全国信息学奥林匹克联赛(NOIP2009)复赛
提高组
全国信息学奥林匹克联赛(NOIP2009)复赛
提高组
全国信息学奥林匹克联赛(NOIP2009)复赛
提高组
(请选手务必仔细阅读本页内容)
一.题目概况
中文题目名称 英文题目名称 可执行文件名 输入文件名 输出文件名 每个测试点时限 测试点数目 每个测试点分值 附加样例文件 结果比较方式
题目类型
潜伏者 spy spy spy.in
四.运行内存限制
内存上限
128M
128M
128M
128M
注意事项:
1、文件名(程序名和输入输出文件名)必须使用小写。 2、C/C++中函数 main()的返回值类型必须是 int,程序正常结束时的返回值必须是 0。 3、全国统一评测时采用的机器配置为:CPU 1.9GHz,内存 1G,上述时限以此配置为准。各 省在自测时可根据具体配置调整时限。
spy.out 1秒 10 10 有
全文比较 过滤行末空格 及文末回车
传统
Hankson 的趣味题 son son
son.in son.out
1秒 10 10 有 全文比较 过滤行末空格及 文末回车 传统
最优贸易 trade trade
trade.in trade.out
1秒 10 10 有 全文比较 过滤行末空格 及文末回车 传统
全国信息学奥林匹克联赛(NOIP2009)复赛
提高组
【输入输出样例 1 说明】 原信息中的字母‘A’和‘B’对应相同的密字,输出“Failed”。
【输入输出样例 2】
spy.in
spy.out
QWERTYUIOPLKJHGFDSAZXCVBN
Failed
ABCDEFGHIJKLMNOPQRSTUVWXY
1. x 和 a0 的最大公约数是 a1; 2. x 和 b0 的最小公倍数是 b1。 Hankson 的“逆问题”就是求出满足条件的正整数 x。但稍加思索之后,他发现这样的 x 并不唯一,甚至可能不存在。因此他转而开始考虑如何求解满足条件的 x 的个数。请你帮 助他编程求解这个问题。
【输入】 输入文件名为 son.in。第一行为一个正整数 n,表示有 n 组输入数据。接下来的 n 行每
(son.pas/c/cpp) 【问题描述】
Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson。现 在,刚刚放学回家的 Hankson 正在思考一个有趣的问题。
今天在课堂上,老师讲解了如何求两个正整数 c1 和 c2 的最大公约数和最小公倍数。现 在 Hankson 认为自己已经熟练地掌握了这些知识,他开始思考一个“求公约数”和“求公 倍数”之类问题的“逆问题”,这个问题是这样的:已知正整数 a0,a1,b0,b1,设某未知正整 数 x 满足:
数目。 第二行 n 个正整数,每两个整数之间用一个空格隔开,按标号顺序分别表示这 n 个城
市的商品价格。 接下来 m 行,每行有 3 个正整数,x,y,z,每两个整数之间用一个空格隔开。如果 z=1,
表示这条道路是城市 x 到城市 y 之间的单向道路;如果 z=2,表示这条道路为城市 x 和城市 y 之间的双向道路。
相关文档
最新文档