acm icpc bicol2013 problemset final

15
Problem A: Honey Bees Input from file: pa.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 2 seconds The behavioral activity of worker honey bees can be divided into the following recognizable tasks: resting (Re), patrolling (Pt), Cell-cleaning (Cc), eating pollen (Ea), tending brood (Tb), comb-building and maintenance (Cm), and external activities ( Ex) such as guarding, foraging and dance-following. The tasks carried out by a honey bee were recorded at hourly intervals for a day, resulting in a data set consisting of whitespace separated symbols from the set { Re, Pt, Cc, Ea, Tb, Cm, Ex}. INPUT FORMAT The input consists of symbols from the set {Re, Pt, Cc, Ea, Tb, Cm, Ex}. The symbols are whitespace separated and could span for several lines. There are at most 24 symbols. OUTPUT FORMAT The output is a table consisting of 8 lines. Lines 1 to 7 are values in the following format: Task Count Proportion The tasks should be ordered this way: Re, Pt, Cc, Ea, Tb, Cm, and Ex. The count is the total frequency count of the task while proportion is the the frequency count divided by the total number of recorded tasks. The proportion should be rounded off to the nearest hundreths and should show exactly two digits after the decimal point. The 8th line should always be “Total <total> 1.00” where <total> is the total number of recorded tasks. SAMPLE INPUT Cc Pt Pt Re Tb Re Cm Cm Re Pt Pt Re Ea Ea Pt Pt Pt Re Re Cb Cb Pt Pt Cb SAMPLE OUTPUT Re 6 0.25 Pt 9 0.38 Cc 1 0.04 Ea 2 0.08 Tb 1 0.04 Cm 2 0.08 Ex 0 0.00 Total 24 1.00 __ Copyright © 2013, Rafael Saldaña and ACM ICPC Philippines Multi-Provincial Programming Contest ACM ICPC – Problem 1

Upload: saiidma

Post on 22-Nov-2015

99 views

Category:

Documents


14 download

TRANSCRIPT

  • Problem A: Honey BeesInput from file: pa.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 2 seconds

    The behavioral activity of worker honey bees can be divided into the following recognizable tasks: resting (Re), patrolling (Pt), Cell-cleaning (Cc), eating pollen (Ea), tending brood (Tb), comb-building and maintenance (Cm), and external activities (Ex) such as guarding, foraging and dance-following.

    The tasks carried out by a honey bee were recorded at hourly intervals for a day, resulting in a data set consisting of whitespace separated symbols from the set {Re, Pt, Cc, Ea, Tb, Cm, Ex}.

    INPUT FORMATThe input consists of symbols from the set {Re, Pt, Cc, Ea, Tb, Cm, Ex}. The symbols are whitespace separated and could span for several lines. There are at most 24 symbols.

    OUTPUT FORMATThe output is a table consisting of 8 lines. Lines 1 to 7 are values in the following format:

    Task Count Proportion

    The tasks should be ordered this way: Re, Pt, Cc, Ea, Tb, Cm, and Ex. The count is the total frequency count of the task while proportion is the the frequency count divided by the total number of recorded tasks. The proportion should be rounded off to the nearest hundreths and should show exactly two digits after the decimal point.

    The 8th line should always be Total 1.00 where is the total number of recorded tasks.

    SAMPLE INPUTCc Pt Pt Re Tb Re Cm Cm Re Pt Pt Re Ea Ea Pt Pt Pt Re Re Cb Cb Pt Pt Cb

    SAMPLE OUTPUTRe 6 0.25Pt 9 0.38Cc 1 0.04Ea 2 0.08Tb 1 0.04Cm 2 0.08Ex 0 0.00Total 24 1.00

    __Copyright 2013, Rafael Saldaa and ACM ICPC Philippines Multi-Provincial Programming Contest

    ACM ICPC Problem 1

  • Problem B: Repeating DecimalsInput from file: pb.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 5 seconds

    A routine problem in basic mathematics is to convert fractions to decimals. For example, 12

    is just

    0.5 while 13

    is 0.333..., which is simply written as 0. 3 . The decimal 0.5 is said to be terminating

    while 0. 3 is repeating. Other examples of fractions which convert to repeating decimals are:

    27=0.285714

    1766

    =0.2575

    256=4.16

    3401333

    =10. 213

    Your task is to determine the fraction in lowest terms that is equal to a given repeating decimal.

    INPUT FORMATThe input consists of one or more input lines. Each input line consists of a repeating decimal. The digits that repeat are enclosed in a pair of parentheses. The total number of digits in the decimal is at most 9.

    OUTPUT FORMATThe output consists of one or more lines with each line consisting of the given input followed by the equal sign and followed by the fraction in lowest terms. The fraction is displayed in the form x / y, where x is the numerator and y is the denominator.SAMPLE INPUT

    0.(285714)0.25(75)4.1(6)

    SAMPLE OUTPUT0.(285714) = 2 / 70.25(75) = 17 / 664.1(6) = 25 / 6

    __Copyright 2013, Bernard Marquez and ACM ICPC Philippines Multi-Provincial Programming Contest

    2 ACM ICPC Problem

  • Problem C: Solutions of Cubic EquationInput from file: pc.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 2 seconds

    Hannah asked you to determine all distinct real solutions of a cubic equation in the following form:

    Ax3 + Bx2 + Cx + D = 0

    The task is quite complicated especially if one solution is irrational. Before you complained, Hannah told you that she'll only give cubic equations with at least one integer solution.

    Your task then is to find all distinct real solutions of the cubic equation given the coefficients A, B, C, and D where A is not 0.

    The range of values of A, B, C, and D is -2,000,000 to 2,000,000. The range of values of x is -1,000,000 to 1,000,000.

    INPUT FORMATThe input starts with an integer N (where 0 < N < 100). It is then followed by N input lines. Each input line consists of four numbers A, B, C, and D, not necessarily integers. A is never 0.

    OUTPUT FORMATFor each input line, print all distinct real solutions of the cubic equation in one line, sorted in increasing order. Each real solution must be rounded off to the nearest ten thousandth and must be printed with exactly four digits after the decimal point. Two or more distinct real solutions must be separated by exactly one space.

    SAMPLE INPUT31.5 -5 2 -1.52 -7 7 -22 0 0 0

    SAMPLE OUTPUT3.00000.5000 1.0000 2.00000.0000

    __Copyright 2013, Allan Sioson and ACM ICPC Philippines Multi-Provincial Programming Contest

    ACM ICPC Problem 3

  • Problem D: Multiplication in a Dihedral GroupInput from file: pd.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 5 seconds

    A dihedral group is a set D with a multiplication operation * defined on D. The set D is generated by two elements a and b. The multiplication operation * will not be explicitly written, so that a*a will be indicated by aa or by a2. Similarly, a*a*b will be indicated by a2b1 or simply a2b.

    The dihedral group D has two integer parameters m and n, with m 2 and n 2, and so we write the dihedral group as Dm,n. The relations that define Dm,n are:

    am = a0 = 1, bn = b0 = 1, and ba = a(m-1)b.

    Thus Dm,n has (mn) elements, namely

    Dm,n = { ajbk | 0 j < m, 0 k < n } = { a0b0, a1b0, a2b0, , a(m-1)b0, . . . , a(m-1)b(n-1) }.

    For example, select m = 7 and n = 2. The elements of D7,2 are

    { a0b0, a1b0, a2b0, a3b0, a4b0, a5b0, a6b0, a0b1, a1b1, a2b1, a3b1, a4b1, a5b1, a6b1 }.

    Multiplication is not commutative, and so ba ab. In fact ba = a6b, according to the defining relations of D7,2. Also, ajak = a(j+k)%m, and bjbk = b(j+k)%n. Thus

    (ajbk)(apbq) (a(j+p)%mb(k+q)%n).

    To properly multiply the two elements (a3b1) and (a2b1) of D7,2, we proceed as follows,

    (a3b1)(a2b1) = (a3b0)(ba)(a1b1) = (a3b0)(a6b1)(a1b1),

    since ba = a6b.

    Also, since a3b0a6 = a3a6 = a(3+6)%7 = a2, we can multiply the first two factors and get (a3b0)(a6b1) = (a2b1). Thus

    (a3b0)(a6b1)(a1b1) = (a2b1)(a1b1).

    Now we can rewrite this as follows,

    (a2b1)(a1b1) = (a2b0)(ba)(a0b1) = (a2b0)(a6b1 )(a0b1) = (a8b2) = (a1b0).

    Thus, multiplying the two elements (a3b1) and (a2b1) gives, (a3b1)(a2b1) = (a1b0).

    4 ACM ICPC Problem

  • Your problem is to write a computer program, given m, n, and any two elements (a jbk) and (apbq) of the dihedral group Dm,n that computes the correct product of the two.

    INPUT FORMAT The input consists of several problem sets. Each problem set consists of several lines of input. The first line will contain the problemID, m, n, and p, separated by spaces. The integers m and n will not exceed 1000 in value. The number p is the number of multiplication problems for this problem set. The first line is followed by p lines of input, each line containing two elements of Dm,n to multiply. Each element will be given in the form a3b1 instead of a3b1. Data for the next problem set will immediately follow the previous problem set. A set problemID of ZZ will indicate end of input.

    OUTPUT FORMATFor each multiplication problem, print one line of the form

    ProblemID id: ajbk * apbq = arbs

    where id is the problemID given in the input, ajbk and apbq are the elements to multiply, and arbs is the correct answer.

    SAMPLE INPUTC1 7 2 3 a3b1 a2b1 a5b1 a3b1 a2b1 a4b1C2 9 3 2 a3b1 a2b1 a4b1 a3b1ZZ 0 0 0

    SAMPLE OUTPUTProblemID C1: a3b1 * a2b1 = a1b0 ProblemID C1: a5b1 * a3b1 = a2b0 ProblemID C1: a2b1 * a4b1 = a5b0 ProblemID C2: a3b1 * a2b1 = a1b2 ProblemID C2: a4b1 * a3b1 = a1b2

    __Copyright 2013, Pablo Manalastas and ACM ICPC Philippines Multi-Provincial Programming Contest

    ACM ICPC Problem 5

  • Problem E: Area Between Outer Hull and Inner HullInput from file: pe.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 5 seconds

    Given a set S of N points on the plane, namely S = {(x[0], y[0]), (x[1], y[1]), ... , (x[N-1], y[N-1])}, the outer hull Ho of S is simply just the convex hull of S. It is a subset of points of S which when joined by line segments will form a convex polygon P of minimum area that includes all points of S inside P or on P. Points of S falling on P but are not corner vertices of P are not considered part of the convex hull. The inner hull Hi of S is obtained by getting the convex hull of S Ho. That is, remove from set S all points that belong to the outer hull Ho, to get the set (S Ho). Then compute the inner hull Hi as the convex hull of (S Ho).

    For example given the set S of 8 points A(2.0, 5.0), B(2.0, 4.0), C(2.0, 2.0), D(1.0, 1.0), E(4.0, 1.0), F(0.0, 0.0), G(3.0, 0.0), and H(5.0, 0.0), the outer hull Ho of S can be computed as the set Ho={F, H, A, F}. If we remove Ho from S, we get S Ho = {B, C, D, E, G}. The inner hull Hi of S is computed as the convex hull of S Ho, namely Hi = {D, G, E, B, D}. Now the area inside Ho is area(Ho) = 12.5. The area inside Hi is area(Hi) = 6.0. Thus the area between the outer hull Ho and the inner hull Hi is 12.5 6.0 = 6.5.

    Your problem is, given a set S of N points, to write a program that computes the area between the outer hull Ho of S, and the inner hull Hi of S.

    INPUT FORMATThe input consists of several problem sets. The first line of a problem set will contain the problemID and the value of N. The value of N will not exceed 1,000. The next N lines of the problem set will contain the value of x- and y-coordinate (separated by a space) of a point, at one point per line. Each coordinate x or y will be a real number not exceeding 100.0 in absolute value. The lines of the next problem set will immediately follow the previous problem set. A line with problemID of ZZ and a value of N of 0 indicates the end of input.

    OUTPUT FORMATFor each problem set, print one line of the form ProblemID id: area where id is the problemID given in the input, and area is the area between the outer hull Ho and the inner hull Hi that you computed. Express the area with 4 decimal places.

    See sample input and corresponding output on the next page.

    6 ACM ICPC Problem

  • SAMPLE INPUT

    A1 8 2.0 5.0 2.0 4.0 2.0 2.0 1.0 1.0 4.0 1.0 0.0 0.0 3.0 0.0 5.0 0.0 A2 11 1.0 5.0 5.0 5.0 2.0 4.0 3.0 4.0 2.0 3.0 2.0 2.0 3.0 2.0 1.0 1.0 4.0 1.0 0.0 0.0 4.0 0.0ZZ 0

    SAMPLE OUTPUT

    ProblemID A1: 6.5000 ProblemID A2: 14.0000

    __Copyright 2013, Pablo Manalastas and ACM ICPC Philippines Multi-Provincial Programming Contest

    ACM ICPC Problem 7

  • Problem F: Sharkovskis OrderingInput from file: pf.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 2 seconds

    In a 1964 paper on continuous mappings of the reals into the reals, Alexandr Sharkovski used the following ordering of the positive integers:

    3 5 7 9 ... 32 52 72 ... 322 522 ... 23 22 2 1

    As Ciesielski and Pogoda (2008) describe it:

    First come the odd numbers, beginning with 3, arranged in increasing order. This sequence is repeated with each odd integer multiplied by 2. The initial sequence is again repeated with each odd integer multiplied by 22, and so on. The terminal sequence consists of the nonnegative powers of 2 arranged in decreasing order (note that 1 = 20).

    Write a program that reads an input containing a list of up to 255 unsigned integers with values less than or equal to 65,535 (not necessarily distinct) separated by white space and terminated by 0. The program should display on the screen the numbers arranged in Sharkovskis ordering in one line. The numbers in the line are separated exactly by one space.

    INPUT FORMATThe input starts with an integer N (0 N 255). This is followed by N input cases. Each input case is a non-empty list of up to 255 unsigned integers (not necessarily distinct) with values not exceeding 65,535. Each pair of numbers is separated by white space. Each input case is terminated by 0.

    OUTPUT FORMATFor every input case, print the required numbers arranged in Sharkovskis ordering in one line. The numbers in the line are separated exactly by one space.

    SAMPLE INPUT23 01 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 0

    SAMPLE OUTPUT33 5 7 9 11 13 15 17 19 6 10 14 18 12 16 8 4 2 1 1

    __Copyright 2013, Joel Noche and ACM ICPC Philippines Multi-Provincial Programming Contest

    8 ACM ICPC Problem

  • Problem G: M M Detour

    Input from file: pg.in

    Output to console: stdout (in C), cout (in C++), System.out (in Java)

    Execution time limit: 5 seconds

    Metro Manila currently has five circumferential roads arranged in concentric semicircles, with a sixth

    to be constructed linking the north and the south. From the center (Manila), there are ten radial roads

    that link the inner and outer areas of Metro Manila.

    Figure G-1 Ideal road network of Metro Manila

    In this problem, we are to find the shortest distance to get from point A to point B. Each point is

    defined by the intersection of a circumferential and radial road pair (C#, R#) with the center

    represented as (C0, R0). For calculation purposes, the distance for each segment in the radial road is

    equal to 1 unit, while each arc is equal to the circumferential road number. For instance, the distance

    from (C1, R3) to (C2, R3) is one unit, and the distance from (C3, R1) to (C3, R2) is three units. The

    shortest distance from (C1, R2) to (C5, R1) is five units (See darkened path). It is assumed that C6 is

    passable for this problem.

    However with the new number coding scheme, vehicles are not allowed to use the radial roads with

    the same last digit of the plate numbers. For instance, a vehicle with plate number of ABC-123 cannot

    use R3. Furthermore, the circumferential roads (except for C6) also have restrictions. Plate numbers

    ending in 1 and 2 are not allowed in C1, 3 and 4 in C2, 5 and 6 in C3, 7 and 8 in C4, and 9 and 0 in

    C5. Thus the shortest path from (C1, R2) to (C5, R1) for vehicle with plate number ABC-123 is five

    units, but nine units for vehicle with plate number CBA-321. Note that there will be instances that a

    vehicle cannot reach the destination at all.

    (C6,R1) southernmost intersection

    R3 Sergio Osmea, Sr. Highway - SLEX

    R1 Roxas Boulevard- Manila-Cavite (Coastal) Highway

    R2 Taft Avenue E. Quirino Highway

    R4 Tejeron St. J.P. Rizal St.

    R5 Ramon Magsaysay Shaw Boulevard

    R6 Ramon Magsaysay Aurora Boulevard

    R7 Espaa Quezon Avenue

    R8 Dimasalang A. Bonifacio - NLEX

    R9 Rizal Avenue MacArthur Highway R10 Marcos Highway

    C1 Recto - Ayala Boulevard

    C2 Tayuman Nagtahan - Quirino

    C3 5th Ave Araneta -Ayala Gil Puyat

    C4 EDSA

    C5 C.P. Garcia Katipunan Tandang Sora C5 Ext

    C6 Bulacan-Rizal-Manila-Cavite Regional Expressway ExpresswayExpressway

    ACM ICPC Problem 9

  • INPUT FORMAT

    The input consists of multiple test cases. For simplicity, each test case will have 5 single digit

    numbers that are whitespace separated. The first two numbers represent the starting point, the next

    two numbers represent the destination point, and the last number is the ending digit of the plate

    number. There are no blank lines in between test cases, and the last test case is followed by a line

    containing a single zero.

    OUTPUT FORMAT

    For each test case, print the case number (starting with 1) followed by the shortest distance needed.

    Output not possible if the destination cannot be reached.

    SAMPLE INPUT

    1 2 5 1 3

    1 2 5 1 1

    0

    SAMPLE OUTPUT

    Case 1: 5

    Case 2: 9

    --

    Copyright 2013, Caslon Chua and ACM ICPC Philippines Multi-Provincial Programming Contest

    10 ACM ICPC Problem

  • Problem H: More Fun in Bicol

    Input from file: ph.in

    Output to console: stdout (in C), cout (in C++), System.out (in Java)

    Execution time limit: 5 seconds

    The Bicol region (Region 5) is composed of six provinces. They are Albay, Camarines Norte,

    Camarines Sur, Sorsogon and the island-provinces of Catanduanes and Masbate. The cities in the

    Bicol region are Iriga City, Legazpi City, Ligao City, Masbate City, Naga City, Sorsogon City, and

    Tabaco City.

    Figure H-1: Map of Bicol Region (Location are for illustration purposes only)

    Most of the contestants could not wait to complete the competition and had begun planning on

    exploring the region. They had started asking where certain places were and are in the process of

    listing down the relative location between places.

    INPUT FORMAT

    The input contains several test cases. Each test case contains two data sets. The first data set describes

    the relative location of the first place to the second, and the second data set contains queries on the

    relative location of the first place to the second. For example

    Data set 1

    Place 1 Place 2 Relative Location

    Naga City City of Iriga Northwest

    Masbate City Naga City Southeast

    Tabaco City City of Ligao Northeast

    Sorsogon City Legazpi City Southeast

    City of Ligao Legazpi City West

    Naga City

    Tabaco City

    Legazpi City

    City of Ligao

    Sorsogon City

    Masbate City

    City of Iriga

    ACM ICPC Problem 11

  • Data set 2

    Place 1 Place 2

    Naga City City of Iriga

    City of Iriga Naga City

    Sorsogon City Naga City

    Sorsogon City City of Ligao

    Thus in the above example, there are 5 and 4 entries in data set 1 and 2 respectively.

    Data set 1 is composed of a set of city pair values and a relative location. Each entry indicates that

    relative location of place 1 to 2. For instance, the entry (Naga City, City of Iriga, Northwest) means

    that the Naga City is northwest of City of Iriga. However, the data set will not have reverse

    relationship entry. For instance, (City of Iriga, Naga City, Southeast)

    The data starts with two integers, m and n, representing the number of entries in data sets 1 and 2

    respectively, where (1 m 100) and (1 n 50). This is followed by m entries of position description and n entries of queries.

    The data entries are comma delimited and may contain mixed cases. The allowed relative positions

    are north, south, east, west, northeast, northwest, southeast and southwest. It is assumed that the each

    individual relative position has a value of 1. These are 1 north, 1 south, 1 east, 1 west, 1 north and 1

    east, 1 north and 1 west, 1 south and 1 east, and 1 south and 1 west respectively. Thus, the distance

    from Masbate City to Naga City is the same as Sorsogon City to Legazpi City.

    There is a blank line between test cases and the last test case is followed by a single integer zero.

    OUTPUT FORMAT

    For each test case, output the relative position of the places being queried. The system will output

    Relative location cannot be determined if there is insufficient information; however the system should attempt to use all necessary information to obtain a result.

    SAMPLE INPUT 5 4

    Naga City,City of Iriga,Northwest

    Masbate City,Naga City,Southeast

    Tabaco City,City of Ligao,Northeast

    Sorsogon City,Legazpi City,Southeast

    City of Ligao,Legazpi City,West

    Naga City,City of Iriga

    City of Iriga, Naga City

    Sorsogon City, Naga City

    Sorsogon City, City of Ligao

    0

    SAMPLE OUTPUT Case 1

    Naga City is northwest of City of Iriga

    City of Iriga is southeast of Naga City

    Relative location cannot be determined

    Sorsogon City is southeast of City of Ligao

    --

    Copyright 2013, Caslon Chua and ACM ICPC Philippines Multi-Provincial Programming Contest

    12 ACM ICPC Problem

  • Problem I: Interior Lattice PointsInput from file: pi.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 5 seconds

    A lattice point is a point whose coordinates on a rectangular coordinate system are integers. An interior lattice point is a lattice point that is inside a given polygon and not on its boundary. For example, the drawing below shows a triangle having six interior lattice points.

    Write a program that reads an input containing three pairs of coordinates (xA, yA), (xB, yB), (xC, yC), where each coordinate is an unsigned integer with a value less than or equal to 100. The numbers in the line are separated exactly by one space and are in the order xA yA xB yB xC yC. The coordinates describe three distinct (but possibly collinear) lattice points. If the given coordinates describe a triangle with non-zero area, then the program should display on the screen the number of interior lattice points of the triangle. Otherwise, the program should display on the screen the number zero. (If the three points are collinear, then there are no interior lattice points.)

    INPUT FORMATThe input starts with an integer N (0 N 255). This is followed by N input cases. Each input case is a list of six unsigned integers with values not exceeding 100. The six integers xA yA xB yB xC yC correspond to the coordinates (xA, yA), (xB, yB), (xC, yC).

    OUTPUT FORMATFor every input case, print the number of interior lattice points in one line.

    SAMPLE INPUT40 0 100 0 100 1000 0 98 100 100 1000 0 99 100 100 1000 0 99 99 100 100

    SAMPLE OUTPUT48514900__Copyright 2013, Joel Noche and ACM ICPC Philippines Multi-Provincial Programming Contest

    ACM ICPC Problem 13

  • Problem J: PermutationsInput from file: pj.in Output to console: stdout (in C), cout (in C++), System.out (in Java) Execution time limit: 5 seconds

    A permutation of a set is just an arrangement of all the distinct elements of the set. For example, all the permutations of the set { 2, 3, 5} are given below.

    2 3 52 5 33 2 53 5 25 2 35 3 2

    If each permutation is regarded as a number, the permutations in the above list are arranged in increasing magnitude. The permutations are said to be listed in lexicographic order. Note that the permutation in position 4 is 3 5 2 while the permutation in the last position, which is 6, is 5 3 2.

    For another example, all the permutations of the set { b, e, i, n } are listed in tabular form below.

    b e i n e b i n i b e n n b e ib e n i e b n i i b n e n b i eb i e n e i b n i e b n n e b ib i n e e i n b i e n b n e i bb n e i e n b i i n b e n i b eb n i e e n i b i n e b n i e b

    The permutations here are listed in dictionary order, which is just another way of describing lexicographic order. Note that the permutation in position 4 is b i n e while the permutation in position 20 is n b i e.

    Given a set of distinct digits or letters, your task is to determine the permutation of the set in a given position when the permutations are assumed to be listed in lexicographic order.

    Format of I/O and sample I/O are provided on the next page.

    14 ACM ICPC Problem

  • INPUT FORMATThe input consists of one or more input lines. Each input line consists of a string that is composed either entirely of distinct letters or entirely of distinct digits. The letters or digits are already arranged in order. The length of the string is at most 10 and is followed by a space and a number that gives the position of the required permutation.

    OUTPUT FORMATThe output consists of one or more lines. Each output line consists of the given input followed by the equal sign and followed by the permutation in the required position. If the given position is beyond the total number of permutations, then the output should indicate No permutation.

    SAMPLE INPUT235 4bein 20123456 700mnpqr 130tuvwxyz 4000

    SAMPLE OUTPUT235 4 = 352bein 20 = nbie123456 700 = 651342mnpqr 130 = No permutationtuvwxyz 4000 = ywuxvzt

    __Copyright 2013, Bernard Marquez and ACM ICPC Philippines Multi-Provincial Programming Contest

    ACM ICPC Problem 15