ACM题目
大学ACM考试题目及作业答案整理
ACM作业与答案整理1、平面分割方法:设有n条封闭曲线画在平面上,而任何两条封闭曲线恰好相交于两点,且任何三条封闭曲线不相交于同一点,问这些封闭曲线把平面分割成的区域个数。
#include <iostream.h>int f(int n){if(n==1) return 2;else return f(n-1)+2*(n-1);}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}2、LELE的RPG难题:有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.编程全部的满足要求的涂法.#include<iostream.h>int f(int n){if(n==1) return 3;else if(n==2) return 6;else return f(n-1)+f(n-2)*2;}void main(){int n;while(1){cin>>n;cout<<f(n)<<endl;}}3、北大ACM(1942)Paths on a GridTime Limit: 1000MS Memory Limit: 30000K DescriptionImagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b2). So you decide to waste your time with drawing modern art instead.Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left:Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?InputThe input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.OutputFor each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right orone unit up? You may safely assume that this number fits into a 32-bit unsigned integer.Sample Input5 41 10 0Sample Output1262#include<iostream>using namespace std;longlong f(long long m, long long n){if(n==0) return 1;else return f(m-1,n-1)*m/n;}int main(){longlongm,n;while(scanf("%I64d %I64d",&n,&m) &&n+m){printf("%I64d\n",f(m+n,min(m,n)));}return 0;}1、(并查集)若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系。
acm数学竞赛试题
acm数学竞赛试题
ACM数学竞赛试题通常涉及各种数学领域,包括但不限于代数、几何、概率统计和组合数学等。
以下是一些经典的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程序设计东北林业大学陈宇Lg_chenyu@第一讲算法原理和ACM入门(Introduction to ACM)我校的ACM在线评测系统**课件下载地址:*/kj/suanfa01.ppt预期赛事(今后每年)*3~4月,举行校内大赛(暨选拔赛)*4月,ACM全国邀请赛*5月,参加黑龙江省大学生程序设计大赛*6月,参加东北4省大学生程序设计大赛*10~11月,参加ACM/ICPC亚洲区比赛(至少参加4~5个赛区的比赛)*另外,每学期至少有三次月赛以及适当的练习赛第一部分算法概述*算法分析(Algorithm Analysis):对算法所需要的两种计算机资源——时间和空间进行估算;时间复杂性(Time Complexity)空间复杂性(Space Complexity)算法分析的目的:设计算法——设计出复杂性尽可能低的算法选择算法——在多种算法中选择其中复杂性最低者算法的描述语言:⑴自然语言优点:容易理解缺点:冗长、二义性使用方法:粗线条描述算法思想注意事项:避免写成自然段(2)流程图优点:流程直观缺点:缺少严密性、灵活性使用方法:描述简单算法注意事项:注意抽象层次⑶程序设计语言优点:能由计算机执行缺点:抽象性差,对语言要求高使用方法:算法需要验证注意事项:将算法写成子函数(4)伪代码——算法语言伪代码(Pseudocode):介于自然语言和程序设计语言之间的方法,它采用某一程序设计语言的基本语法,操作指令可以结合自然语言来设计。
优点:表达能力强,抽象性强,容易理解评价算法*评价算法的三条主要标准是:*(1) 算法实现所耗费的时间;*(2) 算法实现所所耗费的存储空间,其中*主要考虑辅助存储空间;*(3) 算法应易于理解,易于编码,易于调*试等等。
和算法执行时间相关的因素:1)问题中数据存储的数据结构2)算法采用的数学模型3)算法设计的策略4)问题的规模5)实现算法的程序设计语言6)编译算法产生的机器代码的质量7)计算机执行指令的速度算法效率的衡量方法*通常有两种衡量算法效率的方法:*1)事后统计法(有缺点,较少使用)*2)事前分析估算法*算法的时间效率是问题规模的函数。
ACM大赛原题目
一Network of SchoolsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 4526 Accepted: 1776 DescriptionA number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (the “receiving schools”). Note that ifB is in the distribution list of school A, then A does not necessarily appear in the list of school BYou are to write a program that computes the minimal number of schools that must receive a copy of the new software in order for the software to reach all schools in the network according to the agreement (Subtask A). As a further task, we want to ensure that by sending the copy of new software to an arbitrary school, this software will reach all schools in the network. To achieve this goal we may have to extend the lists of receivers by new members. Compute the minimal number of extensions that have to be made so that whatever school we send the new software to, it will reach all other schools (Subtask B). One extension means introducing one new member into the list of receivers of one school.InputThe first line contains an integer N: the number of schools in the network (2 <= N <= 100). The schools are identified by the first N positive integers. Each of the next N lines describes a list of receivers. The line i+1 contains the identifiers of the receivers of school i. Each list ends with a 0. An empty list contains a 0 alone in the line.OutputYour program should write two lines to the standard output. The first line should contain one positive integer: the solution of subtask A. The second line should contain the solution of subtask B.Sample Input52 43 04 5 01 0Sample Output12二Remmarguts' DateTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 10811 Accepted: 2944 Description"Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story."Prince Remmarguts lives in his kingdom UDF – United Delta of Freedom. One day their neighboring country sent them Princess Uyuw on a diplomatic mission.""Erenow, the princess sent Remmarguts a letter, informing him that she would come to the hall and hold commercial talks with UDF if and only if the prince go and meet her via the K-th shortest path. (in fact, Uyuw does not want to come at all)"Being interested in the trade development and such a lovely girl, Prince Remmarguts really became enamored. He needs you - the prime minister's help!DETAILS: UDF's capital consists of N stations. The hall is numbered S, while the station numbered T denotes prince' current place. M muddy directed sideways connect some of the stations. Remmarguts' path to welcome the princess might include the same station twice or more than twice, even it is the station with number S or T. Different paths with same length will be considered disparate.InputThe first line contains two integer numbers N and M (1 <= N <= 1000, 0 <= M <= 100000). Stations are numbered from 1 to N. Each of the following M lines contains three integer numbers A, B and T (1 <= A, B <= N, 1 <= T <= 100). It shows that there is a directed sideway from A-th station to B-th station with time T.The last line consists of three integer numbers S, T and K (1 <= S, T <= N, 1 <= K <= 1000).OutputA single line consisting of a single integer number: the length (time required) to welcome Princess Uyuw using the K-th shortest path. If K-th shortest path does not exist, you should output "-1" (without quotes) instead.Sample Input2 21 2 52 1 41 2 2Sample Output14三ChessboardTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 7406 Accepted: 2306 DescriptionAlice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in the figure below).We call a grid, which doesn’t contain a hole, a normal grid. Bob has to follow the rules below:1. Any normal grid should be covered with exactly one card.2. One card should cover exactly 2 normal adjacent grids.Some examples are given in the figures below:A VALID solution.An invalid solution, because the hole of red color is covered with a card.An invalid solution, because there exists a grid, which is not covered.Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.InputThere are 3 integers in the first line: m, n, k (0 < m, n <= 32, 0 <= K < m * n), the number of rows, column and holes. In the next k lines, there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.OutputIf the board can be covered, output "YES". Otherwise, output "NO".Sample Input4 3 22 13 3Sample OutputYES四RSATime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 2583 Accepted: 490DescriptionRSA is the best-known public key encryption algorithm. In this algorithm each participant has a private key that is shared with no one else and a public key which is published so everyone knows it. To send a secure message to this participant, you encrypt the message using the widely known public key; the participant then decrypts the messages using his or her private key. Here is the procedure of RSA:First, choose two different large prime numbers P and Q, and multiply them to get N (= P * Q).Second, select a positive integer E (0 < E < N) as the encryption key such that E and T= (P - 1) * (Q - 1) are relatively prime.Third, compute the decryption key D such that 0 <= D < T and (E * D) mod T = 1. Here D is a multiplicative inverse of E, modulo T.Now the public key is constructed by the pair {E, N}, and the private key is {D, N}. P and Q can be discarded.Encryption is defined by C = (M ^ E) mod N, and decryption is defined by M = (C ^ D) mod N, here M, which is a non-negative integer and smaller than N, is the plaintext message and C is the resulting ciphertext.To illustrate this idea, let’s see the following example:We choose P = 37, Q = 23, So N = P * Q = 851, and T = 792. If we choose E = 5, D will be 317 ((5 * 317) mod 792 = 1). So the public key is {5, 851}, and the privatekey is {317, 851}. For a given plaintext M = 7, we can get the ciphertext C = (7 ^ 5) mod 851 = 638.As we have known,for properly choosen very large P and Q, it will take thousands of years to break a key, but for small ones, it is another matter.Now you are given the ciphertext C and public key {E, N}, can you find the plaintext M?InputThe input will contain several test cases. Each test case contains three positive integers C, E, N (0 < C < N, 0 < E < N, 0 < N < 2 ^ 62).OutputOutput the plaintext M in a single line.Sample Input638 5 851Sample Output7五A New Operating SystemTime Limit: 20000MS Memory Limit: 65536KTotal Submissions: 669 Accepted: 49Case Time Limit: 5000MSDescriptionMay is a lovely girl. Due to her filial piety, she wants to give a present on hermother's birthday. Because both her parents are the top programmer in the world, she decided to design a new program, a special program that is an Operating System! With the help of her excellent programming skill, May has already finished the kernel of the new OS. And the birthday is coming, she is afraid that time is not enough to finish the entire project in time. As her best net-pal, it's your duty to help her.This is a multitask OS, processes run at the same time. There are following command in the OS:CreateProcess(PID,Memory,Priority)A new process is created with the process identification PID and memory size, and a priority. The priority in this command is called outer priority of a process.AddMessage(PID,Priority)That means, add a new message to the message queue of process PID, with the priority of Priority. The message with higher Priority will run earlier that lower ones. The Priority is called inner priority.RunFind out the message with biggest HP. HP is defined as the product of the inner priority of a message and the corresponding process priority. If two or more messages have the same HP, the one with smallest PID will run first. Print the information "Run: HP" to the output file, HP will be replaced by the message HP you found, or print "Empty" instead if the message queue is empty. Finally remove this message if exist.ChangePriority(PID,NewValue)Change the outer priority of process PID to NewValue.GetMemory(PID,Memory)Process PID memory increases the amount of Memory.FreeMemory(PID,Memory)Process PID memory decreases the amount of Memory.RunProcess(PID)Similar with Run command. Find out the message in the process PID message queue, print the information "Run Process: Priority" to the output file, Priority will be replaced by the message priority you found, or print "Empty" instead if the messagequeue is empty. Finally remove this message if exist.CloseMaxMemoryFind out the process that used the largest number of memory and close it if exists (if tie, the one with smallest PID should be release first), or print "Empty" instead.CloseProcess(PID)Close the process with the identification of PID.Whenever a process' memory is less than or equal to 0, it will be close automatically. In any of the above commands except the first one, if the PID doesn't exist, please print an "Error" to the output. For the first command, if the PID is already exist, print an "Error" and ignore this command.InputFirst line in the input is an integer number N (1 <= N <= 100000), which represents the number of commands. The next N lines, each gives a command described above. Any number given in the input file will be non-negative integer and will not be more than 1000000000.OutputThe output format has been described above.Sample Input11CloseMaxMemoryCreateProcess(1,100,1)CreateProcess(2,200,1)CreateProcess(3,300,1)AddMessage(1,9)AddMessage(2,19)AddMessage(1,10)GetMemory(2,999)CloseMaxMemoryRunRunProcess(1)Sample OutputEmptyRun: 10Run Process: 9六A New Kind of ChessTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 245 Accepted: 42DescriptionPrince Remmarguts met Uyuw successfully in our previous story, and after that Princess Uyuw introduced a new kind of chess to Remmarguts named Nixgnauhc. The only chessman allowed in it was a special type of Knight.The chessboard is of (N + 1) * (M + 1). Each of the rows and columns are numbered as the following graph:Here N + 1 = 5 + 1 is the number of rows and M + 1 = 4 + 1 is the number of columns. We are also given two integer numbers P and Q, and told that at the beginning of the game, the blocks of (x, y) - (row number, column number) - where x <= P and y <= Q are already taken up by Knight.During the game, we can choose a single Knight to move, and the only allowed movements for Knight at (x, y) is to (x + a, y + b) or to (x + c, y + d). But during the movement, the position it goes must be on the chessboard and NOT be taken up by another Knight. Our purpose is to move that chessman to the final end (N, M). (The description above means that once you choose a chessman, you can only move that chessman in the following steps)Meanwhile, we suppose 3 <= N, M <= 100000, 0 <= P < N, 0 <= Q < M, 1<= a, b, c, d. Princess Uyuw wanted to know the number of essentially different games. Two games are called “different” if and only if we choose the different chessman at the beginning or perform a different movement at some time.WARNING: Even if a = c, b = d, we also call (+a, +b) and (+c, +d) DIFFERENT movements!InputYou should read the number of test cases Z in the first line – Z <= 100.Each of the following lines denotes a single test case, consisting of 8 integers N, M, P, Q, a, b, c, and d. The meanings of such integers are described above.OutputOutput one line per test case, showing the total possibilities of games. We guarantee this number is less than 10^500.Sample Input23 3 0 0 1 1 1 15 4 2 1 1 1 2 1Sample Output87七An Easy ProblemTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6197 Accepted: 3631 DescriptionAs we known, data stored in the computers is in binary form. The problem we discuss now is about the positive integers and its binary form.Given a positive integer I, you task is to find out an integer J, which is the minimum integer greater than I, and the number of '1's in whose binary form is the same as that in the binary form of I.For example, if "78" is given, we can write out its binary form, "1001110". This binary form has 4 '1's. The minimum integer, which is greater than "1001110" and also contains 4 '1's, is "1010011", i.e. "83", so you should output "83".InputOne integer per line, which is I (1 <= I <= 1000000).A line containing a number "0" terminates input, and this line need not be processed. OutputOne integer per line, which is J.Sample Input123478Sample Output245883八Uyuw's ConcertTime Limit: 6000MS Memory Limit: 65536KTotal Submissions: 3177 Accepted: 1240 DescriptionPrince Remmarguts solved the CHESS puzzle successfully. As an award, Uyuw planned to hold a concert in a huge piazza named after its great designer Ihsnayish.The piazza in UDF - United Delta of Freedom’s downtown was a square of [0, 10000] * [0, 10000]. Some basket chairs had been standing there for years, but in a terrible mess. Look at the following graph.In this case we have three chairs, and the audiences face the direction as what arrows have pointed out. The chairs were old-aged and too heavy to be moved. Princess Remmarguts told the piazza's current owner Mr. UW, to build a large stage inside it. The stage must be as large as possible, but he should also make sure the audience in every position of every chair would be able to see the stage without turning aside (that means the stage is in the forward direction of their own).To make it simple, the stage could be set highly enough to make sure even thousands of chairs were in front of you, as long as you were facing the stage, you would be able to see the singer / pianist – Uyuw.Being a mad idolater, can you tell them the maximal size of the stage?InputIn the first line, there's a single non-negative integer N (N <= 20000), denoting the number of basket chairs. Each of the following lines contains four floating numbers x1, y1, x2, y2, which means there’s a basket chair on the line segment of (x1, y1) –(x2, y2), and facing to its LEFT (That a point (x, y) is at the LEFT side of this segment means that (x – x1) * (y – y2) – (x – x2) * (y – y1) >= 0).OutputOutput a single floating number, rounded to 1 digit after the decimal point. This is the maximal area of the stage.Sample Input310000 10000 0 500010000 5000 5000 100000 5000 5000 0Sample Output54166666.7九Knight MovesTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 15129 Accepted: 6765 DescriptionBackgroundMr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fast. Can you beat him?The ProblemYour task is to write a program to calculate the minimum number of moves needed for a knight to reach one point from another, so that you have the chance to be faster than Somurolov.For people not familiar with chess, the possible knight moves are shown in Figure 1.InputThe input begins with the number n of scenarios on a single line by itself.Next follow n scenarios. Each scenario consists of three lines containing integer numbers. The first line specifies the length l of a side of the chess board (4 <= l <= 300). The entire board has size l * l. The second and third line contain pair of integers {0, ..., l-1}*{0, ..., l-1} specifying the starting and ending position of the knight on the board. The integers are separated by a single blank. You can assume that the positions are valid positions on the chess board of that scenario.OutputFor each scenario of the input you have to calculate the minimal amount of knight moves which are necessary to move from the starting point to the ending point. If starting point and ending point are equal,distance is zero. The distance must be written on a single line.Sample Input380 07 01000 030 50101 11 1十Equal Sum PartitionsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 297 Accepted: 214DescriptionAn equal sum partition of a sequence of numbers is a grouping of the numbers (in the same order as the original sequence) in such a way that each group has the same sum. For example, the sequence:2 5 13 3 7may be grouped as:(2 5) (1 3 3) (7)to yield an equal sum of 7.Note: The partition that puts all the numbers in a single group is an equal sum partition with the sum equal to the sum of all the numbers in the sequence.For this problem, you will write a program that takes as input a sequence of positive integers and returns the smallest sum for an equal sum partition of the sequence.InputThe first line of input contains a sin gle integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed bya decimal integer M, (1 ≤ M ≤ 10000), giving the total number of integers in the sequence. The remaining line(s) in the dataset consist of the values, 10 per line,separated by a single space. The last line in the dataset may contain less than 10 values.OutputFor each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the smallest sum for an equal sum partition of the sequence.Sample Input31 62 5 13 3 72 61 2 3 4 5 63 201 12 1 1 2 1 1 2 11 2 1 1 2 1 1 2 1 1Sample Output1 72 213 2如果有想要答案的朋友,请给我留言!。
ACM题目、测试用例及参考答案汇编——一次ACM协会内部测试
ACM题目、测试用例及参考答案汇编——一次ACM协会内部测试第一题:梦境是虚幻吗?时间限制:3000ms 内存限制:65535KB 难度:★★描述《盗梦空间》是一部精彩的影片,在这部电影里,Cobb等人可以进入梦境之中,梦境里的时间会比现实中的时间过得快得多,这里假设现实中的3分钟,在梦里就是1小时。
然而,Cobb他们利用强效镇静剂,可以从第一层梦境进入第二层梦境,甚至进入三层,四层梦境,每层梦境都会产生同样的时间加速效果。
那么现在给你Cobb在各层梦境中经历的时间,你能算出现实世界过了多长时间吗?比如,Cobb先在第一层梦境待了1个小时,又在第二层梦境里待了1天,之后,返回第一层梦境之后立刻返回了现实。
那么在现实世界里,其实过了396秒(6.6分钟)输入第一行输入一个整数T(0<=T<=100),表示测试数据的组数。
每组测试数据的第一行是一个数字M(3<=M<=100)随后的M行每行的开头是一个字符串,该字符串如果是"IN" 则Cobb向更深层的梦境出发了,如果是字符串"OUT"则表示Cobb从深层的梦回到了上一层。
如果是首字符串是"STAY"则表示Cobb在该层梦境中停留了一段时间,本行随后将是一个整数S表示在该层停留了S分钟(1<=S<=10000000)。
数据保证在现实世界中,时间过了整数秒。
输出对于每组测试数据,输出现实世界过的时间(以秒为单位)。
样例输入16INSTAY 60INSTAY 1440OUTOUT样例输出396测试输入106INSTAY 60INSTAY 1440OUTOUT6INININOUTOUTOUT7INININSTAY 0 OUTOUTOUT2INSTAY 203INSTAY 0 OUT3INSTAY 10 OUT4INSTAY 10 STAY 10 OUT5INSTAY 20 STAY 20 OUT STAY 120 10INSTAY 20 STAY 20 INSTAY 1440STAY 1440OUTSTAY 120OUTSTAY 11STAY 50测试输出39660306073209723000参考代码:#include<stdio.h>int main(){int n;char a[5];scanf("%d",&n);while(n--){int m,i,b=1,c,time=0;scanf("%d",&m);for(i=0;i<m;i++){scanf("%s",&a);if(a[0]=='I') b*=20;else if(a[0]=='S') {scanf("%d",&c);time+=c*60/b;} else if(a[0]=='O') b/=20;}printf("%d\n",time);}return 0;}第二题:独木舟过河时间限制:3000ms 内存限制:65535KB 难度:★★描述进行一次独木舟的旅行活动,独木舟可以在港口租到,并且之间没有区别。
acm程序设计大赛试题
acm程序设计大赛试题题目:旅游管理系统一、问题描述随着信息技术的飞速发展,旅游业作为全球经济的重要组成部分,其管理和服务水平也在不断提升。
为了更好地服务游客,提高工作效率,我们计划开发一个旅游管理系统。
该系统旨在帮助旅游公司管理客户信息、行程安排、预订情况以及费用结算等业务。
本文将详细介绍该系统的设计要求和功能特点。
二、功能需求1. 客户信息管理系统应能够记录客户的基本信息,包括姓名、联系方式、身份证号码等。
同时,应支持对客户信息的增加、修改和查询功能。
此外,系统还应具备客户信息的分类和统计功能,便于旅游公司对客户群体进行分析。
2. 行程安排旅游公司需要根据客户需求和旅游资源情况,为客户制定合适的旅游行程。
系统应提供行程规划功能,包括景点选择、活动安排、住宿和交通预订等。
同时,系统应能够根据实际情况调整行程,并及时更新相关信息。
3. 预订管理系统应能够处理客户的旅游预订,包括景点门票、酒店房间、交通工具等。
预订管理功能应包括预订的创建、修改、取消和确认等操作,并能够实时更新预订状态,确保信息的准确性。
4. 费用结算旅游费用的结算是旅游管理系统的核心功能之一。
系统应能够根据客户的预订情况和实际消费,自动计算应付费用。
同时,系统还应支持多种支付方式,如信用卡、支付宝、微信支付等,并能够生成详细的费用清单和发票。
5. 数据安全与备份鉴于旅游管理系统中涉及大量敏感信息,系统必须具备严格的数据安全措施。
包括但不限于用户权限管理、数据加密、防止SQL注入等。
此外,系统还应定期进行数据备份,以防数据丢失或损坏。
三、系统架构设计1. 前端设计系统的前端设计应注重用户体验,界面友好、操作简便。
可以使用HTML5、CSS3和JavaScript等技术开发响应式网页,以适应不同设备和屏幕尺寸。
同时,前端应提供丰富的交互功能,如日历选择、地图展示、图片上传等。
2. 后端设计后端设计主要负责处理业务逻辑、数据存储和安全保障。
整理出ACM所有题目及答案
1000 A + B ProblemProblem DescriptionCalculate A + B .InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2AuthorHDOJ代码:#include<stdio.h>int main(){int a , b;while( scanf ( "%d %d" ,& a,& b)!= EOF)printf( "%d\n" , a+b);}1001 Sum ProblemProblem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.InputThe input will consist of a series of integers n, one integer 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 signed integer.Sample Input1100Sample Output15050AuthorDOOM III解答:#include<stdio.h>main (){int n , i , sum;sum =0;while (( scanf ( "%d" ,& n)!=- 1)) {sum for =0;( i =0; i <= n; i ++)sum +=i ;printf( "%d\n\n" , sum);}}1002 A + B Problem IIProblem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2Sample OutputCase 1:1+2=3Case 2:Author代码:#include <stdio.h>#include <string.h>int main (){char str1 [ 1001 ], str2 [ 1001 ];int t , i , len_str1 , len_str2 , len_max , num = 1 , k ; scanf ( "%d" , & t );getchar ();while ( t --){int a [ 1001 ] = { 0}, b [1001]={ 0}, c [1001]={ 0};scanf ( "%s" , str1 );len_str1 = strlen ( str1 );for ( i = 0 ; i <= len_str1 - 1;++ i )a [ i ] = str1 [ len_str1 - 1 - i ] - '0' ;scanf ( "%s" , str2 );len_str2 = strlen ( str2 );for ( i = 0 ; i <= len_str2 - 1;++ i )b [ i ] = str2 [ len_str2 - 1 - i ] - '0' ;if ( len_str1 > len_str2 )len_max = len_str1 ;elselen_max = len_str2 ;k = 0 ;for ( i = 0 ; i <= len_max - 1 ;++ i ){c [ i ] = ( a[ i ] + b [ i ] + k ) % 10 ;k = ( a[ i ] + b [ i ] + k ) / 10 ;}if ( k != 0 )c [ len_max ] = 1 ;printf ( "Case %d:\n" , num );num ++;printf ( "%s + %s = " , str1 , str2 );if ( c[ len_max ] == 1 )printf ( "1" );for ( i = len_max - 1 ; i >= 0 ;-- i ){printf ( "%d" , c [ i ]);}printf ( "\n" );if ( t >= 1 )printf ( "\n" );}return 0 ;}1005 Number Sequence Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.OutputFor each test case, print the value of f(n) on a single line.Sample Input1 1 312100 0 0Sample Output25AuthorCHEN, ShunbaoSourceRecommendJGShining代码:#include<stdio.h>int f [ 200 ];int main (){int a , b, n, i ;while ( scanf ( "%d%d%d" ,& a,& b,& n)&& a&&b&&n){if ( n>= 3){f [ 1]= 1; f [ 2]= 1;for ( i =3; i <= 200 ; i ++){f [ i ]=( a* f [ i - 1]+ b* f [ i - 2])% 7;if ( f [ i - 1]== 1&&f [ i ]== 1)break ;}i -= 2;n =n%i ;if ( n== 0)printf ( "%d\n" , f [ i ]);elseprintf ( "%d\n" , f [ n]);}elseprintf ( "1\n" );}return 0 ;}1008 ElevatorProblem DescriptionThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevatorup one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.InputThere are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.OutputPrint the total time on a single line for each test case.Sample Input1 23231Sample Output1741AuthorZHENG, JianqiangSourceRecommendJGShining代码:#include<stdio.h>int a [ 110 ];int main(){int while { sum , i , n;( scanf ( "%d" ,& n)&& n!= 0)forscanf ( i =1; i <= n; i ++)( "%d" ,& a[ i ]);sum a for=0;[ 0]= 0;( i =1; i <= n; i ++){ifsum ( a[ i ]> a[ i - 1])+=6*( a[ i ]- a[ i - 1]);elsesum +=4*( a[ i - 1]- a[ i ]);sum +=5;printf ( "%d\n" , sum);}return 0 ;}1009 FatMouse' TradeProblem DescriptionFatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.InputThe input consists of multiple test cases. Each test case begins with a line containing two non-negative integersM and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test caseis followed by two -1's. All integers are not greater than 1000.OutputFor each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.Sample Input53724352203251824151510-1-1Sample OutputAuthorCHEN, YueSourceRecommendJGShining代码:#include<stdio.h>#include<string.h>#define MAX 1000int main(){int i,j,m,n,temp;int J[MAX],F[MAX];double P[MAX];double sum,temp1;scanf("%d%d",&m,&n);while(m!=-1&&n!=-1){sum=0;memset(J,0,MAX*sizeof(int));memset(F,0,MAX*sizeof(int));memset(P,0,MAX*sizeof(double));for(i=0;i<n;i++){ scanf("%d%d",&J[i],&F[i]); P[i]=J[i]*1.0/((double)F[i]); }for(i=0;i<n;i++){for(j=i+1;j<n;j++){if(P[i]<P[j]){temp1=P[i];P[i]=P[j];P[j]=temp1;temp=J[i]; J[i]=J[j]; J[j]=temp; temp=F[i];F[i]=F[j]; F[j]=temp;} }}for(i=0;i<n;i++) { if(m<F[i]){ else{sum+=m/((double)F[i])*J[i];sum+=J[i];break;m-=F[i];} }}printf("%.3lf\n",sum); scanf("%d%d",&m,&n); }return 0; }1021 Fibonacci AgainProblem DescriptionThere are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).InputInput consists of a sequence of lines, each containing an integer n. (n < 1,000,000).OutputPrint the word "yes" if 3 divide evenly into F(n). Print the word "no" if not.Sample Input0 1 2 3 4 5Sample Outputno no yes no no noAuthorLeojayRecommendJGShining#include<stdio.h> int main () { long while if printfn ;( scanf ( "%ld" ,& n) !=( n%8==2 || n %8==6) ( "yes\n" ); EOF ) elseprintf ( "no\n");return0 ;}1089 A+B for Input-Output Practice (I)Problem DescriptionYour task is to Calculate a + b.Too easy?! Of course! I specially designed the problem for acm beginners.You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.OutputFor each pair of input integers 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 input.Sample Input151020Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h>main (){int a , b;while( scanf ( "%d%d" ,& a,& b)!=EOF)printf( "%d\n" , a+b);}1090 A+B for Input-Output Practice (II)Problem DescriptionYour task is to Calculate a + b.InputInput contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.OutputFor each pair of input integers 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 input.Sample Input2151020Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h>#define M 1000void main (){int a , b, n, j [ M], i ;//printf("please input n:\n");scanf( "%d" ,& n);for( i =0; i <n; i ++){scanf( "%d%d" ,& a,& b);//printf("%d %d",a,b);j[ i ]= a+b;}i=0;while( i <n){printf( "%d" , j [ i ]);i++;printf( "\n" );}}1091 A+B for Input-Output Practice(III) Problem DescriptionYour task is to Calculate a + b.InputInput contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line.A test case containing 0 0 terminates the input and this test case is not to be processed.OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line ofoutput for each line in input.Sample Input15102000Sample Output630AuthorlcyRecommendJGShining解答:#include<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 DescriptionYour task is to Calculate the sum of some integers.InputInput contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input.。
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数学竞赛试题及答案# 题目一:数列问题问题描述:给定一个数列 \( 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试题题目:K-数组合时间限制:1.00秒内存限制:256MB【题目描述】给定一个长度为N的整数序列,所有的数都是不超过10^9的非负实数。
另外给定一个整数K(1 <= K <= N)。
现在要求找出序列中所有长度为K的数的组合,使得这些数的和不大于一个给定的值M(1 <= M <= 10^12)。
【输入格式】第一行包含三个整数N,K和M。
第二行包含N个长度为1的整数,表示序列中的数。
【输出格式】对于每个合法的组合,输出一行,格式为:x1 x2 ... xk其中x1, x2, ..., xk是序列中的数,并且按照从小到大的顺序排列。
如果存在多种组合,输出的顺序可以任意,但是任何一种合法的组合都至多只能输出一次。
【样例】输入样例1:5 3 10000001 2 3 4 5输出样例1:1 2 31 2 41 3 52 3 51 4 5输入样例2:5 2 101 2 3 4 5输出样例2:1 22 3【数据范围】对于100%的数据,1 <= N, K <= 10^5,1 <= M <= 10^12,序列中的数不大于10^9。
【提示】可以通过排序加双指针的方法来解决这个问题。
【参考代码】```pythondef main():N, K, M = map(int, input().split())nums = list(map(int, input().split()))nums.sort() # 排序results = set() # 存储结果,避免重复for i in range(N - K + 1):subset = nums[i:i+K]if sum(subset) <= M:results.add(tuple(subset))for result in sorted(results):print(' '.join(map(str, result)))if __name__ == '__main__':main()```【解题思路】本题是一个典型的组合问题,要求我们找出所有满足条件的子集。
acm基础试题及答案
acm基础试题及答案1. 题目:给定一个整数数组,请找出数组中第二大的数。
答案:我们可以使用排序的方法,将数组从小到大排序,然后数组中的倒数第二个数就是第二大的数。
或者使用一次遍历的方法,首先初始化两个变量,一个用来存储最大值,一个用来存储第二大的值。
遍历数组,每次比较当前元素与最大值,如果当前元素大于最大值,则更新第二大的值为最大值,并将当前元素赋给最大值;如果当前元素小于最大值但大于第二大的值,则更新第二大的值。
2. 题目:实现一个函数,计算一个字符串中字符出现的次数。
答案:可以使用哈希表来实现,遍历字符串中的每个字符,将其作为键值对存储在哈希表中,键是字符,值是该字符出现的次数。
遍历结束后,哈希表中存储的就是每个字符出现的次数。
3. 题目:给定一个链表,删除链表的倒数第n个节点,并且返回新的链表头节点。
答案:可以使用双指针的方法,首先初始化两个指针,都指向链表的头节点。
然后移动第一个指针,移动n步,此时第一个指针指向倒数第n个节点的前一个节点。
接着同时移动两个指针,直到第一个指针到达链表的末尾,此时第二个指针指向的节点就是需要删除的节点的前一个节点。
然后更新第二个指针的next指针,使其指向第二个指针的next节点的next节点,最后返回链表的头节点。
4. 题目:编写一个函数,判断一个整数是否是回文数。
回文数是指正序和倒序读都一样的数。
答案:首先将整数转换为字符串,然后使用双指针的方法,一个指针从字符串的开始位置,一个指针从字符串的结束位置,向中间移动。
如果两个指针指向的字符不相等,则该整数不是回文数。
如果遍历结束后没有发现不相等的字符,则该整数是回文数。
5. 题目:给定一个字符串,找出其中不含有重复字符的最长子串的长度。
答案:可以使用滑动窗口的方法,维护一个哈希表记录窗口内字符的出现情况,以及一个变量记录不含有重复字符的最长子串的长度。
遍历字符串,每次移动窗口的右端点,如果当前字符不在窗口内,则更新最长子串的长度,并将字符添加到哈希表中。
2022南开大学acm竞赛题目及答案
2022南开大学acm竞赛题目及答案第一部分理论题(总分100分,考试时间:60分钟)一、选择题(单选,共30题,每个2分)1、下面关于变量及其作用范围的陈述哪个是不对的?()A.实例变量是类的成员变量。
B.实例变量用关键字static声明。
//Static 声明的是类变量C.在方法中定义的局部变量在该方法被执行时创建。
D.局部变量在使用前必须被初始化。
2、下面哪条语句把方法声明为抽象的公共方法?()A.public abstract method();B.public abstract void method();C.public abstract void method(){}D.public void method() extends abstract;3、哪个是将一个十六进制值赋值给一个long型变量?()A.long number = 345L;B.long number = 0345;C.long number = 0345L;D.long number = 0x345L;4、下面的哪个赋值语句是不对的?()A.float f = 11.1;B.double d = 5.3E12;C.double d = 3.14159;D.double d = 3.14D;5、main方法是Java Application程序执行的入口点,关于main 方法的方法头以下哪项是合法的()。
A、public static void main()B、public static void main(String[ ] args)C、public static int main(String[ ] args)D、public void main(String arg[ ])6、在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数个数、类型或顺序各不相同,传回的值也可以不相同。
这种面向对象程序的特性称为()。
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大学生程序试题及答案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题目
输入一个字符串,判断其是否是C的合法标识符。
Input输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
Output对于每组输入数据,输出一行。
如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
Sample Input312ajffi8x_aff ai_2Sample Outputnoyesno对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
Input输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。
Output对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入"(max)"。
Sample InputabcdefgfedcbaxxxxxSample Outputabcdefg(max)fedcbax(max)x(max)x(max)x(max)x(max)统计每个元音字母在字符串中出现的次数。
Input输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。
Output对于每个测试实例输出5行,格式如下:a:num1e:num2i:num3o:num4u:num5多个测试实例之间由一个空行隔开。
请特别注意:最后一块输出后面没有空行:)Sample Input2aeioumy name is ignatiusSample Outputa:1e:1i:1o:1u:1a:2e:1i:3o:0u:1求n个数的最小公倍数。
Input输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。
你可以假设最后的输出是一个32位的整数。
ACM题库完整版
if(str[i]>='a'&&str[i]<='z') { str[i]=str[i]-32; } i++;
} puts(str); return 0; }
日历问题
1.题目描述 在我们现在使用的日历中, 闰年被定义为能被4整除的年份,但是能被100整除而不能被400整除的年 是例外,它们不是闰年。例如:1700, 1800, 1900 和 2100 不是闰年,而 1600, 2000 和 2400是闰年。 给定从公元2000年1月1日开始逝去的天数,你的任务是给出这一天是哪年哪月哪日星期几。 2.输入 输入包含若干行,每行包含一个正整数,表示从2000年1月1日开始逝去的天数。输入最后一行是?1, 不必处理。可以假设结果的年份不会超过9999。 3.输出 对每个测试样例,输出一行,该行包含对应的日期和星期几。格式为“YYYY-MM-DD DayOfWeek”, 其中 “DayOfWeek” 必须是下面中的一个: "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" 或 "Saturday“。 4.样例输入 1730 1740 1750 1751 -1 5.样例输出 2004-09-26 Sunday 2004-10-06 Wednesday 2004-10-16 Saturday 2004-10-17 Sunday 6.提示 2000.1.1. 是星期六
ACM练习题
ACM练习题(1)描述浙江工商大学校园里绿树成荫,环境非常舒适,因此也引来一批动物朋友来此居住。
童心未泯的redraiment就经常带些碎面包什么的去广场喂鸽子和兔子,并和它们玩耍。
一点也不像大学生,还是一副老不正经的样子,呵呵。
随着鸽子和兔子数目的增多,redraiment带的那点食物已经不够它们瓜分了。
为了能让自己的好朋友吃的饱饱的,redraiment决定统计一下有多少只鸽子和有多少只兔子,以便带来足够的食物。
一、二、三、四、五...他开始数了。
现在,他已经知道有这些鸽子和兔子一共有n个头和m只脚。
请你帮他写个程序计算一下一共有多少只鸽子和兔子。
输入输入包括多组数据。
每行包括2个数据:n、m(代表上面题目中提到的意思1≤n, m≤230)。
n、m都是整数。
输入以0 0作为结束。
输出每组数据的输出都只有一行,分别是鸽子的数量和兔子数量。
如果输入的测试数据不能求得结果,那肯定是redraiment这个马大哈数错了,就输出"Error"提示他。
样例输入35 941 30 0样例输出23 12Error(2)念数字时间限制(普通/Java):1000MS/10000MS 运行内存限制:65536KByte总提交: 727 测试通过: 316描述编一个“念数字”的程序,它能让计算机完成以下工作:当你输入一个0至99 之间的数后,计算机就会用汉语拼音印出这个数。
如果输入的数不在0到99 之间,就印出“CUO LE”。
注:为了使不熟悉汉语拼音的同学也能做这个题,把“零,一,二,三,……,九,十”的拼音法写在下面。
零LING 一YI 二ER 三SAN 四SI 五WU六LIU 七QI 八BA 九JIU 十SHI输入输入数据有多组,每组数据占一行,内容为一个数字,数据以EOF作为结束。
输出输出对应的汉语拼音,字母全部为大写。
每组数据占一行样例输入3511100样例输出SAN SHI WULINGSHI YICUO LE(3)University时间限制(普通/Java):1000MS/10000MS 运行内存限制:65536KByte总提交: 698 测试通过: 304描述在大学里,很多单词都是一词多义,偶尔在文章里还要用引申义。
ACM典型试题--简单的加密算法(一)
ACM典型试题--简单的加密算法(⼀)1. 题⽬描述简单的加密算法:把字符串中的字符替换成另外的字符,只有对⽅知道如何替换就可以解密。
要求根据给定的加密⽅法和密⽂,得到原始消息。
输⼊格式第⼀⾏输⼊密钥,第⼆⾏输⼊密⽂。
输出格式对输⼊的数据输出解密后的原始信息。
输⼊样例eydbkmiqugjxlvtzpnwohracsfKifq oua zarxa suar bti yaagrj fa xtfgrj输出样例Jump the fence when you seeing me coming2. 题⽬分析和算法实现第⼀⾏的“eydbkmiqugjxlvtzpnwohracsf”相当于密钥,含义是a 对应e、b 对应y、c 对应d…。
因此,只要把密⽂序列中的相应字符替换为对应后⾯的字符即可。
即对于“Kifq oua zarxa suar bti yaagrj fa xtfgrj”,把K 替换成J,把i 替换成u,把f 替换成m,…。
但要注意⼤⼩写。
编程的时候,可以定义数组表⽰密钥。
然后对密⽂进⾏遍历得到原始信息。
3. 问题实现及代码分析#include <stdio.h>int main( void ){char codeKey[128],codeWord[100],Decode[100];printf("\n输⼊密钥26个字母:");for (int i='a';i<='z';i++){scanf("%c",&codeKey[i]);codeKey[i-32]=codeKey[i]-32;}codeKey[127]='\0';printf("\n输⼊密钥为:");for (int i='a';i<='z';i++){printf("%c",codeKey[i]);}printf("\n输⼊密⽂:");getchar();gets(codeWord);int j=0;while(codeWord[j]!='\0'){if (codeWord[j]==' '){Decode[j]=codeWord[j];}else{Decode[j]=codeKey[codeWord[j]];}++j;}Decode[j]='\0';printf("\n解密为:");puts(Decode);}4.结果。
ACM软件大赛之编程大赛题目(附部分答案)
ACM软件大赛之编程大赛比赛注意事项:●比赛时间为3小时(180分钟);比赛分两个阶段:第一阶段限时30分钟,完成公示的3题,第二阶段限时150分钟(事先完成第一阶段题目的小组可提前进入第二阶段);●比赛第一阶段的3道题目将在前期宣传中告知参赛选手,比赛第二阶段的题目将由赛事主席当场公布竞赛题目;●前两阶段题目分为三个分值(5分、10分、15分),第一阶段3道公示题都为5分;第二阶段总共15道题,根据不同的难度分值不同,分别为5道5分题,5道10分题,5道15分题;第一阶段参赛队员不可参考任何相关资料;第二阶段参赛队员可以携带诸如书,手册,程序清单等参考资料。
比赛过程中队员不得携带任何电子媒质的资料;参赛者可以选择自己擅长的语言(C,C++,JAVA等等)进行编写●考虑到大一和大二学生的知识掌握程度,大一参加选手一开始就会有10分的分数,最后总分是由所做题目及初始的10分相加得到。
●每组队员根据安排使用电脑,小组人数为两人的使用一台电脑,超过两人的使用两台电脑,每台的电脑配置完全相同;●各小组每做完一题或几题,必须交予评委老师运行,评委老师当场给分;●如在比赛中发现作弊等行为,将取消比赛资格。
第一阶段公示题目:题目一:(5分)打印以下图形,纵遵从字母顺序,行字符数遵从斐波那契数列ABCCDDDEEEEEFFFFFFFFGGGGGGGGGGGGG#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 time){int h=time/100;int m=time-100*h;return h<=12&&m<=59&&h>0?true:false;//12小时制}int main(){int time=0;int j(0);//总计数器while(time<1270){//max 12:59int t=time;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(time)){//cout<<n[3]<<n[2]<<":"<<n[1]<<n[0]<<"\n";//testj++;}time++;}cout<<"total: "<<j*2<<endl;}题目三:(5分)10进制的四位数中有几个符合如下特征:将其分别表示为16进制、10进制、12进制,在每种状态下,分别将各个位上的数相加,能得到3个相等10进制数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
【题目 1】N皇后问题(含八皇后问题的扩展,规则同八皇后):在N*N的棋盘上,放置N个皇后,要求每一横行
每一列,每一对角线上均只能放置一个皇后,问可能的方案及方案数。
【题目 2】排球队员站位问题
┏━━━━━━━━┓图为排球场的平面图,其中一、二、三、四、五、六为位置编号,┃ ┃二、三、四号位置为前排,一、六、五号位为后排。
某队比赛时,┃ ┃一、四号位放主攻手,二、五号位放二传手,三、六号位放副攻┠──┬──┬──┨手。
队员所穿球衣分别为1,2,3,4,5,6号,但每个队
┃ 四 │ 三 │ 二 ┃员的球衣都与他们的站位号不同。
已知1号、6号队员不在后排,┠──┼──┼──┨2号、3号队员不是二传手,3号、4号队员不在同一排,5号、┃ 五 │ 六 │ 一 ┃6号队员不是副攻手。
┗━━┷━━┷━━┛编程求每个队员的站位情况。
【算法分析】本题可用一般的穷举法得出答案。
也可用回溯法。
以下为回溯解法。
【题目 2】把自然数N分解为若干个自然数之和。
【参考答案】
n │ total
5 │ 7
6 │ 11
7 │ 15
10 │ 42
100 │ 190569291
【题目 3】把自然数N分解为若干个自然数之积。
【题目 4】马的遍历问题。
在N*M的棋盘中,马只能走日字。
马从位置(x,y)处出发,把棋盘的每一格都走一次,且只走一次。
找出所有路径。
【参考程序】 {深度优先搜索法}
【题目 5】加法分式分解。
如:1/2=1/4+1/4.找出所有方案。
输入:N MN为要分解的分数的分母
M为分解成多少项
【题目 6】地图着色问题
【题目 7】在n*n的正方形中放置长为2,宽为1的长条块,问放置方案如何
【题目 8】找迷宫的最短路径。
(广度优先搜索算法)
【题目 9】 把1-8这8个数放入下图8个格中,要求相邻的格(横,竖,对角线)上填的数不连续.
┌─┐
│①│
┌─┼─┼─┐
│②│③│④│
├─┼─┼─┤
│⑤│⑥│⑦│
└─┼─┼─┘
│⑧│
└─┘
【题目 10】 在4×4的棋盘上放置8个棋,要求每一行,每一列上只能放置2个.
【题目 11】迷宫问题.求迷宫的路径.(深度优先搜索法)
【题目 12】一笔画问题
从某一点出发,经过每条边一次且仅一次.(具体图见高级本P160)
【题目 13】城市遍历问题.
给出六个城市的道路连接图,找出从某一城市出发,遍历每个城市一次且仅一次的最短路径及其路程长度.(图见高级本P147}
【题目 14】棋子移动问题
【题目 15】求集合元素问题(1,2x+1,3X+1类)
某集合A中的元素有以下特征:
(1)数1是A中的元素
(2)如果X是A中的元素,则2x+1,3x+1也是A中的元素
(3)除了条件(1),(2)以外的所有元素均不是A中的元素。