uva problems

Upload: nadim-hussain

Post on 04-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Uva Problems

    1/6

    [Type text]

    A ArithmancyHermione Granger, the most talented witch of her generation, likes to solve various types of

    mathematical problems in the Arithmancy class. Today, the professor has given her the following

    task:

    Find the number of fractions a/bsuch that-

    1. gcd(a, b) = 12. 0< a/b< 13. a * b= (n!) ^ (n!)

    Where n!denotes the factorial of nand ^ denotes power, i.e. (2!) ^ (2!) = 4.

    She is quite confident that she can solve it for n 10^7, but then she remembers that she has to

    study some case history so that she can help Hagrid to win the case of Buckbeak. So, she wants your

    help to solve the problem.

    Input

    There will be one line for each test case containing the number n (1 n 10^7). Input will be

    terminated by EOF. There will be around 20,000test cases.

    Output

    For each case, print the number of fractions in a separate line. This number may be very large, so

    print the answer modulo 10,007.

    Sample Input Output for Sample Input12

    0

    1

  • 8/13/2019 Uva Problems

    2/6

    [Type text]

    B CalendarWe know that there are so many calendar systems. For example, Bangla, Christ, Arabic, Chinese etc.

    This problem is about Decimal calendar. There are 3 months in this calendar. First month is

    Hundreds. There are 300days in this month. Second month is Tens. There are 60days in this

    month. And this followed by the last month Ones having 5or 6days depending on whether this

    is leapyear or not. A Decimal year spans a full Christ calendar. That is 1stHundreds in Decimal

    Calendar is 1stJanuary in Christi Calendar. Similarly, 31stDecember of Christ Calendar is 5thor 6th

    day of Decimal calendar (depending on whether it is leap year or not).

    A year in Decimal calendar is leap year if the corresponding Christ year is leap year. For example, the

    Decimal year corresponding to 2000Christ year is leap year but 2001 is not, and again 1900 is not

    leap year too. A year in Christ calendar is leap year if the year is divisible by 400or divisible by 4but

    not by 100.

    You are given a day in Christ calendar in DD-MMM-YYYY format (DD stands for day, MMM

    stands for first threeletters (in CAPS) of the month andYYYYstands for the year). You are to give

    the date in Decimal Calendar format.

    Input

    First line contains number of test case. Every test case consists of a date in Christ Calendar format

    in each line.

    Output

    You are to output the case number and the date in Decimal Calendar format. Output the date andthe month in the Decimal Calendar.

    Sample Input Output for Sample Input

    3

    01-JAN-1900

    10-JAN-1900

    16-DEC-1900

    Case 1: 1 Hundreds

    Case 2: 10 Hundreds

    Case 3: 50 Tens

    Note

    First three letters for the months are:

    JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC.

  • 8/13/2019 Uva Problems

    3/6

    [Type text]

    C Mr. and Mrs. AntMr. and Mrs. Ant are very hungry. So, they want to collect food as much as they can. They can

    search for foods simultaneously. To do so, they start from their house and collect all foods together

    and meet in some place (not necessarily their house). Finally, they eat together.

    The world of Mr. and Mrs. Ant is a two dimensional grid. Each cell is either the home, or free, or

    blocked, or contains a food. Two cells are adjacent if they share an edge. In each second, they can

    move from one cell to another cell simultaneously. One can decide to not to move in some step,

    while other may move. One cell can be visited many times. Both of them can move into the same

    cell also.

    In this problem, the grid is given by an Rx Cmatrix represented by following characters:

    Character Meaning Remarks

    H Home of Mr. and Mrs. Ant Occurs exactlyonce

    F A food item Occurs at leastonce, at most 8times.

    . (dot) Free (passable) cell

    # (hash) Blocked cell

    Given the grid information, give the minimum amount of time that must be needed for them to

    collect all the foods and then meet.

    Input

    The first line of input will contain T (T 30)denoting the number of cases. Each case starts withtwo integers Rand C(2 R, C 12). Then, Rlines follow giving the grid.

    Output

    For each case, print the case number, the minimum amount of time (in seconds) that must be

    needed for them to collect all the foods and meet. If it is impossible to collect all the food items,

    output -1(negative one) instead.

    Sample Input Output for Sample Input

    2

    2 3

    H#.

    .#F

    2 6

    F#F..#

    ..H#.F

    Case 1: -1

    Case 2: 8

  • 8/13/2019 Uva Problems

    4/6

    [Type text]

    D CricinfoI guess the most visited site of the past 3 months is www.cricinfo.com. First World Cup Cricket,

    then Australia tour to Bangladesh and now IPL T20. I believe there are lots of cricket fans among

    you. So I do not need to describe the game rule. But for the purpose of this problem here is short

    description of scoring. Any rule out of this problem description is not applicable for this problem.

    For this problem we will use only the following outcomes in a ball:

    Possible Outcomein a Ball

    Runs Is the Ball valid?

    . 0 Yes1 1 Yes2 2 Yes3 3 Yes

    4 4 Yes6 6 Yes

    Wd 1 No1Wd 2 No2Wd 3 No4Wd 5 No

    Nb 1 No1Nb 2 No4Nb 5 No6Nb 7 No

    W 0 Yes

    (Wd stands for wide, Nb for No Ball and W for Wicket)

    In cricinfo we always watch the score card. In cricket an over consists of 6 valid balls. A score card

    of an over may look like below:

    1 . W . Wd Nb . 6

    In this over there were 1wicket and 9runs. In the last over of second innings of a match, a team

    requires N runs to win. You are to output number of ways of the outcome of the over. Note that, as

    you are watching second innings of the match, so it may be possible that he can score Nruns in first4 balls and win the match. That means, it is not necessary to play an entire over to score N runs.

    Also suppose you do not know how many wickets are already gone. So it may also be possible that

    after a few wicket falls they are all out. Also note that, if a team scores greater or equal to Nruns the

    team wins and does not play any ball.

  • 8/13/2019 Uva Problems

    5/6

    [Type text]

    Input

    First line contains number of test case T (T 10000). For each test a line contains N

    (1N10000).

    Output

    For every test case, output the case number and number of ways of outcome of the lastover where

    the team needs Nruns to win. As the answer can be very big, so output in mod 10000007.

    Sample Input Output for Sample Input

    1

    1

    Case 1: 946

    Note

    Two ways are different if the outcome of a ball in the last over is different.

  • 8/13/2019 Uva Problems

    6/6

    [Type text]

    E Pole and WireThere are Npoles along a road side. You have to tie wires to the poles. You can attach two ends of

    a wire to two different poles. A pole might not have any wire attached to it. A pole also must not

    have more than one wire attached to it. Two wires must not cross each other but may overlap. For

    example, suppose there are 5poles. Say a wire is from pole 1to pole 4and another from pole 2to

    pole 5. These two wires crossed each other. So such configuration is invalid. But say a wire is from

    pole 1to pole 4and another from pole 2to pole 3. This is overlap, so it is valid configuration.

    Input

    First line of the test file contains number of test cases, T(T300). For every test case you will be

    given number of poles N(1 N10^5).

    Output

    For every test case you are to output number of test case and number of ways of valid configuration.

    As the number of ways is very big you have to output the result in modulo 1,000,003.

    Sample Input Output for Sample Input2

    3

    4

    Case 1: 4

    Case 2: 9

    Hint

    For N= 3, there are 4possible valid configurations.

    No wires attached Wire from Pole 1to Pole 2 Wire from Pole 2to Pole 3 Wire from Pole 1to Pole 3