tceic.com

# 大一ACM寒假20题

ACM 寒假 20 题
^_^o~ 加油，努力！

1

（1）例题
1001: A + B Problem (2) Description
Calculate a + b. a and b are integers.

Input
The input may contain several test cases. In each test case, there are two integers, a and b, separated by a space. Input is terminated by EOF.

Output
For each test case, print out the sum of a and b.

Sample Input
1 2 10 20 324 111

Sample Output
3 30 435

（2）题目讲解

2

（3）代码

01、1020: C 语言程序设计教程（第三版）课 后习题 1.6
Description

Input

Output
a b c 其中最大的数

Sample Input
10 20 30

Sample Output
30

02、1021: C 语言程序设计教程（第三版）课 后习题 3.7
Description

3

Input
China

Output

Sample Input
China

Sample Output
Glmre

03、1023: C 语言程序设计教程（第三版）课 后习题 4.9
Description

Input

Output

Sample Input
-40

Sample Output
c=-40.00

HINT

4

04、1028: C 语言程序设计教程（第三版）课 后习题 5.8
Description

Input

Output

Sample Input
900

Sample Output
90

HINT

5

05、1038: C 语言程序设计教程（第三版） 课后习题 6.10
Description

Input
N

Output

Sample Input
10

Sample Output
1534

06、1043: C 语言程序设计教程（第三版） 课后习题 7.4
Description

Input

Output

Sample Input
1 7 8 17 23 24 59 62 101
6

50

Sample Output
1 7 8 17 23 24 50 59 62 101

07、1052: C 语言程序设计教程（第三版）课 后习题 8.8
Description

Input

Output

Sample Input
1990

Sample Output
1 9 9 0

7

08、1058: C 语言程序设计教程（第三版） 课后习题 9.6
Description

Input

Output

Sample Input
0.618

Sample Output
0.62 0.62 0.62 0.62 0.62

0.62

09、1065: C 语言程序设计教程（第三版） 课后习题 10.5
Description

Input

Output

Sample Input
8

3

Sample Description

Input

Output

Sample Input
2000 12 31

Sample Output
366

Output
2

10、1067: C 语言程序设计教程（第三版）课 后习题 11.1
Description

Input

Output

Sample Input
2000 12 31

Sample Output
366

9

11、1006: 1-Norm Distance
Description
For two points with coordinates of (x1, y1) and (x2, y2), their 1-norm distance D1 is defined as: D1 = |x1 – x2| + |y1 – y2|. Calculate the 1-norm distance of any two given points (You should not use any mathematical function).

Input
Two lines, each line has two integers. The first line is x1 and y1; the second line is x2 and y2.

Output
The 1-norm distance between the two points.

Sample Input
1 1 2 2

Sample Output
2

12、1007: Sum of 1 to n
Description
Calculate 1 + 2 + 3 + ... + n (n is an integer, and 1 <= n <= 10000). If n<=0, print out “Error Input”, else print out the sum.

Input
There are multiple test cases. For each case, there is a line contains n which has been described above. Input is terminated by EOF.
10

Output
The result of 1 + 2 + 3 + ... + n.

Sample Input
8 100 -1 200

Sample Output
36 5050 Error Input 20100

13、1008: Closest Points
Description
Given a point p and a set of points S in 3-D coordinate system, the distance from p to S is defined as the Euclidean Distance from p to the closest point a in S. Write a program to find out the point in S from which is closest to p.

Input
The first line is three floating numbers, denoting the coordinates of p (x, y, z). The second line is an integer N (1<=N<=20), indicating that there are N pointers in S. Then the following N lines will show the 3-D coordinates of each point in S, one point on each line.

Output
The coordinates of the nearest point in S to p, denoting the coordinate in format of (x, y, z), and the distance, separating the coordinate and the distance by a space. Each output number must be formatted as a floating point number with exactly two digit after the decimal point.
11

Sample Input
1.1 3 4.2 1.0 5.0 2.0 3.0 5.0 6.0 3.1 4.0 6.0 1.0

Sample Output
(1.00 3.10 4.00) 1.49

14、1009: Median Value
Description
Figure out the median of a floating point number array. If the size of an array is an odd number, the median is the middle element after arranging all the array elements from lowest value to highest value; If there is an even number of elements, then there is no single middle value, so the median is the mean of the two middle values.

Input
The input may contain several test cases. The first line of each test case is an integer n (n >= 1), representing the size of the array. The second line of each test case contains all the elements in the array. Input is terminated by EOF.

Output
For each test case, output the median , which must be formatted as a floating point number with exactly two digit after the decimal point.

Sample Input
6 5.0 4.0 3.0 2.0 11.0 3.0 11 5.0 6.0 222.0 23.0 23.0 4.0 2.0 5.0 99.0 1.0 8.0
12

Sample Output
3.50 6.00

Description
There are some students’ grade records, in format of “name grade”. In order to make the teacher to view and manage all the records easily, you are asked to develop a program to sort the records first by grade (in descending order), and second by name (in alphabetic order). That means the sorted records will be from the highest grade to lowest grade; and if two students have the same grade, whose name appeared earlier in a dictionary will be shown earlier.

Input
8 grade records, one record on per line. Only letters and digits appear in the name of a student (i.e. there will be no space in a name). All grades are integers.

Output
The 8 sorted records, one record per line.

Sample Input
WangYi 90 LiMing 90 HuRui 50 ZhangLi 65 LiLei 80 ZhangFei 65 ZhaoSan 70 ChenZi 100

Sample Output
ChenZi 100 LiMing 90 WangYi 90
13

LiLei 80 ZhaoSan 70 ZhangFei 65 ZhangLi 65 HuRui 50

16、1012: Joseph Problem
Description
The Joseph's problem is notoriously known. From among n people, numbered 1, 2, . . ., n, standing in circle. Starting from sth and every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give us the message about the incident. For example when n = 6, s = 1 and m = 5, then the people will be executed in the order 5, 4, 6, 2, 3 and 1 will be saved. (1<= n <=20000, s>=1, m >=1)

Input
There are multiple test cases. For each case, there is a line contains three positive integers, n, s and m.. Input is terminated by EOF.

Output
For every test case, output a single line containing the number of the person who may be saved.

Sample Input
13 1 5 15 2 5

Sample Output
6 2

14

Description
A website requests its new user to register a user name before using it. A valid username should: (1) contain only letters (a~z, A~Z) and digits (0~9); (2) have neither less than 6 characters nor more than 10 characters (6 <= name length <= 10); and (3) start with a letter (a~z, A~Z). Please write a program to check whether a given string is a valid username or not.

Input
The input may contain several test cases. Each test case is one user name (i.e. a string). Input is terminated by EOF.

Output
For each test case, output “Valid” or “Invalid”.

Sample Input
Mary8912 Tom_cat

Sample Output
Valid Invalid

18、1075: Problem E – Steps
Description
One steps through integer points of the straight line. The length of a step must be nonnegative and can be by one bigger than, equal to, or by one smaller than the length of the previous step. What is the minimum number of steps in order to get from x to y? The length of the first and the last step must be 1.

15

Input consists of a line containing n, the number of test cases. For each test case, a line follows with two integers: 0 <= x <= y < 2^31. For each test case, print a line giving the minimum number of steps to get from x to y.

Sample Input
3 45 48 45 49 45 50

Sample Output
3 3 4

19、1076: Problem A: Freckles
Description
In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad's back to form a picture of the Liberty Bell. Alas, one of the freckles turns out to be a scar, so his Ripley's engagement falls through. Consider Dick's back to be a plane with freckles at various (x,y) locations. Your job is to tell Richie how to connect the dots so as to minimize the amount of ink used. Richie connects the dots by drawing straight lines between pairs, possibly lifting the pen between lines. When Richie is done there must be a sequence of connected lines from any freckle to any other freckle.

Input
The first line contains 0 < n <= 100, the number of freckles on Dick's back. For each freckle, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the freckle.

Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the freckles.

16

Sample Input
3 1.0 1.0 2.0 2.0 2.0 4.0

Sample Output
3.41

20、1074: Problem D – Snap
Description
Snap is a 2-player card game. The deck of cards contains several of each type of card. Initially each player has one half of the deck, in some random sequence, face down in a pile, and plays them in sequence from top to bottom, placing each card face-up in another pile. When the face-down pile is exhausted, the face-up pile is turned over to become the face-down pile and play continues. The two players play their cards concurrently and synchronously. That is, each places a card face up at exactly the same time. If two cards turned up at the same time are the same type, each player calls "Snap!" and the player who calls first takes the other's face-up pile and places it on top of his or her own. Play proceeds until one player has all the cards. This player is the winner. Your job is to simulate a game of snap to determine whether it will end within 1000 turns and, if so, to determine the winner.

Input
Each type of card is denoted by a single letter or digit. The first line of input Jane's initial pile of cards, from top to bottom. The second line of input is John's initial pile. Jane and John start with the same number of cards; not more than 50 each.

Output
During play, whenever it comes time to call "Snap!" the builtin function "random" is used to determine who calls first: if the expression

17

random()/141%2 random div 141 mod 2

{in C or C++} {in Pascal; see note below}

yields 0, Jane calls first; otherwise John calls first. Whenever Jane calls first, print "Snap! for Jane: " followed by Jane's face-up pile, from top to bottom. Whenever John calls first, print "Snap! for John: " followed by John's face-up pile. If the game ends, print "John wins." or "Jane wins.", whichever is appropriate. If the game does not end when each player has turned over 1000 cards, print "Keeps going and going ..."

Sample Input

Sample Output
Snap! for Jane: Snap! for Jane: Snap! for John: Snap! for John: John wins. BCBA DADCBCBA CBAC ADADCBAC

Source
waterloo

http://blog.csdn.net/New_C_YUER/article/category/816398，组合数学的题好多，可以跟 着他的顺序做。当然，等你学到一定程度也可以自己写 BLOG，交流、共享，IT 人的精神嘛~
18

19

### acm大赛介绍

ACM 国际大学生程序设计竞赛简介 ACM 国际大学生程序设计竞赛 (ACM/ICPC 或 ...开始后 1:00 和 2:45,B 队为 1:20 和 2:00,但 B 队有一题提交了 ...

### ACM 常用代码集

(m>20) { if(isprime(a[1]+a[20])) printresult(); return; } else ...ACM经典的题目代码 51页 2下载券 acm算法源代码 92页 1下载券喜欢...

### ACM上机测试题2

ACM上机测试题2_工学_高等教育_教育专区。ACMACM 上机测试题考试时间 考试要求先新建一个文件夹,并以自己的“班级+姓名”命名(如:计算 1001XXX) 。 在该文件夹...

### ACM实验报告

Cube = 20, Triple = (7,14,17) Cube = 24, Triple = (12,16,20) ...一些简单的ACM题 暂无评价 13页 2下载券 ACM入门 暂无评价 82页 2下载券 ...

### ACM程序设计大赛

ACM 程序设计大赛百科名片 2003 年的大赛活动现场 ACM 程序设计大赛是大学级别最...每一次提交运行结果 被判错误的话将被加罚 20 分钟时间,未正确解答的试题不记...

### ACM

ACM 2页 免费 acm 30页 2财富值 ACM 29页 5财富值 Acm题目 14页 1财富值 几个ACM题目 8页 免费 ACM第十章 19页 2财富值 ACM进阶 7页 20财富值 ACM...

### ACM入门试题Problem_Set

ACM入门试题Problem_Set_IT/计算机_专业资料。ACM入门试题Problem_SetA...输入规格: 第一行是一个整数 C,C<=20,紧接着 C 组数据,每组数据包含一行,...