ACM第四次比赛题目及标准程序(STL模板类)
欢迎访问XYNUOJ
题目A: 胜利大逃亡
时间限制: 2 Sec 内存限制: 33 MB题目描述
魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ignatius能否在魔王回来前离开城堡(只要走到出口就算离开城堡,如果走到出口的时候魔王刚好回来也算逃亡成功),如果可以请输出需要多少分钟才能离开,如果不能则输出-1.
输入
特别注意:本题的测试数据非常大,请使用scanf输入,我不能保证使用cin能不超时.在本OJ上请使用Visual C++提交.
输出
样例输入
1
3 3 4 20
0 1 1 1
0 0 1 1
0 1 1 1
1 1 1 1
1 0 0 1
0 1 1 1
0 0 0 0
0 1 1 0
0 1 1 0
样例输出
11
题目 B: 表达式求值
时间限制: 3 Sec 内存限制: 6 MB题目描述
实现输入一个表达式求出它的值的计算器,比如输入:“1+2/4=”,程序就输出1.50(结果保留两位小数)
输入
第一行输入一个整数n,共有n组测试数据(n<10)。 每组测试数据只有一行,是一个长度不超过1000的字符串,表示这个运算式,每个运算式都是以“=”结束。这个表达式里只包含+-*/与小括号这几种符号。其中小括号可以嵌套使用。数据保证输入的操作数中不会出现负数。 数据保证除数不会为0输出
每组都输出该组运算式的运算结果,输出结果保留两位小数。样例输入
2 1.000+2/4= ((1+2)*5+1)/4=
样例输出
1.50 4.00
题目 C:Train
时间限制: 1 Sec 内存限制: 33 MB
题目描述
As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2.
输入
The input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file. More details in the Sample Input.
输出
The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out" for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output.样例输入
3 123 321 3 123 312
样例输出
Yes. in in in out out out FINISH No. FINISH
题目 D: 情报分析
时间限制: 1 Sec 内存限制: 12 MB
题目描述
“八一三”淞沪抗战爆发后,*几次准备去上海前线视察和指挥作战。但都因为宁沪之间的铁路和公路遭到了敌军的严密封锁,狂轰滥炸,一直未能成行。 特科组织,其主要任务是保卫的安全,了解和掌握敌方的动向。经过一段时间的监听,谍报组获取了敌方若干份密报,经过分析,发现密文中频繁出现一些单词,情报人员试图从单词出现的次数中,推出敌军的行动计划。 请你编程,快速统计出频率高的前十个单词。
输入
密文是由英语单词(小写字母)组成,有若干段。单词之间由一个或多个空格分开,自然段之后可以用一个“,”或“。”表示结束。整个内容的单词数量不超过10000,不同的单词个数不超过500.
输出
输出占10行,每行一个单词及出现的次数,中间一个空格。要求按频率降序输出,出现次数相同的单词,按字典序输出。
样例输入
shooting is at shanghai station. shooting must be carried out. shooting shooting. shanghai station must be surrounded, at least a team of one hundred soldiers to fight. twenty five soldiers shooting in the north, twenty five soldiers shooting in the south, twenty five soldiers shooting in the east, twenty five soldiers shooting in the west.
样例输出
shooting 8 soldiers 5 five 4 in 4 the 4 twenty 4 at 2 be 2 must 2 shanghai 2
题目E: Information Sharing
时间限制: 3 Sec 内存限制: 65 MB
题目描述
There is going to be a test in the kindergarten. Since the kids would cry if they get a low score in the test, the teacher has already told every kid some information about the test in advance. But the kids are not satisfied with the information teacher gave. They want to get more. On the testing day, some kids arrived to the classroom early enough, and then shared his/her information with another. kids are honest, if A shares with B, B can get all the information A knows, so does A. At first the classroom is empty. As time pass by, a kid would arrive, or share information with other. However, the teacher hides somewhere, watching everything. She wants to know how much information some kid has gotten.
输入
There are multiple cases. The first line of each case contains an integer n, indicating there is n actions. The following n actions contain 3 types. 1: "arrive Name m a1 a2 ..am", means the kid called Name arrives at the classroom. He has m information, their id is a1 a2 ...am. 2: "share Name1 Name2", means that the kids called Name1 and Name2 share their information. (The sharing state will keep on, that means, if A share with B, later B share with C, A can also get all C's information via B. One kid may share with himself, but it doesn't mean anything.) 3: "check Name", means teacher wants to know the number of information kid called Name has got. n is less than 100000, and is positive. The information id is among [0,1000000]. Each Name has at most 15 characters. There would appears at most 1000 distinct information. Each kid carry no more than 10 information when arriving(10 is included).
输出
For every "check" statement, output a single number. If there's no check statement, don't output anything.
样例输入
8 arrive FatSheep 3 4 7 5 arrive riversouther 2 4 1 share FatSheep riversouther check FatSheep arrive delta 2 10 4 check delta share delta FatSheep check riversouther
样例输出
4 2 5
提示
check 1: FatSheep has 1 4 5 7, having all the information. So answer is 4.
check 2: delta has only 4 10 , doesn't have 1 5 7. So answer is 2
check 3: riversouther has 1 4 5 7 10, having all the information. So answer is 5
题目 F: The Intervals
时间限制: 2 Sec 内存限制: 65 MB
题目描述
Cantor, the famous mathematician, was working on a problem about intervals. Let's start from a line segment of unit length. Remove its middle 1/3. Now remove the middle 1/3's from the remaining two segments. Now remove the middle 1/3's from the remaining four segments. Now remove the middle 1/3's from the remaining eight segments. Now remove ... well, you get the idea. If you could continue this procedure through infinitely many steps, what would you have left? Now he assigns the following task to you. (He asked me to pass his assignment to you last night.) Given two arrays of numbers {A(n)} and {B(m)}. For each B(i) in {B(m)}, find 2 numbers a and b from {A(n)}, such that B(i) is in [a,b) and b-a<=|b'-a'| for all a' and b' from {A(n)} such that [a',b') contains B(i).
输入
There are several test cases. In each test case, the first line gives n and m. The second line contains n numbers, which are the elements of {A(n)}. The third line contains m nubmers, which are the elements of {B(m)}.
输出
For each B(i) in {B(m)}, output a line containing the interval [a,b). If there is no such interval, output "no such interval" instead. Print a blank line after each test case.
样例输入
3 3 10 20 30 15 25 35
样例输出
[10,20) [20,30) no such interval
题目G: 懒省事的小名
时间限制: 1 Sec 内存限制: 12 MB
题目描述
小名总结了一个英语近义词的词典(很厚哦,有多厚,你猜),词典实在太厚了,你需要帮助他写一个程序,输入一个单词,输出它的近义词
输入
第一行输入近义词的个数N和小名要查询的行数M
接下来N行为近义词对
M行单词,根据单词,输出它的近义词
输出
输出近义词,每个近义词占一行
样例输入
2 2 abc cba aaa bbb abc aaa
样例输出
cba bbb