ISTE Week Overnight Coding

12
ISTE Week Overnite Programming Contest 1 ISTE WEEK OVERNIGHT PROGRAMMING CONTEST RULES: 1) All questions carr y equal weight. 2) T eams found indulg ing in unethical acts su ch as sharing o f solutions or ideas will be disqualified. 3) Approaching the judges table is not allowe d, you ar e supposed to call an organizer to you. 4) Decisions of the judges are final and any team found arguing will be disqualified immediately. 5) Do not close the PC ^2 window. 6) G++/GCC is the C/C++ compiler to be used and the file should be cor rectly compiled in that. 7) If usin g Java, use the file name strictly as per the question. For question no 1, use q1.java(note small caps), for 2 q2.java and so on...... 8) Y ou are no t allowed to leave th e lab in between the conte st unless they wish to quit. 9) Girls are not supposed to leave the lab without informing the organizers, as they will have to be provided appropriate permissions. 10)Usage of books is allowed but no (soft copies /internet) is allowed. For the code: Do not use conio.h The so ln. sho uld be ex act as t he que stio n. Mino r discr epan cies will lead t o failu re. Plea se use #includ e<io stream> a nd not #inclu de<i ostr eam.h> fo r C++ he ader s. C headers go as usual. Do not use ff lush , ex it Scoring: The team with maximum number of cor rect submissions win In cas e of t ies, t he indiv idual submi ssion time o f all t he su bmiss ions will be a dded and then the team with the lesser time wins. Which means it does not mean that you submit the last question first, you win, but in case of a tie, the team having a lead early on may carry an advantage. The scores will not be displayed instantaneousl y . It requires calculation time. The results will be displayed on the ISTE notice board on Wednesday, 20 th Feb. at 12:00PM.  Y ou are allowed to carry bo oks in the finals.

Transcript of ISTE Week Overnight Coding

Page 1: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 1/12

ISTE WeekOvernite Programming Contest

1

ISTE WEEK 

OVERNIGHT PROGRAMMINGCONTEST

RULES:

1) All questions carry equal weight.

2) Teams found indulging in unethical acts such as sharing of solutions or ideas will be

disqualified.

3) Approaching the judges table is not allowed, you are supposed to call an organizer toyou.

4) Decisions of the judges are final and any team found arguing will be disqualified

immediately.

5) Do not close the PC ̂ 2 window.

6) G++/GCC is the C/C++ compiler to be used and the file should be correctly compiled in

that.

7) If using Java, use the file name strictly as per the question. For question no 1, use

q1.java(note small caps), for 2 q2.java and so on......

8) You are not allowed to leave the lab in between the contest unless they wish to quit.

9) Girls are not supposed to leave the lab without informing the organizers, as they willhave to be provided appropriate permissions.

10)Usage of books is allowed but no (soft copies /internet) is allowed.

For the code:

– Do not use conio.h

– The soln. should be exact as the question. Minor discrepancies will lead to failure.

– Please use #include<iostream> and not #include<iostream.h> for C++ headers. C

headers go as usual.

– Do not use fflush, exit

Scoring:

– The team with maximum number of correct submissions win

– In case of ties, the individual submission time of all the submissions will be added

and then the team with the lesser time wins. Which means it does not mean that

you submit the last question first, you win, but in case of a tie, the team having a

lead early on may carry an advantage.

– The scores will not be displayed instantaneously. It requires calculation time. The

results will be displayed on the ISTE notice board on Wednesday, 20 th Feb. at

12:00PM.

 You are allowed to carry books in the finals.

Page 2: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 2/12

ISTE WeekOvernite Programming Contest

2

A long way from here in a parallel universe we have no knowledge of, an

epic battle is being fought that will change everything forever. It is a

battle between the light warriors who are just, kind and righteous and theDark Dominators who spread evil wherever they go. This battle shall also

consequently affect the well being and the prosperity of the human race.

In order to stop the Dark Dominators from spreading into our universe,

the light warriors need your help. The future of this planet now lies in your

hands.

Problem 1

 The Light Warrior techies have just finisheddeveloping ‘The Obliterator’, a massive laser

that destroys anything that comes in its path.

However the amount of energy it uses is too

large (even for the light warriors who are a

gazillion light years ahead of us!!!). Hence the

narrower the beam, the lesser the energy used and more focussed the

destruction. Their scouts have just found several planet systems of the

Dark Dominators. The Light Warriors firstly plan to make the width of the

beam so narrow that the only way to destroy the system is to align it in

such a way that the beam lies in the plane defined by the planets in the

system. Secondly, they make the width so small in length that nothing

bigger than the particular system can be covered by it. Finally, they take

‘The Obliterator’ to a strategic position close to the system, orient it in a

way such that the beam lies in the system's plane and then fire it towards

the constellation in a straight line until the whole system is obliterated.

 You are required to calculate the minimum width of the beam that will

destroy the system given the location of the planets within that system.

 Input Format  Sample Input 

<The number of testcases representing the number of systems> 1

<number of points in the 1st testcase or system> 5

<x1 y1> 2 0

<x2 y2> 0 2

. 0 0

<xn yn> 1 1

Page 3: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 3/12

ISTE WeekOvernite Programming Contest

3

. 2 2

<number of points in the n th testcase or system> Sample Output 

. 2.000

<x1 y1>

<x2 y2>

.

<xm ym>

Output Format 

<Length 1 upto 3 decimal places>  

<Length2 upto 3 decimal places>

  .

<Length n upto 3 decimal places>

Page 4: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 4/12

ISTE WeekOvernite Programming Contest

4

Problem 2

 The Light Warrior battle ships used to fight on

planets are very energy efficient. During

daytime, they run on solar energy but at

night they use fusion candles, candles which

burn and release large amounts of energy to

drive the ship. Thus each candle acts as a

mini battery. Every ship takes a limited

number of candles with it before

disembarking from the mothership and going

into war. On the first night of the journey,

they will light one candle. At the end of the

night, they will extinguish the candle. On

each subsequent night, they need to light one more candle than they did

on the previous night, so that on the nth night (indexed from 1) they will

light n candles (and extinguish them all when they find the sun in the

morning). Each night that they light a candle, its height decreases by 1

cm; once its height reaches 0 cm, they cannot use it anymore. You need

to tell them the maximum number of nights a ship will last without

returning to the mothership for refuelling. You are given a int[] candles,

the ith element of which is the height of the ith candle that you own.

For example, if you have three candles of height 2, you can light one the

first night, the other two on the second night, and then all three candles

on the third night.

Input Format:

<an integer k denoting the number of testcases>

<An integer n denoting the number of candles for testcase 1>

<Height of 1st candle>

<Height of 2nd candle>

.

.

<Height of nth candle>

.

.

CL

AR

AN

LE

Page 5: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 5/12

ISTE WeekOvernite Programming Contest

5

<An integer m denoting the number of candles for testcase k>

<Height of 1st candle>

<Height of 2nd candle>

.

.

<Height of mth candle>

Output Format:

<An integer showing the maximum number of days the candles will last for test case

1>

<An integer showing the maximum number of days the candles will last for test case

2>

.

.

<An integer showing the maximum number of days the candles will last for test case

k>

Sample Input: Sample Output:1 3

3

2

2

2

Page 6: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 6/12

ISTE WeekOvernite Programming Contest

6

Problem 3

 The Light Warriors’ hacker (which is you by

the way) has just hacked into the DarkDominators’ computer base, and you want to

delete one of the operational files. But wait,

why not make the Dark Dominators delete it

themselves! As you keep watching them, you

learn that they have a delete command typed

in on their terminal which contains a 'pattern'.

 You want to rename the operational file to

match this pattern so that it gets deletedonce they issue the command. You must

accomplish this by renaming the given file to a similar name. Other than

lowercase letters, a pattern might contain '?' which represents exactly

one character (so "a?b" matches "aab", "abb", "acb" etc).

A move is defined as adding a character, deleting a character, or

modifying a character from the 'filename'. Given two Strings, 'filename'

and 'pattern', display the minimal number of moves required to make thefile match the pattern.

Input Format: Sample Input :

<the number of testcases> 1

<String1_filename for test case 1> abcd

<String2_pattern for test case 1> b??

<String1_filename for test case 2>

<String2_pattern for test case 2> Sample Output:

. 1 (First character needs to be

removed)

.

<String1_filename for test case n>

<String2_pattern for test case n>

Output Format:

<An integer giving the minimum number of moves required for test case 1>

<An integer giving the minimum number of moves required for test case 2>

.

Page 7: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 7/12

ISTE WeekOvernite Programming Contest

7

<An integer giving the minimum number of moves required for test case n>

Problem 4

Oh Oh! Looks like the Dark Dominators have

 just found out the location of the Abode of 

Light, the home system o the Light Warriors.

It’s time to pull up the defences and prepare for

battle before the darkness reaches the base.

 The Light Warriors use a highly advanced shield

system that does not allow anything to

penetrate through it. However it needs to be

set up in a rather primitive manner. It consists of two mobile generators

that need to be placed very strategically in the system, for the shield is

actually an impenetrable sphere created using the distance between the

two mobile generators as its diameter. You will be provided with a map of 

the home system (not more than 10X10) where ‘a’ represents the location

of a planet and ‘-’ shows empty space in between the planets. You need

to select two planets in the system where the generators will be placed so

that the shield generated encloses all other planets in the system. Mark

the selected planets with ‘@’ and return the map with the changes. Take

the map as a 2D character matrix.

Input Format Sample Input:Sample Output:

<An integer n telling the range of the map> 5 - - -

- @

( n represents n X n map )

- - - - a -- - - -

<1st line of the map> - - - - - -

- - - -

<2nd line of the map> - - - - - a- - - -

Page 8: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 8/12

Page 9: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 9/12

ISTE WeekOvernite Programming Contest

9

Problem 5 :

Victory seemed eminent, but the power of the ring could not be

undone.

I am certainly not talking of the ring in the Lord of TheRings. The Dark Dominators were great I should say intheir own sense. They had set up a ring of oblivion, thedeeper you go, the more you forget. Even the wirelessnetworks seemed to lose everything (As for the wired

circuits, they went out of fashion like a million years ago!). However theforces of Darkness seem to be operating in all their fervour, seeminglyimmune to this ring. Yet luck has its own strange way. A faithful informantshared a very important piece of information with the Light Warriors. The

enemy machines seem to be catching words through their iCode value, avalue based on the punctuations present in the message sent. So thatmeans, if we can remove all punctuations, the message will go through.

 The Light forces have a set of codes which must be transmitted if they areto survive in this chaos. The spaces pass luckily, but aaaargghhhh, thefull-stops, the colons, the commas don’t go through. There may be manymore that may not cross through. As far as they know for sure, onlynumbers, spaces and letters will pass. We can’t risk any more, lest theenemy might intercept and decipher. So now you’ve gotta plug in a

program to do that for the Light Warriors. Time is slipping through yourfingers, and the enemy forces are growing...(The maximum length of the input code is 500 characters)Input Format:

<The number of testcases>

<A string to represent the code for testcase 1>

< A string to represent the code for testcase 2>

.< A string to represent the code for testcase n>

Output Format:

<A string to represent the send-able code for testcase 1.>

.

<A string to represent the send-able code for testcase n>

Sample Input:

“This is important!”!!. Encoded hereby: @JTHFKE**0933 $5 FFGHB

Sample Output:

Page 10: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 10/12

ISTE WeekOvernite Programming Contest

10

This is important Encoded hereby JTHFKE0933 5 FFGHB

Problem 6It is time. The titans are set to clash.

 The end has begun. Due to your

help, the Light Warriors have

successfully vanquished the forces of 

evil from most parts of the universe.

 The Dark Dominators have now been

pinned down in the Valley of 

Darkness, their home system. It’stime to exterminate the exceedingly

evil and ever evolving forces of darkness and enrich the universe with the

essence of excellence, energising , enlightening and exalting all from the

extremities of lowness to the highest echelons of existence( the Light

Warriors have a thing for the letter ‘e’ ).

Now all that the Light Warriors need to do is to take ‘The Obliterator’

there and blow everything to smithereens. However in response to ‘The

Obliterator’ the Dark Dominators have finally built ‘The Drain’ which is a

series of mines so small that they are virtually untraceable but so

powerful that a single mine can devastate ‘The Obliterator’. Thus they

need a sweeping operation before they can move their master weapon

into position.

It’s a well known fact that the Dominators are crazy after prime numbers.

So much so that most of their childhood is spent trying to calculate the

biggest primes instead of playing ‘Hop Scotch’ or ‘Let’s kill the LightWarriors!!!’. A faithful informant has just revealed that the number of 

mines hidden in a particular sector of space is the same as the number of 

circular primes below the particular sector number. The number 197 is

called a circular prime because all rotations of the digits: 197, 971, and

719, are themselves prime. There are thirteen such primes below 100: 2,

3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. Hence sector 100 has 13

mines hidden within it.

Given a sector number, find out the number of circular primes below that

number to help the Light Warriors quickly sweep out all the mines and

Page 11: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 11/12

ISTE WeekOvernite Programming Contest

11

approach the Valley of Darkness safely, so that they can obliterate all the

remaining scum of the universe from the very shred of existence.

Input Format:

<The number of testcases>

<A positive integer to represent the sector number for testcase 1>

<A positive integer to represent the sector number for testcase 1>

.

.

<A positive integer to represent the sector number for testcase n>

Output Format:

<An integer giving the number of circular primes found below the sector number for testcase 1>

<An integer giving the number of circular primes found below the sector number for testcase

2>

.

.

<An integer giving the number of circular primes found below the sector number for testcasen>

Sample Input: Sample Output:

1 13

100

Page 12: ISTE Week Overnight Coding

8/14/2019 ISTE Week Overnight Coding

http://slidepdf.com/reader/full/iste-week-overnight-coding 12/12

ISTE WeekOvernite Programming Contest

12

-------------May the Light shine

throughout--------------