hunman programming contest 2015 problem set

Upload: asir-mosaddek-sakib

Post on 16-Feb-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    1/13

    The 11th Hunan CollegiateProgramming Contest

    Online Version(with more input data and tighter time limits)

    30thAugust, 2015

    You get 13 Pages11 Problems

    &300 Minutes

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    2/13

    AAerial Tramway

    Input:Standard InputOutput:Standard Output

    An aerial tramway, cable car, ropeway or aerial tram is a type of aerial lift which uses one or two

    stationary ropes for support while a third moving rope provides propulsion. With this form of lift, the

    grip of an aerial tramway cabin is fixed onto the propulsion rope and cannot be decoupled from it

    during operations.

    -- Wikipedia

    ou own a park located on a mountain, which can be described as a se!uence of npoints (xi, yi) from

    left to right, where xi,yi"#, xi$xi%&, yi'yi%&(that means there will not be horiontal segments in the

    mountain skyline), illustrated below (the x-coordinate of piis i)*

    +ince the mountain is very sloppy, some aerial tramways across the park would be very helpful. n the

    figure above, people can go from pto pdirectly, by taking a tram. /therwise he must follow a rather

    igag path* p-p0-p1-p2-p3-p.

    our 4ob is to design an aerial tramway system. 5here should be exactly m trams, each following a

    horiontal segment in the air, between two points p i and p4. 67oriontal6 means yiy4, 8in the air6

    means all the points in between are strictly below, i.e. yk$yifor every i$k$4. 9or example, no tram can

    travel between p:and p, because pis not strictly below p:-p. 7owever, you can have two trams, one

    from p:to p, and one pto p. 5here is another important restriction* no point can be strictly below k

    or more tramways, because it;ll be dangerous. 9or example, if k

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    3/13

    Input5here will be at most :## test cases. =ach case begins with three integers n, m and k(&$n,m$:##,

    :$k$), the number of points, the number of trams in your design and the dangerous parameter

    introduced earlier. 5he next line contains n pairs of positive integers xiand yi.(&$xi,yi$).

    Output9or each test case, print the case number and the maximal sum. f it is impossible to have exactly mtramways, print -&.

    Sample Input Output for Sample Input14 3 3

    1 8

    2 6

    3 4

    4 6

    5 3

    6 4

    7 1

    8 4

    9 6

    10 4

    11 6

    12 5

    13 6

    14 8

    14 3 2

    1 8

    2 63 4

    4 6

    5 3

    6 4

    7 1

    8 4

    9 6

    10 4

    11 6

    12 5

    13 614 8

    Case 1: 20

    Case 2: 9

    Problemsetter: Rujia Liu, Special Thanks: Md. Mahbubul Hasan, Md. Shiplu Halader, !en"#hen

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    4/13

    BBigger or Smaller

    Input:Standard InputOutput:Standard Output

    >iven two floating-point numbers, determine whether the first one is bigger, smaller or the same as the

    second one. =ach floating point number is formatted as

    [integer part].[fraction part]

    9or simplicity, both of the integer part and fraction part of the given floating point numbers will be

    non-empty, and the integer part will not have leading eros. 7owever, fraction part can have trailing

    eros, so #.# is the same as #.###.

    Input

    5here will be at most :# test cases. =ach test case contains a single line with two floating-pointnumbers formatted as above. =ach number is a string with no more than # characters.

    Output9or each test case, print the case number, and one of 6?igger6, 6+maller6 and 6+ame6.

    Sample Input Output for Sample Input1.0 2.0

    0.00001 0.00000

    0.0 0.000

    @ase &* +maller

    @ase :* ?igger

    @ase

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    5/13

    CCommon Area

    Input:Standard InputOutput:Standard Output

    >iven two simple polygons, your task is to determine whether they have a non-empty common area.ote that the two rectangles in figure (a) share a segment, but no common area at all.

    ?y 6simple polygon6, we mean the polygons will not be self-intersecting or self-touching, and will nothave duplicated vertices or ad4acent collinear segments.

    ote* be sure to test your program with many special cases.

    Input5here will be at most # test cases. =ach test case contains two lines, one for each polygon. =ach

    polygon begins with an integer n (

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    6/13

    DDefeat the Wrong Program

    Input:Standard InputOutput:Standard Output

    9ind a cell in an nBmgrid such that the sum of integers in the 6cross shape6 (a cell and all the cells inthe same row or column) is maximied. If the answer is not unique, you can print any solution.

    n the example below*

    $ $ $ $

    % % $ %

    % % $ %

    % % $ %

    5he best solution is (&,

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    7/13

    EEasy Graph Problem?

    Input:Standard InputOutput:Standard Output

    >iven a grid mae with n rows and m columns, each cell is either an obstacle or has a cost associated.

    our task is to go from (r&,c&) to (r:,c:) with minimum cost. n each step, you can go up, down, left or

    right, but not diagonally. /f course you cannot go into an obstacle or go out of the mae. 5he total

    cost of a path e!uals the sum of costs in each cell in the path.

    n the picture below, all shaded cells are obstacles. f you go along A-"?-"F-"9-"=, the cost is

    %

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    8/13

    FFactorial Diision

    Input:Standard InputOutput:Standard Output

    >iven two positive integers n, m, find out n'Cm', where n' &B:B

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    9/13

    GGraph G!essing

    Input:Standard InputOutput:Standard Output

    5here is a strongly-connected graph (i.e. you can reach any node from any other node) with n nodes

    and m edges. will choose some of the edges to make another strongly connected graph. our task is

    to guess that graph. 5oo difficult, rightD Fon;t worry, you only need to guess k edges. f all the edges

    exist in my graph, you win. promise that from all possible graphs, the answer will be chosen

    uniformly. The original graph will not have self-loops or duplicated edges.

    ou already have a guess, but you are a bit unsure. Why not write a program to calculate the

    probability you winD 9or example, if n, m0, the original graph has 0 edges* &-":, :-"

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    10/13

    H

    "eheInput:Standard Input

    Output:Standard Output

    5here is a @hinese 4oke* 6@hat ends with hehe6. >iven a chat log, count how many conversations end

    with a sentence containing the word 6hehe6 (or variations, see below).

    5o check whether the sentence contains 6hehe6, first replace any non-alphabetic characters with

    spaces, convert the characters to lower-case and extract a list of words. 9or example, 67i' Are you

    /ID6 becomes a list of words* hi, are, you, ok. Note that the list of words could be empty.

    ote that some people prefer to use 6hehehe6 or 6hehehehe6 instead of 6hehe6, so a word formed by

    n(n"&) copies of 6he6 should be regarded as a variation of 6hehe6. 7owever, there are some other

    words which contain 6hehe6 as a consecutive substring. FonHt consider them'

    Input5here is only one test case. =ach line is a record formatted as

    Na%e1#(Na%e2: sentence.

    =ach line will have at most ## characters, and there will be at most # lines.

    OutputJrint the percentage (rounded to the nearest integer) of conversations ended with 6hehe6 or its variants.

    5he test data will be carefully chosen so that the answer will not be e!ually near to two integers.

    Sample Input Output for Sample Input)#(*: +e''o,

    )#(C: +i,

    *#(): +e-e

    *#(: +ei,

    #(*: +o/ are o

    )#(C: +i

    )#(C: )re o t-ere

    *#(: +e-e-ei,

    #(*: W-at oes -e-e-ei %ean#(: $ /ant to -e-e-e-e-e a-.

    50

    Explanation@onverstation between A and ? ends with 67ehe6.

    @onverstation between A and @ ends with 6Are you thereD6.

    @onverstation between ? and F ends with 6What does hehehei meanD6.

    @onverstation between = and 9 ends with 6 want to hehehehehe yah6.

    /nly the first one and the last one ends with 6hehe6 (and variants), so the answer is 0#K.

    Problemsetter: Rujia Liu, Special Thanks: Md. Mahbubul Hasan, !en" #hen

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    11/13

    I#nternet of $ights an%

    SwitchesInput:Standard Input

    Output:Standard Output

    ou are a fan of 6nternet of 5hings6(o5), so you build a nice nternet of Lights and +witches in your

    huge mansion. 9ormally, there are nlights and mswitches, each switch controls one or more lights, i.e.

    pressing that switch flips the status of those lights (on-"off, off-"on).

    nitially, all the lights are on. our task is to count the number of ways to turn off all the lights by

    pressing some consecutiveswitches. 5here is only one restriction* the number of switches you pressed

    should be between a and b (inclusive).

    Input

    5here will be at most :# test cases. =ach test case begins with a line containing four integers n, m, a, b(:$n$0#, &$a$b$m$

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    12/13

    J&!st Another Easy Problem

    Input:Standard InputOutput:Standard Output

    >iven a four-digit integer n, your task is to count the number of ways to make it a s!uare number by

    changing exactly one digit (note that you can;t change the first digit to #). 9or example, if n23,

    there are two ways*

  • 7/23/2019 Hunman Programming Contest 2015 Problem Set

    13/13

    K'eep Fit(

    Input:Standard InputOutput:Standard Output

    ou;re designing a game console with a special board which can evaluate how balance people are.

    After the user stands on the board, it can record the movement of the userHs 6center of gravity6.

    5echnically, the record is a se!uence of n points on the :F plane (the userHs 6center of gravity6

    pro4ected to the game board), where the origin (#,#) is the center of the game board. +amples are taken

    every #.#& second, so if the user stands on it for one minute, your database gets 1### sample points.

    n order to know better about his balancing status, the user can ask the game console some !uestions.

    =ach !uestion (i,4) means* count how many pairs of sample points, chosen from the interval between

    the i-th sample and the 4-th sample (inclusive), whose Eanhattan distance is no more thand, where d

    is the presetbalance threshold

    parameter in the system.

    our task is to write a program that can answer the !uestions. ote that you donHt have to answer the

    !uestions one by one. You can read all the questions first, and then answer them.

    Input5here are no more than < test cases. 5he first line contains three integers n, d, !(&$n$:#####,

    &$d$, &$!$##), the number of points, the balance threshold and the number of !ueries. 5he

    next n lines contain the coordinates (x,y) (MxM,MyM$) of the sample points, in order. 5he points are

    numbered &Nn. 5he next ! lines contain the !uestions (i,4) (&$i$4$n).

    Output9or each test case, print the case number in the first line, then the answers of the !uestions, one on

    each line.

    Sample Input Output for Sample Input5 1 2

    0 0

    1 0

    3 0

    2 1

    2 02 4

    1 5

    5 2 2

    0 0

    1 0

    3 0

    2 1

    2 0

    2 4

    1 5

    Case 1:

    0

    4

    Case 2:

    3

    8

    Problemsetter: Rujia Liu, Special Thanks: Md. Mahbubul Hasan