Вы находитесь на странице: 1из 13

BDOI2007 | BIOC | BRACU | BUCC

BDOI2007
Bangladesh Olympiad in Informatics
Arranged by BRAC University BRAC University Computer Club Bangladesh Informatics Olympiad Committee

Page 1 of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM A. 40TH PRIME


ind the !"th prime number# A prime is a number that has e$actly t%o distinct divisors#

PROBLEM B. CROSS + ROADS = DANGER


&olve the follo%ing %here different letter represents different digits# 'rite the actual figures in the format given belo%#

CROSS +ROADS DANGER

PROBLEM C. EXPONENTIAL 00!


ind $ up to 3 digits after the decimal point %here(

ex + e x + e"x = 00!
PROBLEM D. MA#E MADNESS
Oops) *ou are stuc+ in a ma,e) *ou have to get free from the ma,e in minimum number of steps# In one step you can move up( do%n( right or left# *our starting position is denoted by -&.# A bloc+ed cell /a cell %here you can not step into0 is represented by a -1. and -#. represents a free cell# -2. represents your destination# #################################################### #S..............#........###.......................# #..####..####...###..###########.####.####.####....# #..#...#.#...#.#...#...#.......#.#..#.#..#....#....# #..#..#..#...#.#...#...#....####.#..#.#..#....#....# #..#...#.#...#.#...#...#....#....#..#.#..#....#....# #..####..####...###..#####..####.####.####....###### #....#.###....##.................#.......#.........# #....#.....#.....#..##############.####..########### #.###...#..#.#######........#...........#.####.....# #...#.###..#........####..##...#........#......#.#.# #.#....#.#..#.###.....##.....############..#######.# #...#..#............#.....#....................#..D# ####################################################

Page 3 of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM E. RIGHT ANGLED TRIANGLE


*ou are given 4$( y5 co6ordinates of three distinct points of a triangle# 7erify %hether it is a right angled triangle or not#

INPUT:
8here %ill be only one line in the input containing 9 integer values $1( y1( $3( y3( $3( y3# Absolute value of each integer %ill be %ithin 1""#

OUTPUT:
Output should contain only one line( :*es; if it is a right angled triangle( :<o; other%ise# /'ithout the =uotes0

SAMPLE INPUT 1:
0 0 0 1 1 0

OUTPUT FOR SAMPLE INPUT 1:


Yes

SAMPLE INPUT 2: SAMPLE INPUT 3:


1 1 2 2 3 2

10 10 20 20 30 10

OUTPUT FOR SAMPLE INPUT 2:


Yes

OUTPUT FOR SAMPLE INPUT 3:


No

REMARK:
8ry to solve this problem using integer calculation#

Page 3 of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM $.
INPUT:

CO%NT THE N%MBERS

*ou are given < integers# *ou have to find out ho% many of them are positive( negative or ,ero# Input %ill consist of 3 lines# irst line %ill consist of the integer < /" > < > 1"10# In the ne$t line( there %ill be < integers in the range /61""( 1""0#

OUTPUT:
Output should contain 3 integers in a line separated by a single %hite space# 1st integer is the count of positive numbers( 3nd integer is the count of negative numbers and 3rd integer is the count of ,eros#

SAMPLE INPUT 1:
3 0 1 1

OUTPUT FOR SAMPLE INPUT 1:


2 0 1

SAMPLE INPUT 2:

10 1 2 3 4 5 6 7 8 9 10

OUTPUT FOR SAMPLE INPUT 2:


10 0 0

SAMPLE INPUT 3:
5 -1 0 -1 -5 0

OUTPUT FOR SAMPLE INPUT 3:


0 3 2

Page ! of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM G. THE AD&ENT%RE O$ S%PER G%L%


Criminals) Be Afraid) Be 7ery Afraid)) 8he crime has a ne% face of error# It.s the ne%est addition in the fight for ?ustice@ it.s our o%n super heroine( &uper Aulu# 'ith her charming appearance( great strength( and ama,ing ability to holding the stuffs together( she %ill ma+e the %orld a better place# In her =uest for ?ustice and peace( her s%orn enemy( the evilest evily devil( 2is+y 2ude( %ill destroy everything around# But( he can.t be any match for the &uper Aulu( and after a series of une$pected events( dis+y %as defeated# But( before that( he has destroyed something really precious# 8he city had a crystal pyramid# 8he pyramid had a number of layers# Bach layer is unit high( and had e=ual %idth and length 4a s=uare( seen from the top5# 8he ground layer.s dimension %as 2( and each subse=uent layer.s dimension is 3 less than the dimension of the layer beneath# &o( if the bottom layer.s dimension %as C( then the height of the pyramid %ill be 3( and the si,es of the layers %ill be 1( 3( C 4from top to bottom5# 8he city had one really big pyramid# But dis+y had destroyed that into pieces# Bach piece is an unit cube# <o%( it.s Aulu.s ?ob to rebuild the %hole pyramid# In order to do so( he found some really big problems# A number of pieces %ere missing# or e$ample( the pyramid %ith base of C $ C should have 3C unit pieces( but instead of 3C pieces( he found 3"# &o( she decided to ma+e a smaller pyramid# <o%( %hat is the largest pyramid she can createD or e$ample( if she is given %ith 3" pieces( she %ill be able to build a pyramid of height 3( %hose layers %ill of of si,e 3( ! 4from top to bottom5#

INPUT:
Input %ill contain only one integer( <( the number of pieces &uper Aulu has#

OUTPUT:
Output only the ma$imum dimension of the bottom layer#

SAMPLE INPUT 1:
34

OUTPUT FOR SAMPLE INPUT 1:


4

SAMPLE INPUT 2:
57

OUTPUT FOR SAMPLE INPUT 2:


6

REMARKS:
1 E < E 1("""("""("""

Page C of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM H. RABBIT EXPLOSION


It is 13th ebruary( an unluc+y day for &ultana) Fer discrete math teacher has sho%n a problem to the class# But she can.t find the solution can you help herD Oh %ait) I forgot to give you the problem description) *ou +no% I forget very easily) Any%ay( the creator has created one pair of rabbit initially# A pair of rabbit ta+es one month to get matured# 8hen they %ill give birth to a ne% rabbit pair in each month# And all the ne% born rabbit pairs %ill continue this phenomenon# &o that means %e had ?ust 1 pair in the first month# In the second month %e have that old pair only# In the third month %e have 3 pairs( the old pair and the ne% pair given birth by the old pair# In the third month %e have 3 pairs totally( 3 old pairs and one more pair given birth by the first pair# And so on### 'hat you have to say is the number of rabbit pairs in the nth month modulo 1""""# <ote that G modulo * means the remainder of G %hen it is divided by *#

INPUT:
8here %ill be only one line in the input# Inde$ of the month( n 4 " > n > 1"""""""""5#

OUTPUT:
Output should contain only one line( number of rabbit pairs in the nth month by modulo 1""""#

SAMPLE INPUT 1:
1

OUTPUT FOR SAMPLE INPUT 1:


1

SAMPLE INPUT 2:
10

OUTPUT FOR SAMPLE INPUT 2:


55

SAMPLE INPUT 3:
28

OUTPUT FOR SAMPLE INPUT 3:


7811

REMARKS:
In 3"H test casesI " > n > !9# In J"H test casesI " > n > 1""""""#

Page 9 of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM I.

SA&E THE DIAMOND

In an e$hibition a diamond is +ept in high security# And you +no% KA&BR light is usually used in such security system# In our problem %e %ill consider that all the lights are at same plane parallel to hori,on so that %e can represent the lights as straight line in a 32 plane# *ou have to tell me the number of points through %hich more than one light passes# 8he figure on the right represents sample 3#

INPUT:
In the first line( there %ill be given a positive integer < 4number of KA&BR lights5 /" > < > 1"""0# In each of the follo%ing < lines( there %ill be 3 integers a i( bi and ci %hich represent a KA&BR light on a 32 plane# 4ai$ L biy M ci5

OUTPUT:
Output should contain only one line( number of intersection points of the KA&BR lights#

SAMPLE INPUT 1:
1 1 0 0

OUTPUT FOR SAMPLE INPUT 1:


0

SAMPLE INPUT 2:
2 1 0 0 0 1 0

OUTPUT FOR SAMPLE INPUT 2:


1

SAMPLE INPUT 3:
6 -1 1 0 -1 1 -4 0 1 -2 1 1 0 1 0 -2 1 0 2

OUTPUT FOR SAMPLE INPUT 3:


6

REMARKS:
In 3"H test casesI " > < > C"# In J"H test casesI " > < > 1""#

Page J of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM '.

HO( MAN) CO%NTRIES*

*ou are given a map# In the map( -1. denotes land and - .. denotes %ater# 8%o islands belong to same country if the minimum distance bet%een them is not more than one unit# 8he distance is defined by the shortest path through %ater bet%een them# 8ell me ho% many countries are there in the map) In the Nap 1 and Nap 3( the t%o islands are neighboring as you can see that the minimum distance bet%een them is 1 unit %hich is sho%n by the bold line# But in the Nap 3( there is no such path# Nap 1 Nap 3 Nap 3

INPUT:
In the first line( there %ill be given R and C representing the ro%s and columns of the map respectively# / " > R( C > 1"""0 In the follo%ing R lines( there %ill be C characters each of %hich is either -1. or - ..#

OUTPUT:
Output should contain only one line( number of countries in the map#

SAMPLE INPUT 1:
3 3 ### ... #.#

OUTPUT FOR SAMPLE INPUT 1:


1

SAMPLE INPUT 2:
5 5 #..## ...## #.... ....# ..#..

OUTPUT FOR SAMPLE INPUT 2:


2

REMARKS:
In C"H test casesI " > R( C > 1""#

Page O of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM +. $IND THE (ORDS


G is at the last stage of his military training# Fe has to give his shooting test no%# But he is a bit %orried# Because the test not only depends on one.s shooting s+ill but also to luc+# In the tas+( G %ill be given boards of characters hanging in front of him# 'hat he has to do is to +noc+ some characters by firing them so that the remaining characters ma+e a %ord %hich is supplied by the instructor# If he succeeds to do so then he is passed# G has someho% managed the list of the %ords one of %hich is going to be supplied to him# Can you determine the probability of his passing assuming that he %ill be 1""H accurate in his shootingD

INPUT:
In the first line( the characters 4that are hanging in front of G5 are given /%ithout space0# In the second line( P number of %ords in the list of the instructor is given# /P > 1"""0 In the follo%ing P lines( there %ill be given a %ord /%ithout space0# 8he initial board configuration and the %ords all %ill have at most 1""" length#

OUTPUT:
Output should contain only one line( probability of success of G in aQb form( %here a and b are co6prime /i#e# AC2 M 10# 4*ou may assume that the probability %ill never be ,ero#5

SAMPLE INPUT 1:
ItIs4:22AM 5 II st am It I4

OUTPUT FOR SAMPLE INPUT 1:


3/5

SAMPLE INPUT 2:

2007IOIisgoingto e!e"#in$%oatia 4 007 ang"a#es! $%oatia me&i$o

OUTPUT FOR SAMPLE INPUT 2:


1/2

Page R of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM L.

ENCODE,EDOCNE

:8oday I am going to give you an assignment;( said teacher# :<o sir( no) 'e have 3 class tests in this %ee+); :<o) *ou have to do it by tomorro%); :<o sir( please###############; :*ou %ill be given a string# 8hen %rite do%n the string( you get by rotating the given string one unit on right( ?ust belo% the first string# And then %rite do%n another one rotating initial string t%o units to right# And so on# 8his process %ill continue K61 times %here K is the length of the given string# *ou have to output the right6most column of the grid you get#; or e$ample( if the given string isI BRAC then after rotating one unit to right it %ill become CBRA( and one more( ACBR and one more( RACB# 8hus the resulting grid %ill loo+ li+eI BRAC CBRA ACBR RACB And thus the right6most column isI :CARB;

INPUT:
In the first line( there %ill be a string %ithout space# Kength of the string %ill be at most 1""""""#

OUTPUT:
Output should contain only one line( the last column of the grid you got by follo%ing the above %ay#

SAMPLE INPUT 1:
'(A)

OUTPUT FOR SAMPLE INPUT 1:


)A('

SAMPLE INPUT 2:
AAAAA

OUTPUT FOR SAMPLE INPUT 2:


AAAAA

SAMPLE INPUT 3:
)A*

OUTPUT FOR SAMPLE INPUT 3:


*A)

REMARKS:
In C"H test cases( Kength of the string %ill be at most 1"""#

Page 1" of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM M. INSTR%CT THE ROBOT


*ou have to %rite a program to instruct a robot hand to call a specific phone number# 8here are t%o commandsI PI Press the +ey of your location# N4$(y5I Nove $ unit along G a$is and y along * a$is# /<oteI there is no %hite space0 Initially the robot hand %ill be on C# *ou %ill be given a phone number# Instruct the robot hand to call that specific number using minimum number of commands# or e$ample( if the robot is as+ed to call COR1 then the commands %ill beI + M,0--1. + M,1-0. + M,-2-2. + 1 ! J 3 C O " 3 9 R

INPUT:
In the first line( there %ill be given the phone number < /< > 1"""""""""0#

OUTPUT:
Output should the command lines#

SAMPLE INPUT 1:
5891

OUTPUT FOR SAMPLE INPUT 1:


+ M,0--1. + M,1-0. + M,-2-2. +

SAMPLE INPUT 2:
40

OUTPUT FOR SAMPLE INPUT 2:


M,-1-0. + M,1--2. +

Page 11 of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM N. M%SICAL THEMES


A musical melody is represented as a se=uence of < 4" > < > C""15 notes that are integers in the range /1( OO0( each representing a +ey on the piano# It is unfortunate but true that this representation of melodies ignores the notion of musical timing@ but( this programming tas+ is about notes and not timings# Nany composers structure their music around a repeating SthemeS( %hich( being a subse=uence of an entire melody( is a se=uence of integers in our representation# A subse=uence of a melody is a theme if itI is at least five notes long appears 4potentially transposed 66 see belo%5 again some%here else in the piece of music is dis?oint from 4i#e#( non6overlapping %ith5 at least one of its other appearance4s5 8ransposed means a constant positive or negative value is added to every note value in the theme subse=uence# Aiven a melody( compute the length 4number of notes5 of the longest theme#

INPUT:
8he first line of the input contains the integer <# 8hen there follo%s < integers representing the se=uence of notes#

OUTPUT:
8he output should contain a single line %ith a single integer that represents the length of the longest theme# If there are no themes( output "#

SAMPLE INPUT 1:

30 25 27 30 34 39 45 52 60 69 79 69 60 52 45 39 34 30 26 22 18
82 78 74 70 66 67 64 60 65 80

OUTPUT FOR SAMPLE INPUT 1:


5

Page 13 of 13

BDOI2007 | BIOC | BRACU | BUCC

PROBLEM O. STANDING IN THE -%E%E


ebruary is the month of glory( is the month of pride for all the Bangladeshis# Nost of the boo+ lovers. mar+ this month for the age old :B+ushey Boi Nela; held at Bangla Academy( in the memoriam of the Kanguage Novement in 1RC3# *ou can al%ays see happy faces( %andering through the cro%ds in the Boi Nela# But( in the recent years( the cro%d has turned so bigger that( you can see that from %ay outside of the premises# *ou can see almost a mile long =ueue outside the fair( %aiting to get inside# &uppose( you +no% all the persons. arrival time( described as the minutes elapsed from the beginning of the fair# If you are the +th person among them( %hat is the latest and the earliest time( that you can enter the premisesD Please note that( each minute( e$actly one person can enter the fair# If more than one person arrive at the same time( they can stand in any order# or e$ample( if C person come at times( 61( 3(1( 3( 3 then they may enter in either orderI >1( 3( 3( !( CT or >1( 3( 3( C( !T &o( the earliest time for the !th person %ill be time 3( and latest %ill be time !# If anyone.s arrival time is negative( that means( he came before the fair started# Fe %on.t be able to go inside( until the fair opens#

INPUT:
irst line contains t%o integers( n( the total number of persons and +( your position# <e$t n lines contain one integer each( their arrival time#

OUTPUT:
Output t%o integersI earliest time and latest time separated by a space#

SAMPLE INPUT 1:
5 3 -1 2 1 3 3

OUTPUT FOR SAMPLE INPUT 1:


3 4

REMARKS:
n E 1""(""" 1EnE+ 61""("""(""" E arrival time E 1""("""("""

Page 13 of 13

Вам также может понравиться