ACM题目

合集下载

大学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数学竞赛试题通常涉及各种数学领域,包括但不限于代数、几何、概率统计和组合数学等。

以下是一些经典的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程序设计东北林业大学陈宇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大赛原题目

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协会内部测试

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程序设计大赛试题

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

整理出ACM所有题目及答案

整理出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大学生程序设计试题

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相匹配的子串。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 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中的元素。

相关文档
最新文档