Nurse Schedule ListingInput File Name: NrsSchedList.inp Output File Name: NrsSchedList.out The director of a hospital want to schedule a working plan for a nurse in a given period of N c
Trang 1Nurse Schedule Listing - NRSSCHEDLIST 2
Balanced Courses Assignment - BCA 3
Container 2D – CONTAINER 5
Networks — CNET 6
Money Changing - CHANGE 8
ATM withdrawal — ATM 9
Planting Trees — PTREES 10
Pie — PIE 11
Fibonacci Words — FIBWORDS 12
The Hamming Distance — HAMDIST 13
Route Planning — ROUTING 14
The Tower of Babylon — TOWER 15
Marble Cut — MARBLE 16
Gold - GOLD 18
Nurse - NURSE 19
Machine – MACHINE 20
Phone List — PHONELIST 21
DNA Repetitions — DNAREP 22
DNA Sequences — DNASEQ 23
InterCity Bus — ICBus 24
Edges Adding - ADDEDGE 26
KPath – KPATH 27
Longest Common Substring of n Strings — nLCS 28
Lu Ban — HIST 29
The Maximum Subsequence with Bounded Length — MAXSUBSEQ 30
Page 1 of 30
Trang 2Problem A Nurse Schedule Listing
Input File Name: NrsSchedList.inp
Output File Name: NrsSchedList.out
The director of a hospital want to schedule a working plan for a nurse in a given period of N consecutivedays 1, , N Due to the policy of the hospital, each nurse cannot work all the days 1, , N Instead,there must be days off in which the nurse need to take a rest A working plan is a sequence of disjointworking periods A working period of a nurse is defined to be a sequence of consecutive days on whichthe nurse must work and the length of the working period is the number of consecutive days of thatworking period The hospital imposes two constraints:
• Each nurse can take a rest only one day between two consecutive working periods it means that ifthe nurse takes a rest today, then she has to work tomorrow (1)
• The length of each working period must be greater or equal to K1 and less than or equal to K2 (2)
A working plan is represented by a binary sequence (bit 1 means day on, and bit 0 means day off).Given a positive integer K, the director of the hospital want to know the Kth working plan in thelexicographic order satisfying above constraints
Explanation
There are 4 working plans described as follows
working plan 1 off on on off on onworking plan 2 on on off on on offworking plan 3 on on off on on onworking plan 4 on on on off on on
Trang 3Problem B Balanced Courses Assignment
Input File Name: BCA.inp
Output File Name: BCA.out
At the beginning of the semester, the head of a computer science department D have to assign courses
to teachers in a balanced way The department D has m teachers T = {1, 2, , m} and n courses
C = {1, 2, , n} Each teacher t ∈ T has a preference list which is a list of courses he/she can teachdepending on his/her specialization We known a list of pairs of conflicting two courses that cannot
be assigned to the same teacher as these courses have been already scheduled in the same slot of thetimetable The load of a teacher is the number of courses assigned to her/him How to assign n courses
to m teacher such that each course assigned to a teacher is in his/her preference list, no two conflictingcourses are assigned to the same teacher, and the maximal load is minimal
Input
The input consists of following lines
• Line 1: contains two integer m and n (1 ≤ m ≤ 10, 1 ≤ n ≤ 30)
• Line i+1: contains an positive integer k and k positive integers indicating the courses that teacher
i can teach (∀i = 1, , m)
• Line m + 2: contains an integer k
• Line i + m + 2: contains two integer i and j indicating two conflicting courses (∀i = 1, , k)
Output
The output contains a unique number which is the maximal load of the teachers in the solution foundand the value -1 if not solution found
Page 3 of 30
Trang 5a Container b Three rectangle items c Solution
Problem C Container 2D
Input File Name: STANDARD INPUT
Output File Name: STANDARD OUTPUT
There is a container having horizontal size W and vertical size H There are N rectangle items 1, 2, ,
N in which item i has horizontal size wi and vertical size hi Find the way to place these N items intothe container such that
• The sides of items are packed in parallel with the sides of the container
• The items cannot rotated
• No two items overlap
Input
The input consists of following lines
• Line 1: contains two integer H and W (1 ≤ H, W ≤ 30)
Trang 6Figure 1: Communication networks G
Problem D Networks
Input File Name: STANDARD INPUT
Output File Name: STANDARD OUTPUT
The network administrator of a company have to analyze the current state of their communicationnetwork all over the world The communication network consists of servers and cable links between theseservers, each link has a cost A k-route is a sequence of k + 1 different servers in which two consecutiveservers are connected by a cable link A cycle is a k-route (for any k > 1) such that the beginning andthe terminating servers are connected by a cable link The communication network contains no cycle.The cost of a k-route is the sum of cost of links between two consecutive servers of the k-route One ofthe indicators of the analysis is the k-route having minimal cost of the network for a given value of k.The 2-route having minimal cost of the communication network in Figure 1 is 6-1-4 with the cost 3.Given the communication network G and an integral value k, help the network administrator to find thek-route having minimal cost of G
Input
The input consists of following lines
• Line 1: contains two integer n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 2000) in which n is the number ofservers of the communication network G (servers are numbered 1,2, ,n)
• Line 2: contains an integer m (1 ≤ m ≤ 10000) which is the number of cable links between servers
Trang 8Problem E Money Changing
Input File Name: change.inp
Output File Name: change.out
Minh go shopping at the SS shop The shop has currency denominations: 1$, 5$, 10$, 50$, 100$, 500$.Minh takes some items at the shop and pay an amount of 1000$ Your task to devise a method to payback amount to customer using fewest number of money notes
Trang 9Problem F ATM withdrawal
Input File Name: atm.inp
Output File Name: atm.out
Vinh works for an ATM machine manufacturing company The basic functionality of an ATM machine
is cash withdrawal When a user requests a cash withdrawal of W VND (Vietnamese Dong), the ATMhas to dispense N money notes such that they sum up to W For the next generation of ATM machine,Vinh is working on an algorithm to minimize the number N of money notes for each cash withdrawaltransaction
Your task is to help Vinh to do his job given that the money notes come in the values of
1000, 2000, 3000, 5000, 1000·101, 2000·101, 3000·101, 5000·101, , 1000·10c, 2000·10c, 3000·10c, 5000·10cwhere c is a positive integer and Vinh has unlimited supply of money notes for each value
Input
The input file consists of several datasets The first line of the input file contains the number of datasetswhich is a positive integer and is not greater than 1000 The following lines describe the datasets
• The first line consists of one positive integer W (W ≤ 1018);
• The second line consists of one positive integer c (c ≤ 15)
Output
For each dataset, write in one line two space-separated integers N and S where S is the number of ways
to dispense the fewest number N of money notes In case there is no way to serve the cash withdrawalrequest, write out 0 in one line instead
Trang 10Problem G Planting Trees
Input File Name: ptrees.inp
Output File Name: ptrees.out
Farmer Jon has recently bought n tree seedlings that he wants to plant in his
yard It takes 1 day for Jon to plant a seedling1, and for each tree Jon knows
exactly in how many days after planting it grows to full maturity Jon would
also like to throw a party for his farmer friends, but in order to impress them
he would like to organize the party only after all the trees have grown More
precisely, the party can be organized at earliest on the next day after the last
tree has grown up
Help Jon to find out when is the earliest day when the party can take place
Jon can choose the order of planting the trees as he likes, so he wants to plant the trees in such a waythat the party will be as soon as possible
Input
The input consists of two lines The first line contains a single integer N (1 ≤ N ≤ 100 000) denotingthe number of seedlings Then a line with N integers ti follows (1 ≤ ti≤ 1 000 000), where ti denotes thenumber of days it takes for the ith tree to grow
Trang 11Problem H Pie
Input File Name: stdin
Output File Name: stdout
My birthday is coming up and traditionally Im serving pie Not just one pie, no, I have a number N ofthem, of various tastes and of various sizes F of my friends are coming to my party and each of themgets a piece of pie This should be one piece of one pie, not several small pieces since that looks messy.This piece can be one whole pie though My friends are very annoying and if one of them gets a biggerpiece than the others, they start complaining Therefore all of them should get equally sized (but notnecessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better thanspoiling the party) Of course, I want a piece of pie for myself too, and that piece should also be of thesame size What is the largest possible piece size all of us can get? All the pies are cylindrical in shapeand they all have the same height 1, but the radii of the pies can be different
Input
One line with a positive integer: the number of test cases Then for each test case:
• One line with two integers N and F with 1 ≤ N, F ≤ 10000: the number of pies and the number
Page 11 of 30
Trang 12Problem I Fibonacci Words
Input File Name: stdin
Output File Name: stdout
Input
The first line of each test case contains the integer n (0 ≤ n ≤ 100) The second line contains the bitpattern p The pattern p is nonempty and has a length of at most 100 000 characters
Output
For each test case, display its case number followed by the number of occurrences of the bit pattern p in
F (n) Occurrences may overlap The number of occurrences will be less than 263
Trang 13Problem J The Hamming Distance
Input File Name: stdin
Output File Name: stdout
The Hamming distance between two strings of bits (binary integers) is the number of corresponding bitpositions that differ This can be found by using XOR on corresponding bits or equivalently, by addingcorresponding bits (base 2) without a carry For example, in the two bit strings that follow:
A 0 1 0 0 1 0 1 0 0 0
B 1 1 0 1 0 1 0 1 0 0
A XOR B = 1 0 0 1 1 1 1 1 0 0The Hamming distance (H) between these 10-bit strings is 6, the number of 1s in the XOR string
Input
Input consists of several datasets The first line of the input contains the number of datasets, and itsfollowed by a blank line Each dataset contains N , the length of the bit strings and H, the Hammingdistance, on the same line There is a blank line between test cases
Output
For each dataset print a list of all possible bit strings of length N that are Hamming distance H fromthe bit string containing all 0s (origin) That is, all bit strings of length N with exactly H 1s printed inascending lexicographical order
The number of such bit strings is equal to the combinatorial symbol C(N, H) This is the number ofpossible combinations of N H zeros and H ones It is equal to
N !(N H)!H!
This number can be very large The program should work for 1 ≤ H ≤ N ≤ 16
Print a blank line between datasets
Page 13 of 30
Trang 14Problem K Route Planning
Input File Name: stdin
Output File Name: stdout
Superior Island is a very picturesque island and only bicycles are allowed on the island Therefore, thereare many one-way bicycle roads connecting the different best photo-shooting spots on the island To helpthe visitors plan their trip to the island, the tourism commission wants to designate r different bicycleroutes that go through some of the best photo-shooting spots on the island Given a map of all thebicycle roads on the island and a list of the best photo-shooting spots to be included on each of the threeplanned routes (non-listed spots must not be included in the route), please write a program to plan each
of the r routes so that the distance on each route is minimal Note that each best photo-shooting spotmay only appear at most once on the route
Input
There are two parts to the input The first part of input gives the information of the bicycle roads on theisland The first line contains two integer n and r , n ≤ 100 and r ≤ 10 , indicating that there are n bestphoto-shooting spots on the island and there are r routes to be planned The next n lines (line 2 throughline n + 1) contains n × n integers (n lines with n integers on each line), where the j -th integer on line
i denotes the distance from best photo-shooting spot i − 1 to best photo-shooting spot j ; the distancesare all between 0 and 10, where 0 indicates that there is no one-way road going from best photo-shootingspot i − 1 to spot j
The second part of input has r lines, denoting the r sightseeing routes to be planed Each line lists thebest photo-shooting stops to be included in that route The integers on each line denote the recommendedphoto-shooting stops on that particular sightseeing route The first integer on the line is the startingpoint of the route and the last integer is the last stop on the route However, the stops in between can
be visited in any order
Output
Output r integers on r lines (one integer per line) indicating the distance of each of the r planned routes
If a route is not possible, output ‘0’
Trang 15Problem L The Tower of Babylon
Input File Name: stdin
Output File Name: stdout
Perhaps you have heard of the legend of the Tower of Babylon Nowadays many details of this tale havebeen forgotten So now, in line with the educational nature of this contest, we will tell you the wholestory:
The babylonians had n types of blocks, and an unlimited supply of blocks of each type Each type-i blockwas a rectangular solid with linear dimensions (xi, yi, zi) A block could be reoriented so that any two ofits three dimensions determined the dimensions of the base and the other dimension was the height Theywanted to construct the tallest tower possible by stacking blocks The problem was that, in building atower, one block could only be placed on top of another block as long as the two base dimensions of theupper block were both strictly smaller than the corresponding base dimensions of the lower block Thismeant, for example, that blocks oriented to have equal-sized bases couldn’t be stacked
Your job is to write a program that determines the height of the tallest tower the babylonians can buildwith a given set of blocks
Input
The input file will contain one or more test cases The first line of each test case contains an integer n,representing the number of different blocks in the following data set The maximum value for n is 30.Each of the next n lines contains three integers representing the values xi, yi and zi
Input is terminated by a value of zero (0) for n
Page 15 of 30