All Just a Dream

Download All Just a Dream

Post on 03-Apr-2018

227 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

  • 7/28/2019 All Just a Dream

    1/15

    All Just A Dream

    Problem id: dreamTime limit: 3 seconds

    Memory limit: 2048 MB

    Picture in Public Domain via Wikimedia Commons

  • 7/28/2019 All Just a Dream

    2/15

    A common plot device in story-telling is the All Just A Dream trope. Typical

    symptoms of this trope being used are talking lions, main characters dying, yodeling

    aliens on monocycles, and a general plethora of weird events. Then, of course, someonewakes up and it is revealed that everything that happened during the entire season did in

    fact not happen at all. It was All Just A Dream (or some kind of hallucination), and the

    days of our lives spent watching all those episodes are lost forever. In order to causefurther confusion and uncertainty, this can also be done in layers, with characters having

    dreams within dreams within dreams, and so on.

    When the All Just A Dream trick is taken too far and gets used too often, it can get

    difficult to keep track of what has actually happened. This is where you enter the picture.You will be given a list of events, dreams, and scenarios. Each scenario specifies some

    events that have happened and some others that have not happened. Your job is to

    determine for each scenario whether that scenario is possible (possibly using the All JustA Dream trick).

    Input

    The first line of input consists of an integer0n50000, the number of events,dreams and scenarios. Then follow n lines, giving the events, dreams, and scenarios inchronological order. Each line is in one of the following forms:

    An event line is of the form E e, indicating that event e happens (see below forformat ofe).

    A dream line is of the form D r, indicating that the last revents that happenedwere All Just A Dream. Note that these events are now considered to not have

    happened, so they should not be counted when processing subsequent D lines.

    A scenario line is of the form S ke1 ek, where 1k30 is an integergiving the number of events and e1,,ek is the list of events of the scenario. In ascenario, each event may be prefixed with a !, indicating that the event did not

    happen in this scenario.

    Events are strings containing at most 20 characters and using only the characters a-z

    and underscores (_). For D lines, you can assume that ris an integer between 1 and R,where R is the total number of events that have happened so far (and that have not turnedout to be a dream). For E lines, you can assume that e is not an event that has already

    happened, except if the previous occurence of the event turned out to be a dream, inwhich case it can happen again.

    Warning

    This problem has somewhat large amounts of input and output. We recommend you tomake sure that your input and output are properly buffered in order to make the most of

    the few seconds of execution time that we give you.

  • 7/28/2019 All Just a Dream

    3/15

    Output

    For each scenario in the input, output a line as follows:

    Yes if the given scenario is consistent with what has happened so far.

    r Just A Dream if the given scenario would be consistent with what hashappened so far, provided a D r line had occurred just before the scenario. If

    there are many possible values ofr, choose the smallest value. Note that youshould not consider this hypothetical D r line to have occurred (as illustrated by

    sample input 2 below).

    Plot Error otherwise.

    Sample Input 1 Sample Output 110E business_as_usual

    E bobby_diesS 1 bobby_died

    E stuff_happensE jr_does_bad_things

    S 2 !bobby_dies business_as_usualE it_goes_on_and_on

    D 4S 1 !bobby_dies

    S 2 !bobby_dies it_goes_on_and_on

    Plot Error3 Just A Dream

    Yes

    Plot Error

    Sample Input 2 Sample Output 211

    S 1 !somethingE one

    E twoE three

    E fourE five

    S 3 three !four oneD 1

    S 3 three !four one

    D 1

    S 3 three !four one

    Yes

    2 Just A Dream1 Just A Dream

    Yes

  • 7/28/2019 All Just a Dream

    4/15

    Wheel Game

    Problem id: wheelgame

    Time limit: 1 secondsMemory limit: 2048 MB

    Its yet another rainy day in 1959, there are no video games, and you are stuck indoors

    playing a game with a friend. The game is played using an even number2n of sticks,laid out on a table to form a wheel with n spokes as shown in the figure below.

    You and your friend take turns removing sticks (you always start, since you are you). The

    rules are simple: each turn, the current player selects one of the remaining sticks. She

    then removes this stick and all sticks touching the selected stick. This goes on until there

    are no sticks left, and the player who removed the last stick is declared the winner.

    (a) A wheel with 5 spokes

  • 7/28/2019 All Just a Dream

    5/15

    (b) What remains after the grey stick is selected

    Figure 1: A possible initial move in the wheel game

    After a while, this gets boring, and you start fantasizing about what the world will be like

    in the 21st century: no doubt there will be robots to play stick games with instead of

    plain old friends. Oh what jolly fun it would be! But what if the robots are super smart?Then you would never be able to win. That wouldnt be very fun.

    Write a program which, given the value ofn, determines whether you would have anypossibility of winning when playing against a robot, or whether you would lose no matter

    what you do. Assume that the robot is clever enough to always play optimally, andunemotional enough that it would never intentionally lose just to make you feel better.

    Input

    The input consists of a single integern between 3 and 500000, inclusive. (You maycomplain that it is impossible to lay out that many sticks to form something resembling awheel, but recall that this took place in 1959 the times were different back then.)

    Output

    Output a single line, containing The robot is your friend if it is possible for you

    to win, or Destroy the robot before it is too late if the robot would win no

    matter how you play.

    Sample Input 1 Sample Output 15 Destroy the robot before it is too late

    Sample Input 2 Sample Output 2

  • 7/28/2019 All Just a Dream

    6/15

    6 The robot is your friend

    PlaylistProblem id: playlist

    Time limit: 22 seconds

    Memory limit: 2048 MB

    Photo by Anonymous Account on flickrYou have been invited to host a famous radio show to tell your fascinating life story and

    play some of your favorite songs. However, choosing which songs to play is turning out

    to be very tricky; there are just way too many good songs and you only have enough timeto play a measly nine songs!

  • 7/28/2019 All Just a Dream

    7/15

    In order to give the show a sense of continuity, you have decided that consecutive songs

    you play should have some detail in common. For instance, if you start by playing

    Bjrks song Pagan Poetry, you could continue with next playing matmos trackEnigma Machine for Alan Turing since matmos contributed to Bjrks Vespertine

    album (on which Pagan Poetry appears). Continuing, you might play a part of

    Prokofievs , as it was written in 1936, the same year as Alan Turingsseminal paper on undecidability of the Halting Problem, and so on. The ordering of the

    songs is important, so just because you could play song X after song Y it will not

    necessarily be the case that you can play song Y after song X. At the same time asachieving this sense of continuity, you also want the playlist to have a bit of variation, so

    all nine songs must be by different artists.

    You have narrowed things down to a bunch of your favorite songs, but finding a list of

    nine songs with a common thread seems tricky. Maybe you could use your programmingskills to find a good playlist?

    Input

    The first line of input consists of an integern (9n100), the number of songs. Thenfollow n lines. Each line describes a song, starting with the name of the artist (as a stringof a-z of at most 15 characters), followed by an integert(1t40), the number ofsongs that can be played directly after this song. Then follows (on the same line) tdistinct integers s1,,st, each between 1 and n, giving the numbers of the songs thatcan be played after the current song. The songs are numbered from 1 to n, with songnumber1 being described on the first line, and so on.

    OutputIf there is a playlist of nine songs satisfying the requirements, output a list of nineintegers giving the numbers of the songs (according to the same numbering as in the

    input), in the order they should be played. Otherwise, output a single line containing the

    word fail. If there is more than one valid playlist, any one of them will be accepted.

    Sample Input 1 Sample Output 110

    a 2 10 3

    b 1 6

    c 2 1 5d 1 9

    e 1 4f 1 2

    g 2 6 8

    h 0

    i 1 3j 1 7

    5 4 9 3 1 10 7 6 2

    Sample Input 2 Sample Output 210 fail

  • 7/28/2019 All Just a Dream

    8/15

    a 2 10 3

    a 1 6

    c 2 1 5

    d 1 9e 1 4

    f 1 2g 2 6 8

    h 0

    i 1 3

    j 1 7

    Sample Input 3 Sample Output 310

    a 2 10 3b 1 6

    c 2 1 5d 1 9

    e 1 9

    f 1 2

    g 2 6 8h 0

    i 1 3j 1 7

    fail

    Square Pie

    Problem id: squarepie

    Time limit: 11 secondsMemory limit: 2048 MB

    You are working on an OCR (Optical Character Recognition) application to convert

    scanned images into text format. In addition to just being able to parse text, you plan to

    have your software recognize graphs and transcribe them in a meaningful way. Havingalready handled histograms, bar graphs, scatter plots and regular pie charts, you have now

    worked your way tosquare pie charts.

    A square pie chart consists of a rectangle subdivided into regions by horizontal or vertical

    lines. Just like a regular pie chart, the different regions represents how large fractions ofsomething (e.g., baked desserts) are taken up by various subcategories (e.g., pies,

    cookies, etc). See the figure below for an example.

  • 7/28/2019 All Just a Dream

    9/15

    Figure 1: A square pie chart. This is a drawing of the second example case.

    The module you are working on will be given a set of horizontal and vertical linesegments forming a square pie chart, and should compute the sizes of the different

    regions of the chart.

    The set of line segments is guaranteed to have been constructed as described above. In

    other words, four of them form a rectangle constituting the boundary of the square piechart, and then each remaining line segment divides one rectangle into two smaller ones.

    Note that this means that the line segments do not intersect, except that the endpoints of

    each line segment touches some other line segment. However, the order of the linesegments in the input is completely arbitrary and you can not assume that they are given

    in the order they were drawn.

    Input

    The first line of input consists of a single integern (4n100000), the number oflines of the pie chart. Each of the following n lines consists of four integers x1,y1,x2,y2, indicating a line segment from (x1,y1) to (x2,y2). The line segment is eitherhorizontal (i.e.,x1x2 andy1=y2) or vertical (i.e.,x1=x2 andy1y2). Each

    coordinate is at most 109 in absolute value.

    Warning

    This problem has somewhat large amounts of input and output. We recommend you tomake sure that your input and output are properly buffered in order to make the most of

    the few seconds of execution time that we give you.

  • 7/28/2019 All Just a Dream

    10/15

    Output

    If there are m regions in the pie chart, the output should consist ofm lines, giving thesizes of the different regions (as fractions of the entire chart), in non-increasing order.

    You do not need to worry about the precise formatting of the sizes (e.g., number of

    decimals), but the absolute error of each size must be smaller than 109.

    Sample Input 1 Sample Output 14

    2 2 6 26 2 6 6

    6 6 2 6

    2 6 2 2

    1

    Sample Input 2 Sample Output 28

    6 2 0 2

    0 0 6 0

    0 2 0 02 2 2 13 1 3 0

    0 1 6 16 0 6 2

    2 1 2 0

    0.333333333333

    0.25000.16666666670.16666666667

    0.0833333333

    Peer Streaming

    Problem id: streamingTime limit: 12 seconds

    Memory limit: 2048 MB

  • 7/28/2019 All Just a Dream

    11/15

    Photo by Tanbir Ahmed via Wikimedia Commons

    You are developing software to stream music to users over the Interwebs. In order toreduce network traffic for your servers, you plan to do this in a peer-to-peer way: a user

    who has listened to a given song for a while longer than some other user will have parts

    of the song that the second user needs and can send them to her directly.

    It is now time to develop the logic to decide which users should send which data to whichother users. At a high level, the logic works as follows. Each second, the data available at

    the different users listening to a song is examined. Based on this, the system decides what

    data users should transmit, and to whom.

    To be specific, suppose there are n users currently listening to the song. The ith users

    playback is currently at thepith byte of the song, and has already received the firstbipi bytes of the song, and no other parts of the song. Furthermore, each user has abandwidth ui bounding how many bytes she can upload in total to other users during theone second interval. After one second, each users playback will be C bytes further, i.e.,the ith user will be at byte pi+C. Each user now has the first bi bytes of the song,where bi depends exactly on what data was received from other users during the second.Thus, after the one second interval, the buffer that the ith user has is bi(pi+C) bytes.During the one second interval, a user can only upload data that she had before the

  • 7/28/2019 All Just a Dream

    12/15

    interval started (i.e., from the first bi bytes of the song). A user can send data to anynumber of other users, but in order to send a piece of data to several users it needs to besent to each user individually.

    In order to minimize the risk for jitter, the system should make sure that each users

    buffer is as large as possible. Specifically, the goal is to make sure that after the secondhas passed, the minimum buffer size bi(pi+C) is as large as possible. Note that it maybe the case that this value is negative, indicating that it is impossible to avoid that someuser runs out of buffer during the one second interval.

    For simplicity, well assume that this takes place on the Interwebs of an alternate reality

    where upload speeds are completely captured by the ui parameters (e.g., they do notdepend on where the data is being uploaded to), and there are no such things as packet

    losses, slow ping times, or anything else that might make the idealized situation described

    here unrealistic.

    Input

    The first line of input contains two integers n (1n50000) and C (1C109).Then follow n lines. The ith of these lines contains the three integers pi, bi, ui withmeanings as described above. You may assume that 0pibi109, and 0ui109.

    Warning

    This problem has somewhat large amounts of input. We recommend you to make sure

    that your input is properly buffered in order to make the most of the few seconds of

    execution time that we give you.

    Output

    Output a single line containing an integerB, the maximum possible smallest buffer sizeafter one second.

    Sample Input 1 Sample Output 13 20

    50 70 10100 110 4

    150 190 16

    5

    Sample Input 2 Sample Output 24 100

    0 50 1000 50 100

    0 50 100

    1000 1500 100

    -17

  • 7/28/2019 All Just a Dream

    13/15

    Cat Coat Colors

    Problem id: catcoatTime limit: 1 seconds

    Memory limit: 2048 MB

    Photo by Pedro Ribeiro Simes (p...