IIT Kh C Problems

  • Upload
    talk2ap

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

  • 8/9/2019 IIT Kh C Problems

    1/24

    First

    Second

    Third

    Fourth

    Fifth

    Sixth

    Attempt No 1

    Problem 1: Susan' GCD

    The famous cryptographer Susan explained her friend David

    the Euclidean

    algorithm to calculate the GCD of two numbers.

    Then Susan implements the GCD-algorithm :

    int gcd(int a, int b){

    if (b==0)

    return a;

    else

    return gcd(b,a%b);

    }

    and it proposes to use the algorithm with a little integer

    and another

    integer that has up to 250 digits.

    Your task is to help David programming an efficient code

    for the

    challenge of his wife Susan.

    Input:

    The first line of the input file contains a number

    representing the

    number of lines to follow. Each line consists of two

    numbers A and B

    (0

  • 8/9/2019 IIT Kh C Problems

    2/24

    10 11

    Output:

    2

    1

    Filename:

    Submit

    Attempt No 1

    Problem 2: Susan's Primality Testing

    Susan has introduced the concept of Primality into thecommon Binary

    language of computers.

    Computers use only 2 alphabet symbol 1 and 0 to make

    words. A given word

    is called "prime" if it cannot be written in the form of

    the concatenation

    of several copies of some shorter word.

    For example the words '01', '110', and '0010' are prime,

    while the words

    '11', '100100', '110110', are not prime.

    So, here we give a challenge to you this time, to

    calculate the number of

    prime words which you can form from exactly x 1s and y 0s.

    Input:

    The first line specifies the number of test cases t. For

    each test case,

  • 8/9/2019 IIT Kh C Problems

    3/24

    two integers: 1

  • 8/9/2019 IIT Kh C Problems

    4/24

    (0.2 attr1

    (0.81 attr1

    (0.3)

    (0.2)

    )

    (0.1 attr2

    (0.3 attr3

    (0.01)

    (0.01)

    )

    (0.1)

    )

    )

    A decision tree is defined recursively. It always has a

    root node and a

    weight(frequency here). It also, optionally, has a node-

    name and two

    sub-trees, which are themselves decision trees.More formally, a decision tree is defined using the

    following grammar.

    tree ::= (weight [feature tree tree])

    weight is a real number between 0 and 1,inclusive

    node-name is a string of 1 or more lower case English

    letters

    The part inside the square brackets, [], is optional. The

    parentheses, (),

    weight and name are tokens. There will be at least one

    whitespace character

    between any two tokens, except (possibly) after an open-bracket '('

    or before a close-bracket ')'. Whitespace characters are

    space (' ') and

    endline ('\n').

    To figure out the efficiency of a server, we start at the

    root of the tree

    with weight p set to 1. At each node, we multiply p by the

    weight of the

    node. If the node is a leaf (has no sub-trees), then we

    stop, and the value

    of p is the final efficiency of the entire server.Otherwise, we look at

    the node-attribute associated with the node. If the server

    has this

    node-attribute, we move down into the first sub-tree(first

    child server)

    and continue recursively. If it does not have this

    attribute, then we move

  • 8/9/2019 IIT Kh C Problems

    5/24

    down into the second sub-tree(second server) and continue

    in the same way.

    In the above example, there is a single server and it has 2

    attributes:

    attr1 and attr3. We start at the root with p equal to 1. We

    multiply p by

    0.2, the weight of the root and move into the first sub-

    tree because the

    first child-server has that attribute. There, we multiply p

    by 0.81, which

    makes p equal to 0.162. From there we move further down

    into the first

    sub-tree because the server has attribute attr1. Finally,

    we multiply p

    by 0.3 and end up with 0.0486 as the final efficiency.

    You will be given a decision tree and a list of servers

    with their

    attributes. For each item, you need to return theefficiency of a server.

    Input:

    The first line of input contains a single integer, N, the

    number of test

    cases.

    N test cases follow.

    Each test case description will start with a line that

    contains an integer

    L --

    the number of lines that describe a decision tree. The nextL lines will

    contain

    a decision tree in the format described above. The line

    after that will

    contain

    A -- the number of servers. The next A lines will each

    contain the

    description of

    one server in the following format.

    server n attribute1 attribute2 ... attributen

    Output:

    For each test case, output one line containing "Case #x:"

    followed by

    exactly A

    lines, one per server, in the same order as they appear in

    the input.

    Each line

  • 8/9/2019 IIT Kh C Problems

    6/24

    should contain the efficiency of server. Answers that are

    precise to

    within an

    absolute or relative error of 10-6 will be considered

    correct.

    Limits

    1 N 100

    All weights will be between 0 and 1, inclusive.

    All weights will consist of only digits with at most one

    decimal point.

    The weights will not start or end with a decimal point.

    The weights will not have more than one 0 before a decimal

    point.

    All servers and attributes will consist of between 1 and 10

    lower case

    English

    letters.

    All server names within a test case will be distinct.All attribute names for a single server will be distinct.

    Each of the L lines in a decision tree definition will have

    at most 80

    characters,

    not including the endlines.

    Small dataset

    1 L 10

    1 A 10

    0 n 5

    Large dataset1 L 100

    1 A 100

    0 n 100

    Example:

    Input:

    1

    7

    (0.084016 pj

    (0.680189 hd(0.465482)

    (0.912155)

    )

    (0.066448)

    )

    8

    yad 0

  • 8/9/2019 IIT Kh C Problems

    7/24

    ljxslm 2 hd pj

    yuufr 2 hd pj

    qqdtg 0

    vkmqyd 1 hd

    tubm 2 hd pj

    ddm 2 hd pj

    okwes 1 hd

    Output:

    Case #1:

    0.00558270

    0.02660079

    0.02660079

    0.00558270

    0.00558270

    0.02660079

    0.02660079

    0.00558270

    Filename:

    Submit

    Attempt No 1

    Problem 4: TRANSLTR At Work !!

    TRANSLTR, like all great technological advancements, had

    been a child of

    necessity. Its three million processors would all work inparallelcounting upward at blinding speed, trying

    every new permutation as they went. The hope was that even

    codes within

    thinkably colossal pass-

    keys would not be safe from TRANSLTRs tenacity.

    This multi-billion-dollar masterpiece would use

    the power of parallel processing as well as some highly

    classifiedadvances in clear text assessment to

    guess pass-keys and break codes. It would derive its power

    not only from

    its staggering number of

    processors but also from new advances in quantum-computing

    .

  • 8/9/2019 IIT Kh C Problems

    8/24

    The moment of truth came on a blustery Thursday morning in

    October.

    The first live test.

    Testing strategy utilises a very simple encoding scheme.

    Scheme: Assign A the code word 1, B will be 2, and so

    on down to Z

    being assigned 26.

    So, the encoding of the word BEAN is: 25114. Does it have

    a unique

    decoding ?-----

    Ans: Obviously No !!.......Other than BEAN, youd get

    BEAAD, YAAD,

    YAN, YKD and BEKD.

    If you got a string of length 5000 there would be tons of

    differentdecoding and with that many you would find at least two

    different ones

    that would make sense.

    Q: How many different decoding?

    A: Jillions!

    Your task is to determine how many decoding there can be

    for a given

    string .

    Input:Input will consist of multiple input sets. Each set will

    consist of a

    single line of at most 5000 digits representing a valid

    encryption

    (for example, no line will begin with a 0). There will be

    no spaces

    between the digits. An input line of 0 will terminate the

    input and

    should not be processed.

    Output:For each input set, output the number of possible decoding

    for the input

    string. All answers will be within the range of a 64 bit

    signed integer.

    Example:

  • 8/9/2019 IIT Kh C Problems

    9/24

    Input:

    25114

    1111111111

    3333333333

    0

    Output:

    6

    89

    1

    Filename:

    Submit

    Attempt No 1

    Problem 5: Hacking NSA security

    Strathmore has been caught wanting by Ernie Tankoda, as

    Strathmore has

    run the Digital Fortress, a junk of malicious code from

    Tankoda. All

    the gates are being broken one-by-one and only a few have

    been left.

    The Security of NSA has been defined in a unique recursive

    way, such

    that a gate numbered k is protected by all gates upto k-1

    in followingway:

    s0 = ()

    sk = (s0s1.....sk-1)

    Your task is to identify those gates which are yet to be

    broken. The

    more efficiently you can find it, more time you have to

    save those

    gates.

    In each test case, you are given k, l, m, where k defines

    the Level ofsecurity( k in the above recurrence ). l defines the

    starting position

    of the vulnerable gate and m defines the number of

    vulnerable gates

    and you have to print all the vulnerable gates in the above

    range.

  • 8/9/2019 IIT Kh C Problems

    10/24

    Input:

    The first line specifies the number of test cases t.

    For each test case, two integers: 1

  • 8/9/2019 IIT Kh C Problems

    11/24

    Given N, the last number you wrote, compute what the next

    number in

    the list will be.

    Input:

    The first line of input contains an integer T, the number

    of test

    cases in the input. T lines follow, one for each test case,

    each

    containing a single integer N.

    Output:

    For each test case, output

    Case #X: K

    where X is the test case number, starting from 1, and K is

    the next

    integer in the list.

    LimitsSmall dataset

    1 T 50

    1 N 106

    Large dataset

    1 T 500

    1 N 1020

    Examples:

    Input:

    1118, 181, 811

    Output:

    Case #1: 1018

    Filename:

    Submit

    No 1 : 0

    No 2 : 0No 3 : 0

    No 4 : 0

    No 5 : 0

    No 6 : 0

    Total Marks : 0

    http://203.110.240.102/overnite/index1.php#problems
  • 8/9/2019 IIT Kh C Problems

    12/24

    Reply Forward

    Reply

    |

    Ambujpandey ---------- Forwarded message ---------- From: Ambuj pandey

  • 8/9/2019 IIT Kh C Problems

    13/24

    and it proposes to use the algorithm with a little integer

    and another

    integer that has up to 250 digits.

    Your task is to help David programming an efficient code

    for the

    challenge of his wife Susan.

    Input:

    The first line of the input file contains a number

    representing the

    number of lines to follow. Each line consists of two

    numbers A and B

    (0

  • 8/9/2019 IIT Kh C Problems

    14/24

    Computers use only 2 alphabet symbol 1 and 0 to make

    words. A given word

    is called "prime" if it cannot be written in the form of

    the concatenation

    of several copies of some shorter word.

    For example the words '01', '110', and '0010' are prime,

    while the words

    '11', '100100', '110110', are not prime.

    So, here we give a challenge to you this time, to

    calculate the number of

    prime words which you can form from exactly x 1s and y 0s.

    Input:

    The first line specifies the number of test cases t. For

    each test case,

    two integers: 1

  • 8/9/2019 IIT Kh C Problems

    15/24

    Output:

    4

    Filename:

    Submit

    Attempt No 1

    Problem 3: NSA Servers Efficiency

    NSA servers have been arranged in special manners and have

    been organized

    in special trees, called classification trees. In this

    data-structure,every server is characterised by its own clock-frequency

    (in Tera flip-flops) and a node-attribute.

    For any given server, we can decide its efficiency by

    looking at the

    frequencies of all its child nodes and using the following

    decision tree.

    (0.2 attr1

    (0.81 attr1

    (0.3)

    (0.2)

    )(0.1 attr2

    (0.3 attr3

    (0.01)

    (0.01)

    )

    (0.1)

    )

    )

    A decision tree is defined recursively. It always has a

    root node and a

    weight(frequency here). It also, optionally, has a node-name and two

    sub-trees, which are themselves decision trees.

    More formally, a decision tree is defined using the

    following grammar.

    tree ::= (weight [feature tree tree])

    weight is a real number between 0 and 1,inclusive

  • 8/9/2019 IIT Kh C Problems

    16/24

    node-name is a string of 1 or more lower case English

    letters

    The part inside the square brackets, [], is optional. The

    parentheses, (),

    weight and name are tokens. There will be at least one

    whitespace character

    between any two tokens, except (possibly) after an open-

    bracket '('

    or before a close-bracket ')'. Whitespace characters are

    space (' ') and

    endline ('\n').

    To figure out the efficiency of a server, we start at the

    root of the tree

    with weight p set to 1. At each node, we multiply p by the

    weight of the

    node. If the node is a leaf (has no sub-trees), then we

    stop, and the value

    of p is the final efficiency of the entire server.Otherwise, we look at

    the node-attribute associated with the node. If the server

    has this

    node-attribute, we move down into the first sub-tree(first

    child server)

    and continue recursively. If it does not have this

    attribute, then we move

    down into the second sub-tree(second server) and continue

    in the same way.

    In the above example, there is a single server and it has 2

    attributes:attr1 and attr3. We start at the root with p equal to 1. We

    multiply p by

    0.2, the weight of the root and move into the first sub-

    tree because the

    first child-server has that attribute. There, we multiply p

    by 0.81, which

    makes p equal to 0.162. From there we move further down

    into the first

    sub-tree because the server has attribute attr1. Finally,

    we multiply p

    by 0.3 and end up with 0.0486 as the final efficiency.You will be given a decision tree and a list of servers

    with their

    attributes. For each item, you need to return the

    efficiency of a server.

    Input:

  • 8/9/2019 IIT Kh C Problems

    17/24

    The first line of input contains a single integer, N, the

    number of test

    cases.

    N test cases follow.

    Each test case description will start with a line that

    contains an integer

    L --

    the number of lines that describe a decision tree. The next

    L lines will

    contain

    a decision tree in the format described above. The line

    after that will

    contain

    A -- the number of servers. The next A lines will each

    contain the

    description of

    one server in the following format.

    server n attribute1 attribute2 ... attributen

    Output:

    For each test case, output one line containing "Case #x:"

    followed by

    exactly A

    lines, one per server, in the same order as they appear in

    the input.

    Each line

    should contain the efficiency of server. Answers that are

    precise to

    within anabsolute or relative error of 10-6 will be considered

    correct.

    Limits

    1 N 100

    All weights will be between 0 and 1, inclusive.

    All weights will consist of only digits with at most one

    decimal point.

    The weights will not start or end with a decimal point.

    The weights will not have more than one 0 before a decimal

    point.

    All servers and attributes will consist of between 1 and 10lower case

    English

    letters.

    All server names within a test case will be distinct.

    All attribute names for a single server will be distinct.

    Each of the L lines in a decision tree definition will have

    at most 80

  • 8/9/2019 IIT Kh C Problems

    18/24

    characters,

    not including the endlines.

    Small dataset

    1 L 10

    1 A 10

    0 n 5

    Large dataset

    1 L 100

    1 A 100

    0 n 100

    Example:

    Input:

    1

    7

    (0.084016 pj(0.680189 hd

    (0.465482)

    (0.912155)

    )

    (0.066448)

    )

    8

    yad 0

    ljxslm 2 hd pj

    yuufr 2 hd pj

    qqdtg 0vkmqyd 1 hd

    tubm 2 hd pj

    ddm 2 hd pj

    okwes 1 hd

    Output:

    Case #1:

    0.00558270

    0.02660079

    0.02660079

    0.005582700.00558270

    0.02660079

    0.02660079

    0.00558270

  • 8/9/2019 IIT Kh C Problems

    19/24

    Filename:

    Submit

    Attempt No 1

    Problem 4: TRANSLTR At Work !!

    TRANSLTR, like all great technological advancements, had

    been a child of

    necessity. Its three million processors would all work in

    parallelcounting upward at blinding speed, trying

    every new permutation as they went. The hope was that even

    codes within

    thinkably colossal pass-

    keys would not be safe from TRANSLTRs tenacity.

    This multi-billion-dollar masterpiece would use

    the power of parallel processing as well as some highly

    classified

    advances in clear text assessment to

    guess pass-keys and break codes. It would derive its power

    not only from

    its staggering number of

    processors but also from new advances in quantum-computing

    .

    The moment of truth came on a blustery Thursday morning inOctober.

    The first live test.

    Testing strategy utilises a very simple encoding scheme.

    Scheme: Assign A the code word 1, B will be 2, and so

    on down to Z

    being assigned 26.

    So, the encoding of the word BEAN is: 25114. Does it have

    a unique

    decoding ?-----

    Ans: Obviously No !!.......Other than BEAN, youd getBEAAD, YAAD,

    YAN, YKD and BEKD.

    If you got a string of length 5000 there would be tons of

    different

  • 8/9/2019 IIT Kh C Problems

    20/24

    decoding and with that many you would find at least two

    different ones

    that would make sense.

    Q: How many different decoding?

    A: Jillions!

    Your task is to determine how many decoding there can be

    for a given

    string .

    Input:

    Input will consist of multiple input sets. Each set will

    consist of a

    single line of at most 5000 digits representing a valid

    encryption

    (for example, no line will begin with a 0). There will be

    no spaces

    between the digits. An input line of 0 will terminate theinput and

    should not be processed.

    Output:

    For each input set, output the number of possible decoding

    for the input

    string. All answers will be within the range of a 64 bit

    signed integer.

    Example:

    Input:

    25114

    1111111111

    3333333333

    0

    Output:

    6

    89

    1

    Filename:

    Submit

    Attempt No 1

    Problem 5: Hacking NSA security

  • 8/9/2019 IIT Kh C Problems

    21/24

    Strathmore has been caught wanting by Ernie Tankoda, as

    Strathmore has

    run the Digital Fortress, a junk of malicious code from

    Tankoda. All

    the gates are being broken one-by-one and only a few have

    been left.

    The Security of NSA has been defined in a unique recursive

    way, such

    that a gate numbered k is protected by all gates upto k-1

    in following

    way:

    s0 = ()

    sk = (s0s1.....sk-1)

    Your task is to identify those gates which are yet to be

    broken. The

    more efficiently you can find it, more time you have tosave those

    gates.

    In each test case, you are given k, l, m, where k defines

    the Level of

    security( k in the above recurrence ). l defines the

    starting position

    of the vulnerable gate and m defines the number of

    vulnerable gates

    and you have to print all the vulnerable gates in the above

    range.

    Input:

    The first line specifies the number of test cases t.

    For each test case, two integers: 1

  • 8/9/2019 IIT Kh C Problems

    22/24

    Filename:

    Submit

    Attempt No 1

    Problem 6: National SecurityAgency Selection Test

    Congratulations, Mr. Becker. I hear you did a fine job

    today,

    Susan said.

    And, National Security Agency offered David Becker a

    trial post in theirAsiatic Cryptography Division.

    What David did was simple, he just predicted the next

    number in a

    list L.

    Every number in the list L satisfies the property that thelist

    contains all numbers with exactly Di digits in its decimal

    representation which are equal to i, for each i between 1

    and 9,

    inclusive in ascending order.

    For example, if you consider every number with just two

    '1's and

    one '8', then the list would begin as : 118, 181, 811,

    1018, 1081

    ..................

    Given N, the last number you wrote, compute what the nextnumber in

    the list will be.

    Input:

    The first line of input contains an integer T, the number

    of test

    cases in the input. T lines follow, one for each test case,

    each

    containing a single integer N.

    Output:For each test case, output

    Case #X: K

    where X is the test case number, starting from 1, and K is

    the next

    integer in the list.

    Limits

    Small dataset

  • 8/9/2019 IIT Kh C Problems

    23/24

    1 T 50

    1 N 106

    Large dataset

    1 T 500

    1 N 1020

    Examples:

    Input:

    1

    118, 181, 811

    Output:

    Case #1: 1018

    Filename:

    Submit

    No 1 : 0

    No 2 : 0

    No 3 : 0

    No 4 : 0

    No 5 : 0

    No 6 : 0

    Total Marks : 0

    Reply Forward Apaar is not available to chat

    Reply

    |

    Mail Delivery Subsystem

    to me

    show details 5:24 PM (9 minutes ago)

    Delivery to the following recipient failed permanently:

    [email protected]

    Technical details of permanent failure:

    The email account that you tried to reach does not exist. Please try double-checking therecipient's email address for typos or unnecessary spaces. Learn more at

    http://mail.google.com/support/bin/answer.py?answer=6596

    mailto:[email protected]://mail.google.com/support/bin/answer.py?answer=6596http://203.110.240.102/overnite/index1.php#problemsmailto:[email protected]://mail.google.com/support/bin/answer.py?answer=6596
  • 8/9/2019 IIT Kh C Problems

    24/24

    ----- Original message -----

    Return-Path:

    Received-SPF: pass (google.com: domain [email protected] designates

    10.229.90.68 as permitted sender) client-ip=10.229.90.68;Authentication-Results: mr.google.com; spf=pass (google.com: domain of

    [email protected] designates 10.229.90.68 as permitted sender)

    [email protected]; dkim=pass [email protected]: from mr.google.com ([10.229.90.68])

    mailto:[email protected]://google.com/mailto:[email protected]://mr.google.com/http://google.com/mailto:[email protected]:[email protected]:[email protected]://mr.google.com/mailto:[email protected]://google.com/mailto:[email protected]://mr.google.com/http://google.com/mailto:[email protected]:[email protected]:[email protected]://mr.google.com/