problemas recomendados en acm icpc news

Upload: thanhtam3819

Post on 02-Jun-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    1/23

    Bejing Normal University

    2014 ACM-ICPC Beijing

    Invitational Programming Contest

    May 18th, 2014

    Problem A: A Matrix

    Problem B: Beautiful Garden

    Problem C: Champions League

    Problem D: Dices in Yahtzee

    Problem E: Elegant String

    Problem F: Football on Table

    Problem G: Great Escape

    Problem H: Happy Reversal

    Problem I: In A Maze

    Problem J: Justice String

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    2/23

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    3/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Problem A. A Matrix

    Chaos King loves permutation and matrix, now he is trying to find out some relations betweenthem.

    Now Chaos King has a permutation. He wants to transform the permutation to a matrix by theprogram beneath.

    int f[][];

    int p[];

    int n;

    void insert(int r, int x)

    {

    for (int i=1; 1; i++)

    if (f[r][i]==0)

    {

    f[r][i]=x;

    return ;

    }

    else if (f[r][i]>x)

    {

    int tmp=f[r][i];

    f[r][i]=x;

    insert(r+1, tmp);

    return ;

    }

    }void Permutation2Matrix()

    {

    for (int i=1; i

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    4/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    It is guaranteed that

    Pi=Nand every element in the matrix is an integer in [1, N]. There areno 2 elements have the same value.

    Output

    For each case, first output the case number as Case #x: , and x is the case number. Thenoutput a permutation ofN, indicating the answer of this test case.

    If there are multiple answers, output the permutation with the largest alphabet order after reversal.(e.g. there are 2 answers: 1 2 3 and 1 3 2. You should output 1 2 3, because 1 3 2 is larger than1 2 3)

    If there is no answer, output No solution.

    Sample input and output

    Sample Input Sample Output

    2

    3 2

    2 1 2

    1 3

    2 1

    2 2 1

    Case #1: 1 3 2

    Case #2: No solution

    Page 2 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    5/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Problem B. Beautiful Garden

    There are n trees planted in lxhgwws garden. You can assume that these trees are planted alongthe X-axis, and the coordinate ofith tree is xi.

    But in recent days, lxhgwwwants to move some of the trees to make them look more beautiful.lxhgwwwill recognize the trees as beautiful if and only if the distance between any adjacent treesis the same.

    Now, lxhgwwwants to know what is the minimum number of trees he need to move.

    Just to be clear, after moving, there should still be n trees in the X-axis.

    InputThe first line of the input contains a single integer T, which is the number of test cases.

    For each case,

    The first line contains an integers number n(1 n 40), representing the number of treeslxhgww planted;

    The second line contains n integers numbers, the ith number represents xi.(1000000000 xi 1000000000)

    OutputFor each case, first output the case number as Case #x: , and x is the case number. Thenoutput a single number, representing the minimum number of trees lxhgwwneeds to move.

    Sample input and output

    Sample Input Sample Output

    1

    4

    1 3 6 7

    Case #1: 1

    Page 3 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    6/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    This page is intentionally left (almost) blank.

    Page 4 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    7/23

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    8/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Sample input and output

    Sample Input Sample Output

    1

    6

    - 1 2 3 4

    2 - 1 3 4

    2 3 - 1 4

    2 3 4 - 1

    - 1 2 3 5

    8 - 1 1 3

    2 3 - 1 5

    8 1 3 - 1

    - 1 2 4 6

    8 - 1 2 4

    6 8 - 1 2

    4 6 8 - 1-1 5 10 2

    1 - 1 3 7

    3 1 - 1 2

    2 2 2 - 1

    - 1 3 5 3

    1 - 1 1 9

    5 1 - 1 1

    3 5 7 - 1

    - 1 2 2 3

    2 - 1 3 42 3 - 1 2

    2 3 0 - 1

    Case #1: 51

    Page 6 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    9/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Problem D. Dices in Yahtzee

    Yahtzee is a famous game with dices, and its scorecard contains 14 boxes. The game contains14 turns. On each turn, the player rolls five dices. After each rolling, the player must choose anunused box to put dices and get his score according to the rule of this box. Each players totalscore is calculated by summing all 14 score boxes.

    The Yahtzee scorecard can be divided into two sections: the upper section and the lower section.

    In the upper section, there are six boxes, and theith box is scored by summing all the dices whoseface is i, i.e, the number of dices whose face is i mutiplies i.

    The lower section contains a number of poker-themed combinations with specific point values:

    1. Two-Pairs: If there are two pairs (for example, 2 2 3 3 4 and 2 2 3 3 3 arevalid, but 3 3 3 3 4 and 3 3 3 3 3 are not valid), the score is the sum of alldices, otherwise the score is zero.

    2. Three-Of-A-Kind: If there are at least three dices showing the same face, the score is thesum of all dices, otherwise the score is zero.

    3. Four-Of-A-Kind: If there are at least four dices showing the same face, the score is the sumof all dices, otherwise the score is zero.

    4. Full House: If there is a three-of-a-kind and a pair (for example, 2 2 3 3 3 is valid,but 3 3 3 3 3 is not valid), the score is 25, otherwise the score is zero.

    5. Small Straight: If there is a four sequential dice (for example, 1 2 3 4, 2 3 4 5,or 3 4 5 6), the score is 30, otherwise the score is zero.

    6. Large Straight: If there is a five sequential dice (for example, 12345 or 23456),the score is 40, otherwise the score is zero.

    7. Yahtzee: If all five dices show the same face, the score is 50, otherwise the score is zero.

    8. Chance: The score is the sum of all dice.

    Now, Elfnesss dices are non-uniform, but he know the probability of the dice showing one to six.Can you tell him the expectation of a players total score if he uses the best strategy to choosethe boxes during the game?

    InputOne integer Ton the first line indicates the number of cases.

    Then followed by T cases, each case contains only one line. Each line contains six numbers, theith number is the probability when the dice shows the face ofi. They are given with 4 digits afterthe decimal point. We assume the sum of the probability equals to 1.

    Output

    For each case, first output the case number as Case #x: , and x is the case number. Thenoutput the expect score that a player will get, rounded to 6 digits after the decimal point.

    Page 7 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    10/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Sample input and output

    Sample Input Sample Output

    2

    0.1600 0.1600 0.1700 0.1700 0.1700

    0.1700

    0.1000 0.1000 0.2000 0.2000 0.2000

    0.2000

    Case #1: 149.372281

    Case #2: 162.624651

    Page 8 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    11/23

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    12/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    This page is intentionally left (almost) blank.

    Page 10 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    13/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Problem F. Football on Table

    Bored? Lets play table football!

    The table football is played on a rectangular table, usually contains m rows of players which are

    plastic, metal, wooden, or sometimes carbon-fibre figures mounted on vertical metal bars. Afterplaying table football for hours, we decide to take a rest. And the state of the table remainsrandom, that means each bar is placed at any legal position with equal possibilities (players cantbe outside the table and a bar is fixed at a row).

    Now Im wondering if the goal-keeper shoot a ball, whats the possibility of this shoot turning toa goal? (If the ball did not touch any player, then I made a goal).

    Lets assume there is ai players on the ith row (counted from left to right). And we know the

    width of each player and the distance between two players. (To simplify the problem, we ignorethe thickness of the players, in other words, we consider the players as vertical segments. Thenwe treat the football as a point, moving along a straight line and will not touch the boundary ofthe table).

    InputThe first line contains an integer T, which denotes the number of test cases.

    For each test case:

    The first line contains two numbers L, W (1 L, W 108), denoting the length and thewidth of the table. (the lower left corner of the table is (0, 0) , and the top right corner ofthe table is (L, W)).

    The second line contains four number X, Y, dx, dy. (X, Y) denotes the initial position ofthe ball and (dx, dy) denotes the shooting direction. (Xwill always be zero, 0 Y W,dx >0).

    The third line contains an integer m(1 m 10), the number of rows of the players.

    Following mblocks, for the ith block,

    The first line contains a number xi and an integer ai,(0 < xi < L, 1 ai 100)denoteing the x-coordinate of the ith row and the number of players at the ith row.

    Page 11 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    14/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    The second line contains ai numbers, the jth number wj denotes the width of the j

    th

    (from bottom to top) player at the ith row.

    The third line contains ai1 numbers, thejth numberdj denotes the distance between

    the jth player and the (j+ 1)th player. Ifai equals 1, this line will be a blank line.

    We guarantee that

    wj+

    dj+ 1< W

    OutputFor each case, first output the case number as Case #x: , and x is the case number. Thenoutput the result rounded to 5 digits after the decimal point, representing the possibility of thisshoot turning to a goal, in other words, that the ball does not touch any player.

    Sample input and output

    Sample Input Sample Output2

    8.0 10.0

    0.0 5.0 2.0 -0.1

    1

    3.0 2

    2.0 2.0

    1.0

    8.0 10.0

    0.0 5.0 2.0 0.0

    23.0 2

    2.0 2.0

    1.0

    4.0 3

    2.0 1.0 2.0

    1.0 1.0

    Case #1: 0.23000

    Case #2: 0.13333

    Page 12 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    15/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    NoteFor test 1:

    The black solid lines denote the table.

    The dashed line denotes the bar.

    The gray lines denote the players.

    The dot-dashed line denote the trajectory of the ball.

    Page 13 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    16/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    This page is intentionally left (almost) blank.

    Page 14 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    17/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Problem G. Great Escape

    Beijing Invitational Programming Contest is now approaching, but the problems-set for the contestis not ready yet. Every day, the DEVIL lxhgww pushed Mochavic to set a question, then set aquestion again, then set a question again once more... Finally, Mochavic could not stand himanymore so he decided to escape to a safer place immediately.

    The area where Mochaviclives in can be seen as N+ 1 identical buildings along a horizontal axis(X-axis), the buildings are numbered 0, 1, 2, . . . , N from left to right. The distance between theith and (i + 1)th building is di unit length. Each building has L + 1 floors, which are numbered0, 1, 2, . . . , L from bottom to top. The height of each floor is 1 unit length so that the jth floorof each building can be viewed as a point (x, j), where x is the location of the building on theX-axis. Mochaviccan move up and down in one building at a vertical speed ofW, he can alsofly between adjacent buildings using the Liserious-Glider. Mochavic has an excellent glidingskill that he can fly along any path he likes, but he has to fall at one of the floors after finishingone glide. The gliding speed is determined by the air motion which he has measured carefully in

    advance: the gliding speed between the ith and (i + 1)th building is a constant vi.

    The DEVIL lxhgww is so horrible that Mochavichas to run faster and faster. So we can assumethat it costs no time for Mochavic to move through one floor inside one building. Moreover,Mochavic dont want waste any opportunity to show his gliding skill, so he will still take a glidebetween buildings even he is at the 0th floor.

    Mochavic(can be simply viewed as a point) is now at the Lth floor of the 0th building, pleasecalculate the least time he has to spend if he wants to escape to the 0th floor of the Nth building.

    Input

    The first line of the input gives the number of test cases, T(T 200). Then Ttest cases follow.For each test case:

    Page 15 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    18/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    The first line contains three integers N, L, W(1 N 103, 1 L 109, 1 W 106).

    The second line contains Nintegers, the ith number represents di(1 di 106) as described.

    The third line contains N integers, the ith number representsvi (1 vi 106) as described.

    OutputFor each case, first output one line as Case #x:, and x is the case number. Then followed bythe least time. Result within a relative error of 106 will be accepted.

    Sample input and output

    Sample Input Sample Output

    2

    3 1 0 3

    5 2 3

    5 2 7

    1 10000 211

    911

    207

    Case #1: 3.231651964072

    Case #2: 48.246236647122

    Page 16 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    19/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Problem H. Happy Reversal

    Elfness is studying in an operation NOT.

    For a binary number A, if we do operation NOT A, after that, all digits ofA will be reversed.

    (e.g. A=1001101, after operation NOT K, A will be 0110010).Now Elfness has Nbinary numbers of length K, now he can do operations NOT for some of hisnumbers.

    Lets assume after his operations, the maximum number is M, the minimum number is P. Hewants to know whats the maximum M Phe can get. Can you help him?

    InputThe first line of input is an integer T (T 60), indicating the number of cases.

    For each case, the first line contains 2 integers N (1 N 10000) andK(1 K 60), the nextN lines contains Nbinary numbers, one number per line, indicating the numbers that Elfnesshas. The length of each binary number is K.

    OutputFor each case, first output the case number as Case #x: , and x is the case number. Thenyou should output an integer, indicating the maximum result that Elfness can get.

    Sample input and output

    Sample Input Sample Output2

    5 6

    100100

    001100

    010001

    010001

    111111

    5 7

    0001101

    00010110010011

    0111000

    1001011

    Case #1: 51

    Case #2: 103

    Page 17 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    20/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    This page is intentionally left (almost) blank.

    Page 18 of 21

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    21/23

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    22/23

  • 8/11/2019 Problemas Recomendados en Acm Icpc News

    23/23

    2014 ACM-ICPC Beijing Invitational Programming Contest

    Problem J. Justice string

    Given two strings A and B, your task is to find a substring ofA called justice string, which hasthe same length as B, and only has at most two characters different from B.

    InputThe first line of the input contains a single integer T, which is the number of test cases.

    For each test case, the first line is string A, and the second is string B.

    Both string A and B contain lowercase English letters from a to zonly. And the length of thesetwo strings is between 1 and 100000, inclusive.

    Output

    For each case, first output the case number as Case #x: , and x is the case number. Thenoutput a number indicating the start position of substring C in A, position is counted from 0. Ifthere is no such substring C, output 1.

    And if there are multiple solutions, output the smallest one.

    Sample input and output

    Sample Input Sample Output

    3

    aaabcd

    abeeaaaaaa

    aaaaa

    aaaaaa

    aabbb

    Case #1: 2

    Case #2: 0

    Case #3: -1