acm 学校海选题目

试题1:【旋转矩阵】

问题描述数学上有一种矩阵叫旋转矩阵,非常的有意思,所谓旋转矩阵,就是在N阶矩阵中,起始数1置于方阵的左上角,然后从起始数开始依次递增,按顺时针方向从外向里旋转填数而成。

【输入】输入文件名“matrix.in

输入文件由一行或多行构成,每行由一个正整数N组成,(N不大于100)。输入文件的最后一行是‘#’表示文件结束。。

【输出】输出文件名“estdout.pc2

对于每一组数据,输出一个N阶的旋转矩阵。两组输出之间不要额外的空行。矩阵中同一行的数字用一个空格分开。

程序运行后结果示例:

【样例输入】

5

#

【样例输出】

1  2  3  4 5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 12 11 10 9

试题2:【单词问题】

【问题描述】

给出一个完整的句子,这个句子中不包含不可见字符或者空格,于是在这个句子中有许多不同的单词。一个单词是指一串连续的最长的英文字母(大写或小写)。例如"#abc#","abc"就是一个单词,而"ab","bc"都不算单词。 

【输入】输入文件名“word.in

输入一个句子,只包含可见字符(不包含空格)。句子长度不超过 100。 

【输出】输出文件名“estdout.pc2

按单词出现的顺序输出不同的单词。如果一个单词出现多次则只有第一次出现时输出。

程序运行后结果示例:

【样例输入】

Wa_Study_Wa_Everyday_Wa_Daxia

【样例输出】

Wa

Study

Everyday

Daxia

试题3:罗马数字

【问题描述】

古罗马帝国开创了辉煌的人类文明,但他们的数字表示法的确有些繁琐,尤其在表示大数的时候,现在看起来简直不能忍受,所以在现代很少使用了。之所以这样,不是因为发明表示法的人的智力的问题,而是因为一个宗教的原因,当时的宗教禁止在数字中出现0的概念!

罗马数字的表示主要依赖以下几个基本符号:

I  1

    V  5

    X  10

    L  50

    C  100

    D  500

    M  1000

这里,我们只介绍一下1000以内的数字的表示法。

单个符号重复多少次,就表示多少倍。最多重复3次。比如:CCC表示300  XX表示20,但这个规则仅适用于I X C M150并不用LLL表示。

如果相邻级别的大单位在左,小单位在右,表示大单位加上小单位,如XI表示11;如果相邻级别的大单位在右,小单位在左,表示大单位中扣除小单位。比如:IX表示9IV表示XL表示40,更多的示例参见下表,你找到规律了吗?

I,1 
II2
III3
IV4
V5
VI6
VII7
VIII,8
IX
X10
XI11
XII12
XIII,13
XIV,14
XV,15
XVI,16
XVII,17
XVIII,18
XIX,19
XX,20
XXI,21
XXII,22
XXIX,29
XXX,30
XXXIV,34
XXXV,35
XXXIX,39
XL,40
L,50
LI,51
LV,55
LX,60
LXV,65
LXXX,80
XC,90
XCIII,93
XCV,95
XCVIII,98
XCIX,99
C,100
CC,200
CCC,300
CD,400
D,500
DC,600
DCC,700
DCCC,800
CM,900
CMXCIX,999

【输入】输入文件名“RomanNumber.in

第一行是整数n,表示接下来有n个罗马数字(n<100)。以后每行一个罗马数字。罗马数字大小不超过999

【输出】输出文件名“estdout.pc2

 要求程序输出n行,就是罗马数字对应的十进制数据。

程序运行后结果示例:

【样例输入】

3

LXXX

XCIII

DCCII

【样例输出】

80

93

702

试题4:【最大区域】

二值图像是由黑白两种像素组成的矩形点阵,图像识别的一个操作是求出图像中最大黑区域的面积。请设计一个程序完成二值图像的这个操作。黑区域由黑像素组成,一个黑区域中的每个像素至少与该区域中的另一个像素相邻,规定一个像素仅与其上、下、左、右的像素相邻。两个不同的黑区域没有相邻的像素。一个黑区域的面积是其所包含的像素的个数。

【输入】输入文件名“area.in

输入由多个测试例组成。每个测试例的第一行含两个整数nm, (1 <=n,m<=100), 分别表示二值图像的行数与列数,后面紧跟着n行,每行含m个整数01,其中第i行表示图像的第i行的m个像素,0表示白像素,1表示黑像素。同一行的相邻两个整数之间用一个空格隔开,两个测试例之间用一个空行隔开,最后一个测试例之后隔一个空行,再接的一行含有两个整数0,标志输入的结束。

【输出】输出文件名“estdout.pc2

每个测试例对应一行输出,含一个整数,表示相应的图像中最大黑区域的面积。

程序运行后结果示例:

【样例输入】

5 6

0 1 1 0 0 1

1 1 0 1 0 1

0 1 0 0 1 0

0 0 0 1 1 1

1 0 1 1 1 0

4 6

0 1 1 0 0 1

1 1 1 1 0 1

0 1 0 1 1 0

0 0 0 1 1 1

0 0

【样例输出】

7

12

试题5:【选拔志愿者】

重庆理工大学要选拔一批志愿者参加一项重要的活动。

参加志愿者选拔的同学们排队接受面试官们的面试。参加面试的同学们按照先来先面试并且先结束的原则接受面试官们的考查。

面试中每个人的人品是主要考查对象之一。(提高人品的方法有扶老奶奶过街,不闯红灯等)

作为主面试官的John想知道当前正在接受面试的同学队伍中人品值最高的是多少。于是他请你帮忙编写一个程序来计算。 

【输入】输入文件名“selection.in

输入数据第一行为一整数T,表示有T组输入数据。 

每组数据第一行为”START”,表示面试开始

接下来的数据中有三种情况:

输入

含义

C  NAME RP_VALUE

名字为NAME的人品值为RP_VALUE的同学加入面试队伍。(名字长度不大于50 <= RP_VALUE <= 1,000,000,000)

G

排在面试队伍最前面的同学面试结束离开考场。

Q

主面试官John想知道当前正在接受面试的队伍中人品最高的值是多少。

最后一行为”END”,表示所有的面试结束,面试的同学们可以依次离开了。

所有参加面试的同学总人数不超过1,000,000

【输出】输出文件名“estdout.pc2

对于每个询问Q,输出当前正在接受面试的队伍中人品最高的值,如果当前没有人正在接受面试则输出-1。 

程序运行后结果示例:

【样例输入】

2

START

C Tiny 1000000000

C Lina 0

Q

G

Q

END

START

Q

C ccQ 200

C cxw 100

Q

G

Q

C wzc 500

Q

END

 

【样例输

1000000000

0

-1

200

100

500

试题6:【数字游戏】

丁丁最近沉迷于一个数字游戏之中。这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易。游戏是这样的,在你面前有一圈整数(一共n个),你要按顺序将其分为m个部分,各部分内的数字相加,相加所得的m个结果对10取模后再相乘,最终得到一个数k。游戏的要求是使你所得的k最大或者最小。
例如,对于下面这圈数字(n=4m=2):
 
当要求最小值时,((2-1) mod 10)×((4+3) mod 10)=1×7=7,要求最大值时,为((2+4+3) mod 10)×(-1 mod 10)=9×9=81。特别值得注意的是,无论是负数还是正数,对10取模的结果均为非负值。

丁丁请你编写程序帮他赢得这个游戏。

【输入】输入文件名“game.in

输入文件第一行有两个整数,n1≤n≤50)和m1≤m≤9)。以下n行每行有个整数,其绝对值不大于104,按顺序给出圈中的数字,首尾相接。

【输出】输出文件名“estdout.pc2

输出文件有两行,各包含一个非负整数。第一行是你程序得到的最小值,第二行是最大值。

【样例输入】

4 2

4

3

-1

2

【样例输

7

81

试题7:【Is It A Tree? 

A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties.

   1. There is exactly one node, called the root, to which no directed edges point.

   2. Every node except the root has exactly one edge pointing to it.

   3. There is a unique sequence of directed edges from the root to each node. 

For example, consider the illustrations below, in which nodes are represented by circles and edges are represented by lines with arrowheads. The first two of these are trees, but the last is not.

In this problem you will be given several descriptions of collections of nodes connected by directed edges. For each of these you are to determine if the collection satisfies the definition of a tree or not.

Input

The input will consist of a sequence of descriptions (test cases) followed by a pair of negative integers. Each test case will consist of a sequence of edge descriptions followed by a pair of zeroes Each edge description will consist of a pair of integers; the first integer identifies the node from which the edge begins, and the second integer identifies the node to which the edge is directed. Node numbers will always be greater than zero.

Output

For each test case display the line "Case k is a tree." or the line "Case k is not a tree.", where k corresponds to the test case number (they are sequentially numbered starting with 1).

Sample InputInput filename:“trees.in”

6 8  5 3  5 2  6 4

5 6  0 0

8 1  7 3  6 2  8 9  7 5

7 4  7 8  7 6  0 0

3 8  6 8  6 4

5 3  5 6  5 2  0 0

-1 -1

Sample OutputOutput filename:“estdout.pc2”

Case 1 is a tree.

Case 2 is a tree.

Case 3 is not a tree.

试题8:【Coconuts, Revisited 

The short story titled Coconuts, by Ben Ames Williams, appeared in the Saturday Evening Post on October 9, 1926. The story tells about five men and a monkey who were shipwrecked on an island. They spent the first night gathering coconuts. During the night, one man woke up and decided to take his share of the coconuts. He divided them into five piles. One coconut was left over so he gave it to the monkey, then hid his share and went back to sheep.

Soon a second man woke up and did the same thing. After dividing the coconuts into five piles, one coconut was left over which he gave to the monkey. He then hid his share and went back to bed. The third, fourth, and fifth man followed exactly the same procedure. The next morning, after they all woke up, they divided the remaining coconuts into five equal shares. This time no coconuts were left over.

An obvious question is "how many coconuts did they originally gather?" There are an infinite number of answers, but the lowest of these is 3,121. But that's not our problem here.

Suppose we turn the problem around. If we know the number of coconuts that were gathered, what is the maximum number of persons (and one monkey) that could have been shipwrecked if the same procedure could occur?

Input

The input will consist of a sequence of integers, each representing the number of coconuts gathered by a group of persons (and a monkey) that were shipwrecked. The sequence will be followed by a negative number.

Output

For each number of coconuts, determine the largest number of persons who could have participated in the procedure described above. Display the results similar to the manner shown below, in the Expected Output. There may be no solution for some of the input cases; if so, state that observation.

Sample InputInput filename:“Coconuts.in”

25

30

3121

-1

Sample OutputOutput filename:“estdout.pc2”

25 coconuts, 3 persons and 1 monkey

30 coconuts, no solution

3121 coconuts, 5 persons and 1 monkey

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值