0% found this document useful (0 votes)
70 views14 pages

Problem A: Sigma Function

Here are the steps I would take to help Dablu reconstruct plant pictures from L-system strings: 1. Define an L-system grammar that can generate the types of plant structures Dablu observed. This would include rules for branching, leaves, stems, etc. and initial axiom strings. 2. Write a program that takes an L-system string as input. 3. The program interprets the string using the predefined grammar rules. It treats each character as an instruction (e.g. 'F' moves forward, '+' turns, etc.). 4. As it interprets each character, it renders the plant structure by drawing lines and shapes to the screen or to an image file.

Uploaded by

ss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views14 pages

Problem A: Sigma Function

Here are the steps I would take to help Dablu reconstruct plant pictures from L-system strings: 1. Define an L-system grammar that can generate the types of plant structures Dablu observed. This would include rules for branching, leaves, stems, etc. and initial axiom strings. 2. Write a program that takes an L-system string as input. 3. The program interprets the string using the predefined grammar rules. It treats each character as an instruction (e.g. 'F' moves forward, '+' turns, etc.). 4. As it interprets each character, it renders the plant structure by drawing lines and shapes to the screen or to an image file.

Uploaded by

ss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Problem A

Sigma Function
Input: Standard Input
Output: Standard Output

Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma
(σ). This function actually denotes the sum of all divisors of a number. For example σ(24) =
1+2+3+4+6+8+12+24=60. Sigma of small numbers is easy to find but for large numbers it is very
difficult to find in a straight forward way. But mathematicians have discovered a formula to find
sigma. If the prime power decomposition of an integer
n = p1e1 * p2e2 * p3e3 * ... * pnen−−11 * pnen , then
p1e1 +1 − 1 p2e2 +1 − 1 p3e3 +1 − 1 pnen−−11 +1 − 1 pnen +1 − 1
σ ( n) = * * * ... * *
p1 − 1 p2 − 1 p3 − 1 pn −1 − 1 pn − 1
For some n the value of σ(n) is odd and for others it is even. Given a value n, you will have to find
how many integers from 1 to n have even value of σ.

Input
The input file contains at most 100 lines of inputs.

Each line contains an integer N (0<N<1000000000001).

Input is terminated by a line containing a single zero. This line should not be processed.

Output
For each line of input produce one line of output. This line denotes how many numbers between 1
and N (inclusive) has even value of function σ.

Sample Input Output for Sample Input


3 1
10 5
1000 947
0

Problem setter: Shahriar Manzoor


Problem B
Claw Decomposition
Input: Standard Input
Output: Standard Output

A claw is defined as a pointed curved nail on the end of each toe in birds, some
reptiles, and some mammals. However, if you are a graph theory enthusiast, you may
understand the following special class of graph as shown in the following figure by
the word claw.

If you are more concerned about graph theory terminology, you may want to define
claw as K1,3.

Let’s leave the definition for the moment & come to the problem. You are given a
simple undirected graph in which every vertex has degree 3. You are to figure out
whether the graph can be decomposed into claws or not.

Just for the sake of clarity, a decomposition of a graph is a list of sub-graphs such that
each edge appears in exactly one sub-graph in the list.

Input

There will be several cases in the input file. Each case starts with the number of
vertices in the graph, V (4<=V<=300). This is followed by a list of edges. Every line
in the list has two integers, a & b, the endpoints of an edge (1<=a, b<=V). The edge
list ends with a line with a pair of 0. The end of input is denoted by a case with V=0.
This case should not be processed.

Output

For every case in the input, print YES if the graph can be decomposed into claws &
NO otherwise.

Sample Input Output for Sample Input


4 NO
12 NO
13
14
23
24
34
00
6
12
13
16
23
25
34
45
46
56
00
0

Problem setter: Mohammad Mahmudur Rahman


Special Thanks to: Manzurur Rahman Khan
Problem C
Reconstructing Binary Forests
Input: Standard Input
Output: Standard Output

Definition 1: A tree is a connected undirected graph with no simple circuits.


Definition 2: A rooted tree is a tree in which one vertex has been designated as the root
and every edge is directed away from the root.
Definition 3: In a rooted tree, if v is a vertex other than root, then the parent of v is the
unique node u, such that, there is a directed edge from u to v.
Definition 4: In a rooted tree, the children of a vertex v are the set of vertices, for which,
u is the parent.
Definition 5: Ancestor of a vertex other than root are the vertices in the path from root to
it’s vertex.
Definition 6: The descendents of a vertex v are those vertices, that have v as an ancestor.
Definition 7: A rooted tree is called full m-ary tree, if every internal vertex has exactly m
children.
Definition 8: Height of a node is the length of the path from that to the farthest
descendent leaf.
Definition 9: A forest is a graph, which is composed of one or more trees.

Given the height of each non leaf node in a forest, find the number of ways to build the
forest. All the trees are complete binary tree, and you can assume that, there are always
enough leaf nodes to complete the tree.
You have to consider two cases, when all nodes are of same color, and when all are of
different color.

Please remember, for colored case, these two trees are different. But, within a forest,
ordering of trees doesn’t matter.

Input and Output


Input contains multiple test cases. Each test case, starts with two integers N and M. N is
the number of nodes. Next line contains N integers, the height of each non leaf node.
Each input is followed by a blank line.
For each test case, output two number c and p, where c is the number of forests, when all
the node are of same color, and p is the number of forests when all the node are of
different color. Output all number modulo M.
Constraints
• 1 ≤ N ≤ 100
• 1 ≤ M ≤ 100000000
• Height of each node will be ≤ N

Sample Input Output for Sample Input


2 1000 22
21 10 20

3 1000
211

Problem setter: Manzurur Rahman Khan


Problem D
The Base-1 Number System
Input: Standard Input
Output: Standard Output

As we know, in an n-based number system, there are n different types of digits. In this
way, a 1-based number system has only 1 type of digit, the ‘0’. Here are the rules to
interpret 1-based numbers. Each number consists of some space separated blocks of 0.
A block may have 1, 2 or more 0s. There is a ‘flag’ variable associated with each
number
• A block with a single 0 sets ‘flag’ variable to 1
• A block with two 0s sets the ‘flag’ to 0
• If there are n (n > 2) 0s in a block, n – 2 binary digits with the current value of
flag is appended to your number.

Note that, the first block of every number will have at most 2 0s. For example, the 1-
base number 0 0000 00 000 0 0000 is equivalent to binary 11011.
• 1st block sets the flag to 1
• 2nd block has 4 0s. So append flag(=1) 4 – 2 = 2 times (11).
• 3rd block has 2 0s. Set the flag to 0
• 4th block has 3 0s. Append flag(=0) 3-2 = 1 time (110).
• 5th block has a single 0. Set flag = 1
• 6th and block has 4 0s. Append flag(=0) 4-2=2 times (11011).

The final binary number won’t have more than 30 digits. Once, you’ve completed the
process, convert the binary value to decimal & print, you’re done!

Input
Input will have at most 100 test cases. Each case consists of a 1-based number as
described above. A number may be spanned to multiple lines but a single block will
always be in a single line. Termination of a case will be indicated by a single ‘#’ char
which will be space-separated from the last digit of your input number. The last case
in the input is followed by a ‘~’ character indicating, end of input.

Output

For each test case, output a single line with the decimal equivalent value of your given
1-based number.

Sample Input Output for Sample Input


0 0000 00 000 0 0000 # 27
0 000 # 1
~

Problem setter: Mohammad Mahmudur Rahman


Problem E
What be thy Name, O Dear Tree?
Input: Standard Input
Output: Standard Output

Sir Jagadish Chandra Bose (জগদীশ চnd বসু , Jôgodish Chôndro Boshu) (November
30, 1858 – November 23, 1937) was a Bengali physicist and science fiction writer,
is considered the father of radio science. He made remarkable progress in his
research of remote wireless signaling as well as in plant physiology. Sir Bose
scientifically proved parallelism between animal and plant tissues using his own
invention crescograph to measure plant response to various stimuli. His
experiments showed that plants grow faster in pleasant music and its growth
retards in noise or harsh sound. [ courtesy : www.wikipedia.org ]

Our hero little Dablu (his actual name is Bablu, see “Shahnaj o Captain
Dablu” by Dr. Md. Zafar Iqbal) is conducting some experiments on plants.
As demonstrated by Sir J.C. Bose, Dablu is upto observing the influence of
music on plants growth. He plays a certain tune to a certain plant for
elongated period of time and takes snapshots of the plant in regular
intervals. Dablu does not believe in uprooting a plant completely or yanking a branch of the plant for
so called ‘speciment collection’ purpose, plants are also living beings, after all. Instead, he would take
a picture of the plant, convert this picture into a string to represent the plant according to a L-System
grammer defined by himself. The string will be stored into his PDA along with time-stamp and other
meta-data. Upon returning to his lab, he would download the snapshots (L-System strings) from his
PDA into his computer. Then he will use a program written by you to reconstruct the plant pictures
from the L-System strings. Only after that he could pay attention to his actual research work i.e.,
analyzing the pictures to figure out the influence of music on growth of plants.

You are to write a program to convert L-System strings into pictures of trees, you need to be properly
informed of the L-System. Aristid Lindenmayer (November 17, 1925 – October 30, 1989) was a
Hungarian biologist who developed a formal language called L-systems or Lindenmeyer Systems to
model plants. The L-System consists of the following components.

V : an alphabet of symbols.
S : a non-empty starting word (or seed)
P : a set of productions rules of the form a -> A , where a ε V and A is a string consisting of
symbols from V only.

For the job at hand, Dablu has supported us with the following alphabet of the L-System he is using.

V = { U , L , l , R , r , f , P , p , [ , ]}

Since it is not our job to convert the plants into L-System strings, we are not really bothered about the
seed or the production rules he uses to encode a plant into L-System string. We are concerned with
interprating each of the symbols in his alphabet on the picture. According to Dablu, the procedure of
drawing a plant from its L-System string should be considered similar to drawing a plant with a pencil
on a paper. We start by putting the tip of the pencil on paper. Then draw line sements in various
directions representing stems of the plant in various spatial orientations. Each of the symbols in V has
a corresponding direction of line segment or any other artifact to be drawn on the paper, which is
given in the following table. Note that the pencil keeps moving according to the drawing. Dablu has
also told us that all the given strings will start with either ‘U’ or ‘[’.
Symbol Drawn Interpretation
as
Upward stroke of pencil, drawing an upright stem/trank of the plant.
U |
A horizontal leftward stroke, drawing a horizontal- stem.
L _
Left inclined stroke, drawing a leftward inclined stem.
l \
A horizontal rightward stroke, drawing a horizontal- stem.
R _
Right inclined stroke, drawing a rightward inclined stem.
r /
A flower.
f *
A growing fruit.
p o
A fully grown fruit.
P O
Indicates the starting of a branch. Whatever is found after a ‘[’ symbol is on this
[ branch of the plant. Note that there a branch itself can have one or more sub-branches
as well.
Indicates the end of a branch. When this symbol is found, the pencil is brought back to
]
the position from where this branch had started.

Input

There will be several lines of input. An L-System string on each line, terminating with a ‘\n’,
containing up to 500 symbols from V and only from V. Input file terminates with EOF. You can
assume that all given strings will be valid and will draw a plant if converted correctly.

Output

For each L-System string your output should be the picture of a correctly drawn plant enclosed in a
rectangular frame similar to the ones shown in sample output. Note that the corners of the character at
the corners of the rectangles are ‘.’(period). There should be no extra white space up/down/right/left
of the plant inside the frame. If you need to overwrite any character while drawing, just go do it.

Sample Input Output for Sample Input


U[lf][rf]UU[lf][rf]UUP .-----.
U[L][R[Up]RR[Uf]RR]U | O |
U[llf][rrf]UU[lf][rf]UUP |* | *|
[U]l[UlU][LUrr[Uf]rr] | \|/ |
[U]l[LUrr[Uf]rr]UlU |* | *|
U[rrRlUUU[r]l]ll[LpPf]U[UUUP][RUlLo]L | \|/ |
| | |
.-----.
.-----------.
| o * |
|_|_|_ _|_ _|
| | |
.-----------.
.---------.
| O |
| * | * |
|* \|/ *|
| \ | / |
| \|/ |
| | |
.---------.
.--------.
| * /|
| |/ |
|| / |
| / |
||_| |
| \| |
.--------.
.--------.
| * /|
| |/ |
|| / |
| \ |
||_| |
| \| |
.--------.
.------------.
| O \ /|
| _| | |
| |\ | |
| _|_| | |
|*_| \|
| \ / |
| \ / |
| | |
.------------.

Problemsetter: K. Raiyan Kamal


Problem F
Lighting System Design
Input: Standard Input
Output: Standard Output

You are given the task to design a lighting system for a huge conference hall. After
doing a lot of calculation & sketching, you have figured out the requirements for an
energy-efficient design that can properly illuminate the entire hall. According to your
design, you need lamps of n different power ratings. For some strange current
regulation method, all the lamps need to be fed with the same amount of current. So,
each category of lamp has a corresponding voltage rating. Now, you know the number
of lamps & cost of every single unit of lamp for each category. But the problem is,
you are to buy equivalent voltage sources for all the lamp categories. You can buy a
single voltage source for each category (Each source is capable of supplying to
infinite number of lamps of its voltage rating.) & complete the design. But the
accounts section of your company soon figures out that they might be able to reduce
the total system cost by eliminating some of the voltage sources & replacing the
lamps of that category with higher rating lamps. Certainly you can never replace a
lamp by a lower rating lamp as some portion of the hall might not be illuminated then.
You are more concerned about money-saving than energy-saving. Find the minimum
possible cost to design the system.

Input

Each case in the input begins with n (1<=n<=1000), denoting the number of
categories. Each of the following n lines describes a category. A category is described
by 4 integers - V (1<=V<=132000), the voltage rating, K (1<=K<=1000), the cost of a
voltage source of this rating, C (1<=C<=10), the cost of a lamp of this rating & L
(1<=L<=100), the number of lamps required in this category. The input terminates
with a test case where n = 0. This case should not be processed.

Output

For each test case, print the minimum possible cost to design the system.

Sample Input Output for Sample Input


3 778
100 500 10 20
120 600 8 16
220 400 7 18
0

Problemsetter: Mohammad Mahmudur Rahman


Special Thanks to: Manzurur Rahman Khan
Problem G
Triangle Counting
Input: Standard Input
Output: Standard Output

You are given n rods of length 1, 2…, n. You have to pick any 3 of them & build a
triangle. How many distinct triangles can you make? Note that, two triangles will be
considered different if they have at least 1 pair of arms with different length.

Input

The input for each case will have only a single positive integer n (3<=n<=1000000).
The end of input will be indicated by a case with n<3. This case should not be
processed.

Output

For each test case, print the number of distinct triangles you can make.

Sample Input Output for Sample Input


5 3
8 22
0

Problem setter: Mohammad Mahmudur Rahman


Problem H
Ahoy, Pirates!
Input: Standard Input
Output: Standard Output

In the ancient pirate ages, the Pirate Land was divided into two teams of pirates,
namely, the Buccaneer and the Barbary pirates. Each pirate’s team was not fixed,
sometimes the opponent pirates attacked and he was taken away to the other pirate
team. All on a sudden a magician appeared in the Pirate Land, where he was making
transition of pirates from their team to other team at his own will. Of course, handy
spells were used. The process of changing team was known as mutating.

There were N pirates and all of the pirates have a unique id from 0 to N-1. The great
magician could mutate a bunch of pirates with consecutive id’s to another one.

Suppose there were 100 pirates in the pirate land and all of them were Barbary pirates,
then the magician could cast a spell to change pirates with id’s from 10 to 33 to
Buccaneer pirates. Then the whole pirate land would have 24 Buccaneer and 76
Barbary pirates.

The magician was very fast casting the spell. Once, God started to dislike this. God
had favor for the Buccaneer pirates and God asked the magician, “Tell me, how many
of the pirates of index from 2 to 30 are Buccaneer pirates?”. Now the magician was
puzzled as he was only efficient in spells, not counting ☺

Being clever enough, the magician captured a clever man from the Earth Land. And
unfortunately it’s you! Now you have to answer the God’s questions.

Input

The first line of input will contain number of test cases T.


For each test case:
The first part of the description will be of the pirate land. There could be up to N
(1<=N<=1024000) pirates. Each pirate is either assigned to Buccaneer or Barbary
Pirate. Buccaneer pirates are described by ‘1’ (ONE) and Barbary pirates are
described by ‘0’ (ZERO). You have to build a string of the pirates description. Each
case starts with an integer M (M<=100), where M pair lines follow. In each pair of
lines (we call it a set), first has an integer T (T <= 200) and next one has a nonempty
string Pirates (consisting of 0 and 1, 0 for Barbary, 1 for Buccaneer, has maximum
length of 50). For each pair concatenate the string Pirates, T times. Concatenate all
the resulting M sets of strings to build the pirate description. The final concatenated
string describes the pirates from index 0 to end (N-1 for N pirates).
Now the next part of the input will contain queries. First line of next part has an
integer Q describing number of queries. Each subsequence Q (1<=Q<=1000) lines
describe each query. Each query has a string F or E or I or S and two integers, a and b
denoting indexes. The meaning of the query string are follows:
F a b, means, mutate the pirates from index a to b to Buccaneer Pirates.
E a b, means, mutate the pirates from index a to b to Barbary Pirates.
I a b, means, mutate the pirates from index a to b to inverse pirates.
S a b, means, “God’s query” God is asking a question: “Tell me, how many
Buccaneer pirates are there from index a to b?”
(a <= b, 0 <= a < n, 0 <= b < n, index range are inclusive)

Output
For each test print the case number as the sample output suggests. Then for each of
“God’s query”, output the query number, colon(:) and a space and the answer to the
query as the sample suggest.

Sample Input Output for Sample Input


2 Case 1:
2 Q1: 5
5 Q2: 1
10 Case 2:
2 Q1: 0
1000
5
F 0 17
I 0 5
S 1 10
E 4 9
S 2 10
3
3
1
4
0
2
0
2
I 0 2
S 0 8

Explanation:
Case1:
The pirate land is as follows (N = 18)
101010101010001000
Before God’s first query it was as follows
000000111111111111

Case 2:
The pirate land is as follows (N=9)
111000000

Problem setter: Istiaque Ahmed


Problem: I
Binary Multiplication
Time Limit: 2 sec

All of us know simple multiplication rule. Can we


make a program to multiply two binary numbers?
Well we can try.

Input specification:
Each case will define two binary strings (x & y). You can assume that length of each
string will not exceed 30. The program will terminate with a 0 0.

Out put specification:


Out put must be formatted like the following examples. You have to show the step by
step procedure for the multiplication. Each result will be separated by an empty line.
Sample Input: Output for Sample Input:
11 11 11
111 10 11
10 111 --
0 0 11
11
----
1001

111
10
---
000
111
----
1110

10
111
---
10
10
10
----
1110

------------------------------------------------
Problem setter: M. Mizanur Rahman

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy