ACM试题

合集下载

acm数学竞赛试题

acm数学竞赛试题

acm数学竞赛试题
ACM数学竞赛试题通常涉及各种数学领域,包括但不限于代数、几何、概率统计和组合数学等。

以下是一些经典的ACM数学竞赛试题:
1. 平面上n个点的k距离和最小值问题:给定平面上n个点,对于每个点,计算它到其他所有点的距离,然后求出这些距离中的k个最小值。

问题是:如何有效地计算这k个最小值?
2.最长公共子序列问题:给定两个序列,找出它们的最长公共子序列。

例如,对于序列
A = [1, 2, 3, 4] 和
B = [2, 3, 4, 5],最长公共子序列是[2, 3, 4]。

3. 凸包问题:给定平面上的一组点,找到一个最小的凸多边形,使得这个多边形能够包含这组点中的所有点。

4. 最短路问题:给定一个有向图,其中每条边都有一个非负的权重,找出图中任意两点之间的最短路径。

5. 子集和问题:给定一个正整数数组和一个目标值,判断数组中是否存在和为目标值的两个非空子集。

例如,给定数组[1, 2, 3, 4] 和目标值7,判断是否存在两个子集,它们的和分别为7。

以上只是ACM数学竞赛试题的一部分,实际上还有更多涉及数学各个领域的题目。

要提高解决这类问题的能力,需要不断练习和研究。

山东科技大学第二届ACM程序设计大赛试题

山东科技大学第二届ACM程序设计大赛试题

山东科技大学第二届ACM程序设计大赛试题册试题共14页,题目共计12道山东科技大学第二届ACM 程序设计大赛试题册Problem A 简单计算Description给出n 个十进制的数,找出这n 个数的二进制表示中1的个数最少的数。

Input输入的第一行为一个正整数T (1≤T ≤20),代表测试数据组数。

对于每组测试数据,输入的第一行为一个正整数n (1≤n ≤10000),第二行为n个正整数A 1、A 2、…、A n (1≤A i ≤109),每个数之间以空格分隔。

Output每组数据输出一行,先输出数据组数,再输出二进制中含1最少的数,如果存在多个数符合条件,输出最小的那个。

具体输出格式见样例输出。

Sample Input Sample Output山东科技大学第二届ACM 程序设计大赛试题册Problem B 关键字搜索Description我们的新网站具有了全新的搜索功能,使用了2个通配符“*”和“?”,其中“*”表示0或者多个小写字母,“?”代表1个字母。

当我们输入一个关键字的时候,我们在不确定的地方就使用通配符。

我们在数据库里面有多条记录,每条记录都是由小写字母组成,现在给出一个关键字,你能告诉我数据库里面有多少条与关键字相匹配的记录吗?例如: 如果关键字是j*y*m*y?,那么jiyanmoyu ,jyanmoyu ,jymyu 都是相匹配的记录。

Input第一行输入一个T (T ≤20),表示有T 组测试数据。

对于每组测试数据,第一行是输入的关键字,接下是数据库里面的所有记录的条数n ,1≤n ≤10000,每条记录的长度不超过50个小写字母。

Output对于每组测试数据,输出与关键字相匹配的总记录条数,占一行。

Sample Input Sample Output山东科技大学第二届ACM 程序设计大赛试题册Problem C 正方形Description在二维坐标轴内给出四个点,这四个点能否构成一个正方形。

计算机acm试题及答案

计算机acm试题及答案

计算机acm试题及答案一、选择题1. 在计算机科学中,ACM代表什么?A. 人工智能与机器学习B. 计算机辅助制造C. 计算机辅助设计D. 国际计算机学会答案:D2. 下列哪个不是计算机程序设计语言?A. PythonB. JavaC. C++D. HTML答案:D3. 在计算机系统中,CPU代表什么?A. 中央处理单元B. 计算机辅助设计C. 计算机辅助制造D. 计算机辅助教学答案:A二、填空题1. 计算机的内存分为__________和__________。

答案:RAM;ROM2. 在编程中,__________是一种用于存储和操作数据的数据结构。

答案:数组3. 计算机病毒是一种__________,它能够自我复制并传播到其他计算机系统。

答案:恶意软件三、简答题1. 请简述计算机操作系统的主要功能。

答案:计算机操作系统的主要功能包括管理计算机硬件资源,提供用户界面,运行应用程序,以及控制其他系统软件和应用软件的运行。

2. 什么是云计算,它与传统的本地计算有何不同?答案:云计算是一种通过互联网提供计算资源(如服务器、存储、数据库、网络、软件等)的服务模式。

与传统的本地计算相比,云计算允许用户按需获取资源,无需购买和维护物理硬件,具有更高的灵活性和可扩展性。

四、编程题1. 编写一个程序,计算并输出从1到100(包括1和100)之间所有偶数的和。

答案:```pythonsum = 0for i in range(1, 101):if i % 2 == 0:sum += iprint(sum)```2. 给定一个字符串,编写一个函数,将字符串中的所有字符按ASCII 码值排序并返回。

答案:```pythondef sort_string(s):return ''.join(sorted(s))```五、论述题1. 论述计算机硬件和软件之间的关系及其对计算机系统性能的影响。

答案:计算机硬件是计算机系统的物质基础,包括CPU、内存、硬盘等,而软件则是运行在硬件上的程序和数据。

acm程序设计大赛试题

acm程序设计大赛试题

acm程序设计大赛试题题目:旅游管理系统一、问题描述随着信息技术的飞速发展,旅游业作为全球经济的重要组成部分,其管理和服务水平也在不断提升。

为了更好地服务游客,提高工作效率,我们计划开发一个旅游管理系统。

该系统旨在帮助旅游公司管理客户信息、行程安排、预订情况以及费用结算等业务。

本文将详细介绍该系统的设计要求和功能特点。

二、功能需求1. 客户信息管理系统应能够记录客户的基本信息,包括姓名、联系方式、身份证号码等。

同时,应支持对客户信息的增加、修改和查询功能。

此外,系统还应具备客户信息的分类和统计功能,便于旅游公司对客户群体进行分析。

2. 行程安排旅游公司需要根据客户需求和旅游资源情况,为客户制定合适的旅游行程。

系统应提供行程规划功能,包括景点选择、活动安排、住宿和交通预订等。

同时,系统应能够根据实际情况调整行程,并及时更新相关信息。

3. 预订管理系统应能够处理客户的旅游预订,包括景点门票、酒店房间、交通工具等。

预订管理功能应包括预订的创建、修改、取消和确认等操作,并能够实时更新预订状态,确保信息的准确性。

4. 费用结算旅游费用的结算是旅游管理系统的核心功能之一。

系统应能够根据客户的预订情况和实际消费,自动计算应付费用。

同时,系统还应支持多种支付方式,如信用卡、支付宝、微信支付等,并能够生成详细的费用清单和发票。

5. 数据安全与备份鉴于旅游管理系统中涉及大量敏感信息,系统必须具备严格的数据安全措施。

包括但不限于用户权限管理、数据加密、防止SQL注入等。

此外,系统还应定期进行数据备份,以防数据丢失或损坏。

三、系统架构设计1. 前端设计系统的前端设计应注重用户体验,界面友好、操作简便。

可以使用HTML5、CSS3和JavaScript等技术开发响应式网页,以适应不同设备和屏幕尺寸。

同时,前端应提供丰富的交互功能,如日历选择、地图展示、图片上传等。

2. 后端设计后端设计主要负责处理业务逻辑、数据存储和安全保障。

ACM面试题-美国计算机程序选拔赛

ACM面试题-美国计算机程序选拔赛

【试题一】青蛙相遇问题【题目描述】两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。

它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。

可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。

不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。

但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。

为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。

我们把这两只青蛙分别叫做青蛙A和青蛙B,并且规定纬度线上东经0度处为原点,由东往西为正方向,单位长度1米,这样我们就得到了一条首尾相接的数轴。

设青蛙A的出发点坐标是x,青蛙B的出发点坐标是y。

青蛙A一次能跳m米,青蛙B一次能跳n米,两只青蛙跳一次所花费的时间相同。

纬度线总长L米。

现在要你求出它们跳了几次以后才会碰面。

Input 输入只包括一行5个整数x,y,m,n,L,其中x≠y < 2000000000,0 < m、n < 2000000000,0 < L < 2100000000。

Output 输出碰面所需要的跳跃次数,如果永远不可能碰面则输出一行"Impossible"示例Sample Input1 2 3 4 5Sample Output4题目要求;1.程序应该可以运行:通过控制台输入数据,输出数据通过printf给出;2.程序结构明了逻辑缜密、清晰,符合编码规范;3.程序功能正确;程序要注意效率;并且要求根据输入及时确认是否能够相遇,如果不能相遇请及早退出程序;程序思路:说明:可以将青蛙的路线看坐是一个圆判断其坐标如果下一次跳动后将饶过原点则把坐标转换这样无论青蛙在哪个位置上都用坐标来表示它如果两只青蛙坐标相等则相遇如果两只青蛙开始的坐标不一样但是速度一样那么将永远不能相遇【试题二】田忌赛马此题就是经典的田忌赛马,田忌和他的对手分别有n匹马,分别给出田忌的马的速度和对手的马的速度。

ACM程序大赛选拔初赛试题 - 参考答案

ACM程序大赛选拔初赛试题 - 参考答案

《解方程》参考答案:
#include <stdio.h> #include <math.h> void main() {
int a,b,c,d; float x1,x2; scanf("%d %d %d %d",&a,&b,&c,&d); if(a==0) printf("x=%.2f",(float)(d-c)/b); else {
float dr=b*b-4*a*c; c-=d; if(dr>0) {
x1=(-b-sqrt(dr))/(2*a); x2=(-b+sqrt(dr))/(2*a); printf("x1=%.2f x2=%.2f\n",x1,x2); } if(dr==0) { x1=(-b+sqrt(dr))/(2*a); printf("x=%.2f\n",x1); } if(dr<0) printf("no answer\n"); } }
3、计算器 (难度系数:★★★☆☆)
题意:输入一个没有答案的算术式子,用计算机求出输出它的结果。 输入:一个字符串形如“a#b=”(#代表运算符号)。注意:输入的字符串中 a,b 代表的数 都为自然数。而且 a,b 的范围都是从 0 到 999。 输出:字符串对应的算式的答案。答案需保留两位有效数字。若无答案则输出“error” 示例:
输出:第1 行是选出顺序,第2 行是两名幸运儿的开始位置(按升序排列),位置编号之 间用一个空格分开。
示例:
输入(只选一组) 3 5 12
输出(幸运儿的位置)
2 13 241 53 2 4 6 8 10 12 3 7 11 5 19

计算机学院ACM设计大赛初赛试题

计算机学院ACM设计大赛初赛试题

计算机学院ACM设计大赛初赛试题问题一:给定一个N位的二进制串b1 b2 …bN-1 bN将该串做旋转,即将b1移到bN后面,得到一个新的二进制串:b2 …bN-1 bN b1对新的二进制串再做旋转,得二进制串b3 b4 …bN-1 bN b1 b2重复旋转操作操作,可得N个二进制串,对这N个串排序,可得一个N*N的矩阵问:给定这种矩阵的最后一列,求出矩阵的第一行。

对于上面的例子,给出1 0 0 1 0,要你的程序输出0 0 0 1 1。

原题描述:Binary codesTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4881 Accepted: 1847DescriptionConsider a binary string (b1…b N) with N binary digits. Given such a string, the matrix of Figure 1 is formed from the rotated versions of the string.b 1b2…b N−1b Nb 2b3…b N b1…b N−1b N…b N−3b N−2b N b1…b N−2b N−1Figure 1. The rotated matrixThen rows of the matrix are sorted in alphabetical order, where ‘0’ is before ‘1’. You are to write a program which, given the l ast column of the sorted matrix, finds the first row of the sorted matrix.As an example, consider the string (00110). The sorted matrix is0 0 0 1 10 0 1 1 00 1 1 0 01 0 0 0 11 1 0 0 0and the corresponding last column is (1 0 0 1 0). Given this last column your program should determine the first row, which is (0 0 0 1 1).InputThe first line contains one integer N≤ 3000, the number of binary digits in the binary string. The second line contains N integers, the binary digits in the last column from top to bottom.OutputThe first line contains N integers: the binary digits in the first row from left to right. Sample Input51 0 0 1 0Sample Output0 0 0 1 1问题二:某地的交通网由路口和公路构成:两个路口之间最多有一条公路,公路两个方向的行驶时间相同。

ACM选拔赛试题

ACM选拔赛试题

ACM选拔赛试题
注意:程序文件命名为:Test+题号
1、已知四位数3025有一个特殊性质:它的前两位数30和后两位数25的和是55,而55的平方刚好等于该数(55*55=3025),编写一个程序求出所有的具有这种性质的四位数。

2、有的三位数很独特,它们每位上的数字互不相同且都不大于7,特别是十位数正好是百位数和个位数之差,编写程序求所有这样的三位数。

3、某电台组织一次智力竞赛,计划奖励30人。

准备了50件奖品,得一等奖者可得3件,二等奖可得2件,三等奖可得1件。

希望把所有奖品都发到获奖者手中,请编程找出所有的设奖方案(即各等奖各有多少人)。

4、修改31743的某一位数字,使之成为823的倍数。

5、在自然数中,各位数字之和的11倍正好等于自身的自然数只有一个,编写程序请找出这个自然数。

6、小明的妈妈是负责分发单位工资的。

为了使分发时有足够的零钞,同时又尽量不使每个人领到的钱太零碎。

每个月她都要计算出各种面值的钞票(100元、50元、20元、10元、5元、2元、1元)各需多少张。

假设每个人的工资都是整数元,你能否为她设计一个程序,从键盘输入10个人的工资,再计算各种面值的钞票各需多少张?
7、4名专家对四款赛车进行评论:
A说:2号赛车是最好的。

B说:4号赛车是最好的。

C说:3号赛车不是最佳赛车。

D说:B说错了。

事实上,只有一款赛车最佳,且只有一名专家说对了,其他3人说错了,请编程输出最佳赛车的车号,以及哪一位专家说对了。

ACM比赛试题

ACM比赛试题

The 35th ACM-ICPC Asia Regional Contest (Hangzhou)Contest SectionOctober 24, 2010Sponsored by IBM & AlibabaZhejiang Sci-Tech UniversityThis problem set should contain 10 problems on numbered 24 pages. Please inform a runner immediately if something is missing from your problem set.Problem A. Naughty fairiesDescriptionOnce upon a time, there lived a kind of fairy in the world. Those fairies could hear the voice of fruit trees, and helped people with a harvest. But people did n’t know that fruits are also those fairies’ favorite food. After the fairies ate people’s fruits, they always did something to cover it up.One day a little fairy named Lily flew into an orchard and found a large peach tree. Hungry as Lily was, she started eating without thinking until her stomach was full. In the fairy world, when a fairy ate the fruits in a fruit tree, sometimes the fruit tree would feel honored and bore more fruits immediately. That’s why sometimes the number of fruits in a tree got increased after a fairy ate fruits of that tree.But the fairies didn’t want people to find out weird things such as fruits become more or less suddenly. Lily decided to use a magic spell so that the orchard owner couldn’t find the change of the number of p eaches.Suppose there were N peaches on a tree originally and there were M peaches left after Lily was full. M may be greater than, less than or equal to N. All M peaches were visible at first, and Lily wanted to make an illusion so that exactly N peaches are visible.Lily can do 3 kinds of spell to change the total visible number of peaches:1) “PAPADOLA”:This spell would increase the number of visible peaches by one.2) “EXPETO POTRONUM”:This spell would double the number of visible peaches.3) “SAVIDA LOHA”:This spell would decrease the number of visible peaches by one. Each spell would take one minute and Lily wanted to finish as fast as possible. Now please tell Lily the least time she needs to change the number of visible peaches to N.InputThere are several test cases, ended by “0 0”.For each test case, there are only one line containing two numbers separated by a blank, N and M, the original numbers of peaches and the numbers of peaches left(0<N,M<10500).There is no leading zero.OutputFor each test case, you should output just a number K indicating the minimum time (in minutes) Lily needed to finish her illusion magic.Sample Input5 21 9986 320 0Sample Output29812Problem B. Prison BreakDescriptionRompire is a robot kingdom and a lot of robots live there peacefully. But one day, the king of Rompire was captured by human beings. His thinking circuit was changed by human and thus became a tyrant. All those who are against him were put into jail, including our clever Micheal#1. Now it’s time to escape, but Micheal#1 needs an optimal plan and he contacts you, one of his human friends, for help.The jail area is a rectangle contains n×m little grids, each grid might be one of the following:1) Empty area, represented by a capital letter ‘S’.2) The starting position of Micheal#1, represented by a capital letter ‘F’.3) Energy pool, represented by a capital letter ‘G’. When entering a n energy pool, Micheal#1 can use it to charge his battery ONLY ONCE. After the charging, Micheal#1’s batt ery will become FULL and the energy pool will become an empty area. Of course, passing an energy pool without using it is allowed.4) Laser sensor, represented by a capital letter ‘D’. Since it is extremely sensitive, Micheal#1 cannot step into a grid with a laser sensor.5) Power switch, represented by a capital letter ‘Y’. Once Micheal#1 steps into a grid with a Power switch, he will certainly turn it off.In order to escape from the jail, Micheal#1 need to turn off all the power switches to stop the electric web on the roof—then he can just fly away. Moving to an adjacent grid (directly up, down, left or right) will cost 1 unit of energy and only moving operation costs energy. Of course, Micheal#1 cannot move when his battery contains no energy.The larger the battery is, the more energy it can save. But larger battery means more weight and higher probability of being found by the weight sensor. So Micheal#1 needs to make his battery as small as possible, and still large enough to hold all energy he need. Assuming that the size of the battery equals to maximum units of energy that can be saved in the battery, and Micheal#1 is fully charged at the beginning, Please tell him the minimum size of the battery needed for his Prison break.InputInput contains multiple test cases, ended by 0 0. For each test case, the first line contains two integer numbers n and m showing the size of the jail. Next n lines consist of m capital letters each, which stands for the description of the jail.You can assume that 1<=n,m<=15, and the sum of energy pools and power switches is less than 15.OutputFor each test case, output one integer in a line, representing the minimum size of the battery Micheal#1 needs. If Micheal#1 can’t escape, output -1.Sample Input5 5GDDSSSSSFSSYGYSSGSYSSSYSS0 0Sample Output4Problem C. To Be an Dream Architect DescriptionThe “dream architect” is the key role in a team of “dream extractors” who enter other’s dreams to steal secrets. A dream architect is responsible for crafting the virtual world that the team and the target will dream into. To avoid the target noticing the world is artificial, a dream architect must have powerful 3D imagination.Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1) and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many blocks are eliminated. Note that one block can only be eliminated once even if it is on multiple lines.Here is a sample graph according to the first test case in the sample input:InputThe first line is the number of test cases.In each test case, the first line contains two integers n and m( 1 <= n <= 1000, 0 <= m <= 1000).,meaning that the cube is n x n x n and there are m eliminations.Each of the following m lines represents an elimination in the following format:axis_1=a, axis_2=bwhere axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b ar e 32-bit signed integers.OutputFor each test case output the number of eliminated blocks.Sample Input23 2Y=1,Z=3X=3,Y=110 2X=3,Y=3Y=3,Z=3Sample Output519Problem D. GomokuDescriptionYou are probably not familiar with the title, “Gomoku”, but you must have played it a lot. Gomoku is an abstract strategy board game and is also called Five in a Row, or GoBang. It is traditionally played with go pieces (black and white stones) on a go board (19x19 intersections). Nowadays, standard chessboard of Gomoku has 15x15 intersections. Black plays first, and players alternate in placing a stone of their color on an empty intersection. The winner is the first player to get an unbroken row of five or more stones horizontally, vertically, or diagonally.For convenience, we coordinate the chessboard as illustrated above. The left-bottom intersection is (0,0). And the bottom horizontal edge is x-axis, while the left vertical line is y-axis.I am a fan of this game, actually. However, I have to admit t hat I don’t have a sharp mind. So I need a computer program to help me. What I want is quite simple. Given a chess layout, I want to know whether someone can win within 3 moves, assuming both players are clever enough. Take the picture above for example. There are 31 stones on it already, 16 black ones and 15 white ones. Then we know it is white turn. The white player must place a white stone at (5,8). Otherwise, the black player will win next turn. After that, however, the white player also gets a perfect situation that no matter how his opponent moves, he will win at the 3rd move.So I want a program to do similar things for me. Given the number of stones and positions of them, the program should tell me whose turn it is, and what will happen within 3 moves.InputThe input contains no more than 20 cases.Each case contains n+1 lines which are formatted as follows.nx1 y1 c1x2 y2 c2......x n y n c nThe first integer n indicates the number of all stones. n<=222 which means players have enough space to place stones. Then n lines follow. Each line contains three integers: x i and y i and c i. x i and y i are coordinates of the stone, and ci means the color of the stone. If c i=0 the stone is white. If c i=1 the stone is black. It is guaranteed that 0<=x i,y i<=14, and c i=0 or 1. No two stones are placed at the same position. It is also guaranteed that there is no five in a row already, in the given cases.The input is ended by n=0.OutputFor each test case:First of all, the program should check whose turn next. Le t’s call the player who will move next “Mr. Lucky”. Obviously, if the number of the black stone equals to the number of white, Mr. Lucky is the black player. If the number of the black stone equals to one plus the numbers of white, Mr. Lucky is the white player. If it is not the first situation or the second, print “Invalid.”A valid chess layout leads to four situations below:1)Mr. Lucky wins at the 1st move. In this situation, print :Place TURN at (x,y) to win in 1 move.“TURN” must be replaced by “black” or “white” according to the situation and (x,y) is the position of the move. If there are different moves to win, choose theone where x is the smallest. If there are still different moves, choose the one where y is the smallest.2)Mr. Lucky’s opp onent wins at the 2nd move. In this situation, print:Lose in 2 moves.3)Mr. Lucky wins at the 3rd move. If so, print:Place TURN at (x,y) to win in 3 moves.“TURN” should replaced by “black” or “white”, (x,y) is the position where the Mr.Lucky should place a stone at the 1st move. After he place a stone at (x,y), no matter what his opponent does, Mr. Lucky will win at the 3rd step. If there are multiple choices, do the same thing as described in situation 1.4)Nobody wins within 3 moves. If so, print:Cannot win in 3 moves.Sample Input313 3 13 4 03 5 03 6 04 4 14 5 14 7 05 3 05 4 05 5 15 6 15 7 15 9 16 4 16 5 16 6 06 7 16 8 06 9 07 5 17 6 07 7 17 8 17 9 08 5 08 6 18 7 08 8 18 9 09 7 110 8 017 7 117 7 0Sample OutputPlace white at (5,8) to win in 3 moves. Cannot win in 3 moves.Invalid.Problem E. GunshotsDescriptionPresident Bartlet was shot! A group of terrorists shot to the crowd when President Bartlet waved to cheering people after his address. Many people were shot by the irrational bullets. Senior FBI agent Don Epps takes responsibility for this case. According to a series of crime scene investigation, including analyzing shot shells, replaying video from closed-circle television and collecting testimony by witnesses, Don keeps all the information about where and how the terrorists shot to crowd, as well as the location of every single person when the gun shoot happened. Now he wants to know how many gunshot victims are there in this case.Imagine that each target person can be regarded as a polygon (can be concave or self-intersecting) and each gunshot can be regarded as a half-line. The bullet will be stopped by the first person it shoots. A person can be shot in three ways:To simplify the problem, we assume that any two polygons can be completely separated by a line. Also each start point of the gunshot can be separated from each polygon by a line. Now given M people and N gunshots, please work out which person has been shot by each bullet.InputThere are multiple test cases in the input. The first line of the input file is an integer T demonstrating the number of test cases. (T<=10).For each test case, the first line is an integer N, representing the number of people (polygons). Following lines demonstrates the polygons. For the i th polygon (0<=i<N), the first line is an integer Q i , representing the number of edges of this polygon. In each of the following Q i lines, there are two real numbers x i and y i representing a point. Every pair of adjacent points demonstrate an edge of this polygon (i.e. (x i , y i ) to (x i+1, y i+1) is an edge, in which 0<=i<Q i -1), and (x Qi-1, y Qi-1) to (x 0, y 0) also demonstrates an edge of this polygon.PersonPerson Person 1. Normal shot 2. The bullet’s path isparallel to an edge 3. The bullet’s path is tangent to an vertexThen there is a line contains an integer M representing the number of gunshots. In the following M lines, each line contains four real numbers x, y, dx and dy, representing the start point (x, y) and direction vector (dx, dy) of that gunshot.In all test cases, we assume that 0< N<=100, 0<Q i<=1000, 0<M<=10000.OutputFor each test case, output contains M lines and the i th line demonstrates the result of the i th gunshot.If the i th gunshot shoots the j th polygon, the i th line contains “HIT j”, otherwise it contains a word “MISS” (means that it does not shoot any target). The polygons are numbered in the order of their appearance in the input file, and the numbers start from 0.At the end of each test case, please output a single line with “*****”.Sample Input1140 01 10 11 02-1 0 1 0-2 0 -1 0Sample OutputHIT 0MISS*****HintThe figure of the first case in the samples is as follows:Problem F. Rotational PaintingDescriptionJosh Lyman is a gifted painter. One of his great works is a glass painting. He creates some well-designed lines on one side of a thick and polygonal glass, and renders it by some special dyes. The most fantastic thing is that it can generate different meaningful paintings by rotating the glass. This method of design is called “Rotatio nal Painting (RP)” which is created by Josh himself.You are a fan of Josh and you bought this glass at the astronomical sum of money. Since the glass is thick enough to put erectly on the table, you want to know in total how many ways you can put it so that you can enjoy as many as possible different paintings hiding on the glass. We assume that material of the glass is uniformly distributed. If you can put it erectly and stably in any ways on the table, you can enjoy it.More specifically, if the polygonal glass is like the polygon in Figure 1, you have just two ways to put it on the table, since all the other ways are not stable. However, the glass like the polygon in Figure 2 has three ways to be appreciated.Pay attention to the cases in Figure 3. We consider that those glasses are not stable.InputThe input file contains several test cases. The first line of the file contains an integer T representing the number of test cases.For each test case, the first line is an integer n representing the number of lines of the polygon. (3<=n<=50000). Then n lines follow. The i th line contains two real number x i and y i representing a point of the polygon. (x i, y i) to (x i+1, y i+1) represents a edge of the polygon (1<=i<n), and (x n,y n) to (x1, y1) also represents a edge of the polygon. The input data insures that the polygon is not self-crossed.OutputFor each test case, output a single integer number in a line representing the number of ways to put the polygonal glass stably on the table.Sample Input240 0100 099 11 160 00 101 101 110 110 0Sample Output23HintThe sample test cases can be demonstrated by Figure 1 and Figure 2 in Description part.Problem G. Traffic Real Time Query System DescriptionCity C is really a nightmare of all drivers for its traffic jams. To solve the traffic problem, the mayor plans to build a RTQS (Real Time Query System) to monitor all traffic situations. City C is made up of N crossings and M roads, and each road connects two crossings. All roads are bidirectional. One of the important tasks of RTQS is to answer some queries about route-choice problem. Specifically, the task is to find the crossings which a driver MUST pass when he is driving from one given road to another given road.InputThere are multiple test cases.For each test case:The first line contains two integers N and M, representing the number of the crossings and roads.The next M lines describe the roads. In those M lines, the i th line (i starts from 1)contains two integers X i and Y i, representing that road i connects crossing X i and Y i (X i≠Y i).The following line contains a single integer Q, representing the number of RTQs. Then Q lines follows, each describing a RTQ by two integers S and T(S≠T) meaning that a driver is now driving on the road s and he wants to reach road t . It will be always at least one way from road s to road t.The input ends with a line of “0 0”.Please note that: 0<N<=10000, 0<M<=100000, 0<Q<=10000, 0<X i,Y i<=N, 0<S,T<=M OutputFor each RTQ prints a line containing a single integer representing the number of crossings which the driver MUST pass.Sample Input5 61 22 33 44 53 522 32 40 0Sample Output 01Problem H. National Day ParadeDescriptionThere are n×n students preparing for the National Day parade on the playground. The playground can be considered as a n×m grid. The coordinate of the west north corner is (1,1) , and the coordinate of the east south corner is (n,m).When training, every students must stand on a line intersection and all students must form a n×n square. The figure above shows a 3×8 playground with 9 students training on it. The thick black dots stand for the students. You can see that 9 students form a 3×3 square.After training, the students will get a time to relax and move away as they like. To make it easy for their masters to control the training, the students are only allowed to move in the east-west direction. When the next training begins, the master would gather them to form a n×n square again, and the position of the square doesn’t matter. Of course, no student is allowed to stand outside the playground.You are given the coordinates of each student when they are having a rest. Your task is to figure out the minimum sum of distance that all students should move to form a n×n square.InputThere are at most 100 test cases.For each test case:The first line of one test case contain two integers n,m. (n<=56,m<=200)Then there are n×n lines. Each line contains two integers, 1<=X i<=n,1<= Y i<=m indicating that the coordinate of the i th student is (X i , Y i ). It is possible for more than one student to stand at the same grid point.The input is ended with 0 0.OutputYou should output one line for each test case. The line contains one integer indicating the minimum sum of distance that all students should move to form a n×n square. Sample Input2 1682 1011 1271 1052 900 0Sample Output41Problem I. SearchlightsDescriptionThere is a piece of grids land of size n×m. Chandler and his team take responsibility to guard it. There are some searchlights on some pieces and each of them has a capability to lighten a distance towards four directions: north, south, east and west. Different searchlight has different lightening capability shown in levels. Searchlight with level k means that it can lighten k grids (including the gird that the searchlight stands in) along any of the four directions. Shown in following figure, there is a searchlight of level 3 and the shadow grids are ones that can be lightened by it. Particularly, searchlight of level 1 means that it can only lighten the grid in which the searchlight stands.Figure: A searchlight of Level 3Each searchlight has a maximum level. You can decrease a searchlight’s level to save the energy. A searchlight whose maximum level is k can be turned to level k, k-1, k-2, …, 1 and 0. Level 0 means turning off the searchlight.A grid is well-guarded if and only if at least one of the following two conditions is satisfied:1.There is a searchlight in this grid, and it is not switched to level 0 (the light is on).2.The grid is lightened by at least two searchlights. One lightens it in horizontaldirection (east or west), and another lightens it in vertical direction (north or south).Chandler asks you to help finding a solution that he can turn on some of the searchlights so that:1.All the grids are well-guarded.2.All the searchlights turned on are in a same level.3.That same level mentioned above is as small as possible.More specifically, if you choose a same level Q, then all the searchlights whose maximum level are less than Q have to be turned off. Please help him to find a solution with the minimum same level.InputThe input file contains several test cases.For each test case, the first line is two integers n and m, representing a grids land of size n×m. (0<n<=100, 0<m<=10000). Following n lines describe an n×m matrix in which a i,j means the maximum level of the searchlight in grid (i, j). a i,j can be zero, which means there is no searchlight on that grid. For all the cases, a i, j<=10000.The input file ends with a line containing two zeros.OutputFor each test case, output a single line with an integer, representing the minimum level you have found. If there is no such a solution, output “NO ANSWER!”Sampl e Input2 20 23 02 20 21 00 0Sampl e Output2NO ANSWER!Problem J. Infinite monkey theorem DescriptionCould you imaging a monkey writing computer programs? Surely monkeys are smart among animals. But their limited intelligence is no match for our human beings. However, there is a theorem about monkeys, and it states that monkeys can write everything if given enough time.The theorem is called “Infinite monkey theorem”. It states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type any given text, which of course includes the programs you are about to write (All computer programs can be represented as text, right?).It’s very easy to prove this theorem. A little calculation will show you that if the monkey types for an infinite length of time the probability that the output contains a given text will approach 100%.However, the time used is too long to be physically reasonable. The monkey will not be able to produce any useful programs even if it types until the death of the universe. To verify this and ensure that our human beings are not replaceable by monkeys, you are to calculate the probability that a monkey will get things right.InputThere will be several test cases.Each test case begins with a line containing two integers n and m separated by a whitespace (2<=n<=26, 1<=m<=1000). n is the number of keys on the typewriter and the monkey will hit these keys m times. Thus the typewriter will finally produce an output of m characters.The following n lines describe keys on the typewriter. Each line has a lower case letter and a real number separated by a whitespace. The letter indicates what the typewriter will produce if the monkey hits that key and the real number indicates the probability that the monkey will hit this key. Two hits of the monkey are independent of each other (Two different hits have the same probability for a same key), and sum of all the probabilities for each key is ensured to be 1.The last line of the test case contains a word composed of lower case letters. The length of the word will be less than or equal to 10.The input will end with a line of two zeros separated by a whitespace. This line should not be processed.OutputFor each test case, output one line containing the probability that the given word will appear in the typewriter’s output. The output should be in percentage format and numbers should be rounded to two digits after the decimal point.Sampl e Input4 10w 0.25o 0.25r 0.25d 0.25word2 10a 1.0b 0.0abc2 100a 0.312345b 0.687655abab0 0Sampl e Output2.73%0.00%98.54%。

acm大学生程序设计试题

acm大学生程序设计试题

acm大学生程序设计试题题目一:最大公约数(GCD)题目描述:给定两个正整数,求它们的最大公约数(GCD)。

输入两个正整数a和b(1 <= a, b <= 10^9),求它们的最大公约数。

输入格式:两个正整数,以空格分隔。

输出格式:输出一个整数,表示输入两个正整数的最大公约数。

示例:输入:14 21输出:7思路和分析:最大公约数(GCD)可以使用欧几里得算法来求解,即辗转相除法。

具体的步骤如下:1. 用较大的数除以较小的数,将得到的余数作为新的较大数。

2. 再用新的较大数除以较小数,将得到的余数作为新的较大数。

3. 如此重复,直到两个数可以整除,此时较小的数就是最大公约数。

代码实现:```cpp#include <iostream>using namespace std;int gcd(int a, int b) {if (b == 0)return a;return gcd(b, a % b);}int main() {int a, b;cin >> a >> b;int result = gcd(a, b);cout << result << endl;return 0;}```题目二:字符串反转题目描述:给定一个字符串,要求将其反转并输出。

输入一个字符串s(1 <= |s| <= 1000),输出该字符串的反转结果。

输入格式:一个字符串s,只包含大小写字母和数字。

输出格式:一个字符串,表示输入字符串的反转结果。

示例:输入:HelloWorld123输出:321dlroWolleH思路和分析:字符串反转可以使用双指针的方法来实现。

初始时,左指针指向字符串的开头,右指针指向字符串的末尾,然后交换左右指针所指向的字符,并向中间移动,直到左指针不小于右指针。

代码实现:```cpp#include <iostream>using namespace std;string reverseString(string s) {int left = 0, right = s.length() - 1; while (left < right) {swap(s[left], s[right]);left++;right--;}return s;}int main() {string s;cin >> s;string result = reverseString(s); cout << result << endl;return 0;}```题目三:字符串匹配题目描述:给定一个字符串s和一个模式串p,判断s中是否存在与p相匹配的子串。

acm数学竞赛试题及答案

acm数学竞赛试题及答案

acm数学竞赛试题及答案# 题目一:数列问题问题描述:给定一个数列 \( a_1, a_2, a_3, \ldots, a_n \),数列中每个元素都是正整数,且满足 \( a_i = a_{i-1} + a_{i-2} \) 对于所有\( i \geq 3 \)。

如果 \( a_1 = 1 \) 且 \( a_2 = 1 \),请找出数列的第 \( n \) 项。

解答:根据题意,这是一个斐波那契数列。

第 \( n \) 项的值可以通过递归关系计算得出。

对于 \( n \) 的值,可以使用以下递归公式:\[ a_n = a_{n-1} + a_{n-2} \]其中,\( a_1 = 1 \) 和 \( a_2 = 1 \)。

因此,数列的前几项为 1, 1, 2, 3, 5, 8, 13, 21, ...。

对于任意的 \( n \),可以通过递归或动态规划方法计算出 \( a_n \)。

# 题目二:组合问题问题描述:从 \( n \) 个不同的元素中选择 \( k \) 个元素的所有可能组合的个数是多少?解答:这个问题可以通过组合数学中的二项式系数来解决。

从 \( n \) 个不同元素中选择 \( k \) 个元素的组合数 \( C(n, k) \) 可以用以下公式计算:\[ C(n, k) = \frac{n!}{k!(n-k)!} \]其中,\( n! \) 表示 \( n \) 的阶乘。

# 题目三:几何问题问题描述:在一个直角坐标系中,给定三个点 \( A(x_1, y_1) \),\( B(x_2, y_2) \) 和 \( C(x_3, y_3) \)。

如果 \( \overrightarrow{AB} \) 和 \( \overrightarrow{AC} \) 是垂直的,求证 \( A \) 是直角三角形 \( ABC \) 的直角顶点。

解答:如果 \( \overrightarrow{AB} \) 和 \( \overrightarrow{AC} \) 垂直,那么它们的数量积(点积)应该为零。

Acm试题及答案

Acm试题及答案

Acm试题及答案1001 Sum Problem (2)1089 A+B for In put-Output Practice (I) (3)1090 A+B for In put-Output Practice (II) (4)1091 A+B for In put-Output Practice (III) (6)1092 A+B for Input-Output Practice (IV) (7)1093 A+B for In put-Output Practice (V) 9 1094 A+B for In put-Output Practice (VI) (11)1095 A+B for Input-Output Practice (VII) (12)1096 A+B for In put-Output Practice (VIII) (14)2000 ASCII 码排序 (15)2001计算两点间的距离 (16)2002计算球体积 (17)2003求绝对值 (18)2004成绩转换 (19)2005第几天? (20)2006求奇数的乘积 (22)2007平方和与立方和 (23)2008数值统计 (24)2009求数列的和 (25)2010水仙花数 (27)2011多项式求和 (28)2012素数判定 (29)2014青年歌手大奖赛—评委会打分 (31)2015偶数求和 (32)2016数据的交换输出 (34)2017字符串统计 (35)2019数列有序! (37)2020绝对值排序 (38)2021发工资咯:) (40)2033人见人爱A+B (41)2039三角形 (43)2040亲和数 (44)1001 Sum ProblemProblem Descripti onHey, welcome to HDOJ(Ha ngzhou Dianzi Uni versity On li ne Judge).In this problem, your task is to calculate SUM( n) = 1 + 2 + 3 + ... + n.In putThe in put will con sist of a series of in tegers n, one in teger per line.OutputFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit sig ned in teger.Sample In put1100Sample Output15050AuthorDOOM III解答:#i nclude<stdio.h>main (){int n , i , sum;sum =0;while (( scanf ("%d",& n)!=- 1)){sum =0;for (i =0; i <=n; i ++)sum +=i ;printf ("%d\n\n" , sum);}1089 A+B for In put-O utput Practice(I)Problem Descripti onYour task is to Calculate a + b.Too easy?! Of course! I specially desig ned the problem for acm beg inn ers.You must have found that some problems have the same titles with this one, yes, all these problems were desig ned for the same aim.In putThe in put will con sist of a series of pairs of in tegers a and b, separated by a space, one pair of in tegers per line.OutputFor each pair of in put in tegers a and b you should output the sum of a and b in one line, and with one line of output for each line in in put.Sample In put1 510 20Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int while printf a , b;(scanf ("%d%d",& a,& b)!= EOF) ("%d\n" , a+b);1090 A+B for In put-Output Practice(II)Problem Descripti onYour task is to Calculate a + b.In putIn put contains an in teger N in the first line, and the n N lines follow. Each line con sists of a pair of in tegers a and b, separated by a space, one pair of in tegers per line.OutputFor each pair of in put in tegers a and b you should output the sum of a and b in one line, and with one line of output for each line in in put.Sample In put21 510 20Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>#defi ne M 1000void mai n (){int a , b, n, j [ M], i ;//prin tf("please in put n:\n");scanf ("%d",& n);for (i =0; i <n; i ++){scanf ("%d%d",& a,& b);//prin tf("%d %d",a,b);j [ i ]= a+b;}i =0;while{ printf iprintf }}(i <n)("%d" , j [ i ]); ++;("\n");1091 A+B for In put-Output Practice (III)Problem Descripti onYour task is to Calculate a + b.In putIn put contains multiple test cases. Each test case contains a pair of in tegers a and b, one pair of in tegers per line. A test case containing 0 0 term in ates the in put and this test case is not to be processed.OutputFor each pair of in put in tegers a and b you should output the sum of a and b in one line, and with one line of output for each line in in put.Sample In put1 510 200 0Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int a , b;scanf ("%d %d",& a,& b); while (!( a==0&&b==0)){printf ("%d\n" , a+b);scanf ("%d %d",& a,&b);}}1092 A+B for Input-Output Practice (IV)Problem Descripti onYour task is to Calculate the sum of some in tegers.In putIn put contains multiple test cases. Each test case contains a in teger N, and the n N in tegers follow in the same line. A test case start ing with 0 term in ates the in put and this test case is not to be processed.OutputFor each group of in put in tegers you should output their sum in one line, and with one line of output for each line in in put.Sample In put4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecomme ndJGShi ning解答:#i nclude <stdio.h>int mai n (){int n , sum, i , t ;while (scanf ("%d" ,&n)!= EOF&&n!= 0){sum =0;for (i =0; i <n; i ++){scanf ("%d",& t);sum =sum+t ;("%d\n" , sum);} printf}1093 A+B for In put-Output Practice (V)Problem Descripti onYour task is to calculate the sum of some in tegers.In putIn put contains an in teger N in the first line, and the n N lines follow. Each line starts with a in teger M, and then M integers follow in the same line.OutputFor each group of in put in tegers you should output their sum in one line, and with one line of output for each line in in put.Sample In put24 1 2 3 45 1 2 3 4 5Sample Output1015Authorlcy解答:#i nclude<stdio.h>main (){int n , a, b, i , j , sum;sum =0;while ( scanf ("%d\n" ,& n)!=- 1){for (i =0; i <n; i ++){scanf ("%d",& b);for (j =0; j <b; j ++){scanf ("%d",& a);sum +=a;printf ("%d\n",sum);sum =0;}}}1094 A+B for Input-Output Practice(VI)Problem Descripti onYour task is to calculate the sum of some in tegers.In putIn put contains multiple test cases, and one case one line. Each case starts with an in teger N, and then N integers follow in the same line.OutputFor each test case you should output the sum of N in tegers in one line, and with one line of output for each line in in put.Sample In put4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int n , a, b, i , j , sum;sum =0;while ( scanf ("%d\n" ,& n)!=- 1) {for (j =0; j <n; j ++){scanf ("%d",& a);sum +=a;}printf ("%d\n" , sum);sum =0;}}1095 A+B for Input-Output Practice (VII)Problem Descripti onYour task is to Calculate a + b.In putThe in put will con sist of a series of pairs of in tegers a and b, separated by a space, one pair of in tegers per line.OutputFor each pair of in put in tegers a and b you should output the sum of a and b, and followed by a bla nk line.Sample In put1 510 20Sample Output630AuthorlcyRecomme ndJGShi ning解答:#i nclude<stdio.h>main (){int a , b;while (scanf ("%d%d",& a,& b)!= EOF)printf ("%d\n\n" , a+b);}1096 A+B for In put-Output Practice(VIII)Problem Descripti onYour task is to calculate the sum of some in tegers.In putIn put contains an in teger N in the first line, and the n N lines follow. Each line starts with a in teger M, and then M integers follow in the same line.OutputFor each group of in put in tegers you should output their sum in one line, and you must note that there is a bla nk line betwee n outputs.Sample In put34 1 2 3 4Sample Output10156AuthorlcyRecomme ndJGShi ning 解答:int mai n (){a , b, i , j , l [ 1000], k;intscanf ("%d",& i );getchar ();for (j =1; j <=i ; j ++)l [ j ]= 0;for (j =1; j <=i ; j ++){scanf ("%d",& a);getchar ();for ( k=1; k<=a; k++){scanf ("%d",& b);getchar ();l [j]+=b;}}for (j =1; j <=i - 1; j ++)printf ("%d\n\n" , l [ j ]);printf ("%d\n" , l [ i ]);}2000 ASCII码排序Problem Descripti on输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

ACM竞赛试题(英文)

ACM竞赛试题(英文)
The jail area is a rectangle contains n×m little grids, each grid might be one of the following:
1) Empty area, represented by a capital letter ‘S’.
The larger the battery is, the more energy it can save. But larger battery means more weight and higher probability of being found by the weight sensor. So Micheal#1 needs to make his battery as small as possible, and still large enough to hold all energy he need. Assuming that the size of the battery equals to maximum units of energy that can be saved in the battery, and Micheal#1 is fully charged at the beginning, Please tell him the minimum size of the battery needed for his Prison break.
Output
For each test case, you should output just a number K indicating the minimum time (in minutes) Lily needed to finish her illusion magic.

ACM选拔测试题(学生版)

ACM选拔测试题(学生版)

----------------------------精品word 文档 值得下载 值得拥有---------------------------------------------- 1. 座位调整问题问题题目描述:公司办公区里到处摆放着各种各样的零食。

人力资源部的调研发现,员工如果可以在自己喜欢的美食旁边工作,工作效率会大大提高。

因此,公司决定进行一次员工座位的大调整。

调整的方法如下:1 . 首先将办公区按照各种零食的摆放分成 N 个不同的区域。

(例如:可乐区,饼干区,牛奶区等等)。

2 . 每个员工对不同的零食区域有不同的喜好程度(喜好程度度的范围为 1 — 100 的整数, 喜好程度越大表示该员工越希望被调整到相应的零食区域)。

3 . 由于每个零食区域可以容纳的员工数量有限,人力资源部希望找到一个最优的调整方案令到总的喜好程度最大。

数据输入:第一行包含两个整数 N , M ,( 1<=N , M<=300 )。

分别表示 N 个区域和 M 个员工。

第二行是 N 个整数构成的数列 a ,其中 a[i] 表示第 i 个区域可以容纳的员工数, (1<=a[i]<=M , a[1]+a[2]+..+a[N]=M) 。

紧接着是一个 M*N 的矩阵 P , P ( i , j )表示第 i 个员工对第 j 个区域的喜好度。

答案输出:对于每个测试数据,输出可以达到的最大的喜好程度。

测试数据:2. 投资问题问题描述:假设有m 元钱,n 项投资,函数()i f x 表示将x 元投入第i 个项目所产生的效益;问如何分配这m 元钱,使得投资的总效益达到最大?(C/C++程序实现)测试数据:5万元钱,4个项目,效益函数如下表所示测试要求:1. 时间2个小时,用C或C++编写程序;2. 可以携带C语言或C++方面的书;----------------------------精品word文档值得下载值得拥有----------------------------------------------。

acm大学生程序试题及答案

acm大学生程序试题及答案

acm大学生程序试题及答案1. 题目:字符串反转描述:给定一个字符串,编写一个函数来将字符串中的字符按相反的顺序重新排列。

输入:一个字符串输出:反转后的字符串答案:```pythondef reverse_string(s):return s[::-1]```2. 题目:寻找最大数描述:给定一个整数数组,找出数组中的最大数。

输入:一个整数数组输出:数组中的最大数答案:```pythondef find_max(nums):return max(nums)```3. 题目:两数之和描述:给定一个整数数组和一个目标值,找出数组中和为目标值的两个数的索引(从1开始计数)。

输入:一个整数数组和一个目标值输出:两个数的索引,如果没有则返回空数组答案:```pythondef two_sum(nums, target):num_to_index = {}for i, num in enumerate(nums):complement = target - numif complement in num_to_index:return [num_to_index[complement] + 1, i + 1] num_to_index[num] = ireturn []```4. 题目:无重复字符的最长子串描述:给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。

输入:一个字符串输出:最长子串的长度答案:```pythondef length_of_longest_substring(s):char_map = {}start = max_length = 0for end in range(len(s)):if s[end] in char_map:start = max(start, char_map[s[end]] + 1)char_map[s[end]] = endmax_length = max(max_length, end - start + 1)return max_length```5. 题目:整数转罗马数字描述:将一个整数转换为罗马数字。

蓝桥杯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试题及答案试题 1: 给定一个整数数组,请找出数组中第二大的数。

答案:1. 对数组进行排序。

2. 数组排序后,倒数第二个元素即为第二大的数。

试题 2: 编写一个函数,计算给定字符串中字符出现的次数。

答案:```pythondef count_characters(s):count_dict = {}for char in s:if char in count_dict:count_dict[char] += 1else:count_dict[char] = 1return count_dict```试题 3: 判断一个数是否为素数。

答案:1. 如果数小于2,则不是素数。

2. 从2开始到该数的平方根,检查是否有因数。

3. 如果没有因数,则该数是素数。

试题 4: 实现一个算法,将一个整数数组按照奇数在前,偶数在后的顺序重新排列。

答案:```pythondef rearrange_array(arr):odd = []even = []for num in arr:if num % 2 == 0:even.append(num)else:odd.append(num)return odd + even```试题 5: 给定一个链表,删除链表的倒数第n个节点。

答案:1. 遍历链表,找到链表的长度。

2. 再次遍历链表,找到倒数第n个节点的前一个节点。

3. 将前一个节点的next指针指向当前节点的下一个节点。

4. 如果当前节点是头节点,则更新头节点。

试题 6: 编写一个函数,实现字符串反转。

答案:```pythondef reverse_string(s):return s[::-1]```试题 7: 给定一个整数数组,找出数组中没有出现的最小正整数。

答案:1. 遍历数组,使用哈希表记录出现的数字。

2. 从1开始,检查每个数字是否在哈希表中。

3. 第一个不在哈希表中的数字即为答案。

试题 8: 实现一个算法,计算斐波那契数列的第n项。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
如果先发投手没有投完5局,而在被替补时得分领先,并且一直保持到终场,则胜利投手属于“最起作用”的替补投手,即第一个上场的替补投手。
在本题中,投手必须在本队防守的半局刚开始的时候被换下。
如果对这些规则不是很清楚,请参见下面的样例和样例解释。
Input
输入包含多组数据。每组数据第一行是一个整数N(9<=N<=20),表示这场比赛的局数。N=0表示输入结束。随后有两行,每行包含N个整数。第一行的第i个数表示第i局客队的得分(不超过20),第二行对应表示主队的得分。如果这个半局没有进行,用’X’表示。接下来的一行有两个整数A和B(1<=A,B<=10),分别表示客队和主队上场的投手人数。然后是A行,每行有一个字符串和一个整数,分别表示依上场顺序给出的客队的投手名字(由字母组成,保证没有空格,不超过20个字符),以及他被替换下场时的局数(局数从1算起)。如果他没有被替换下场,则用’E’表示。最后是B行,表示客队的投手信息。
败战投手从客队中产生。Peavy是先发,他投完的时候是3-3打平,不符合败战投手的条件。而Owings只上来投了一局,投完的时候球队4-3领先,也不符合败战投手的条件。最后上场的Rivera也只投了1局丢了2分,正是这2分使球队输球。易验证Rivera符合败战投手的条件。
Owings被换下时,比分情况为:
先发投手不管投多少局,只要在被替补时比分落后,而且之后本队到终场为止都从未把比分扳平或领先,球队因而失利时,记这名先发投手为败战投手。
投完整场比赛(没有被替补)的投手如果球队获胜,就是胜利投手;如果失利,就是败战投手。
在比赛的任何时刻,只要比分相等,就相当于重新争夺胜负,前面已经被换下的投手就不可能是胜利投手或者败战投手。
,输出两行。第一行包含胜利投手的名字,第二行包含败战投手的名字,格式参考样例输出。
Sample Input
9
2 0 0 0 0 1 1 0 0
0 2 0 0 1 0 0 2 X
3 2
Peavy 6
Owings 7
如果一名替补投手在场上的任何时刻,本队比分落后或打平,而他退场时比分领先并且一直保持到终场(或投完比赛剩下的局数没有退场,而终场时比分领先),记这名替补投手为胜利投手。
如果一名替补投手在场上的任何时刻,本队比分打平或领先,而他退场时比分落后并且一直保持到终场(或投完比赛剩下的局数没有退场,而终场时比分落后),记这名替补投手为败战投手。
2 0 0 0 0 1 1
0 2 0 0 1 0
客队4-3领先
Win: Owings
Lose: Wang
Hint
主队5-4击败客队,因此胜利投手从主队中产生。Santana是该队的先发投手,刚好投完了5局,而且退场的时候球队3-2领先。不过后来球队比分被扳平(然后又被反超),因此Santana不是胜利投手。而Wang则符合胜利投手的条件:他上场时候第6局马上就丢了一分,球队这时和对方3-3打平。而他投完了剩余比赛,最终球队也获胜。因此胜利投手是Wang。
在棒球运动中,投手通常是一个队最重要的球员。一名投手的好坏可以直接决定一场比赛的胜负,因此,对每一场棒球比赛,需要各找出一名胜利投手和一名败战投手。确定胜败投的规则如下:
如果先发投手(每队的第一名投手)投完5局或以上,而且在被替补时得分领先,替补后直至比赛结束为止一直保持领先(不曾被追平或者落后过),球队因而胜利时,记这名先发投手为胜利投手。
Winner and Loser
Time Limit: 1000 ms Memory Limit: 65535 kB
Solved: 1 Tried: 13
Description
棒球是美国的国球,是一项集力量、智慧于一体的运动。在棒球比赛中,两只球队轮流进攻,防守的一方有9名球员,其中负责向击球员投球的人称为投手,而进攻方的球员轮流试图用球棒将投手投出的球击打出去,并且争取跑垒得分。双方各进攻一次的过程叫一局,一方进攻一次叫做一个半局。一场棒球比赛通常进行9局,如果9局之后双方得分相同,就进入1局定胜负的延长赛,直到分出胜负为止。先进攻的一方是这场比赛的客队。如果第9局的上半局结束以后,客队仍然落后,则比赛胜负已定,不进行第9局的下半局比赛。比赛中可以替换球员,不过和足球类似,被替换下场的球员将不可以再上场。
Rivera E
Santana 6
Wang E
9
2 0 0 0 0 1 1 0 0
0 2 0 0 1 0 0 0 0
3 2
Peavy 6
Owings 7
Rivera E
Santana 6
Wang E
0
Sample Output
Win: Wang
Lose: Rivera
相关文档
最新文档