task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
The Easiest Problem (PT07B) You are given an unweighted, undirected tree T . We say T is special iff it has this property: "All nodes of degree greater than or equal to 3 are surrounded by at most two nodes of degree two or greater." Finding maximal size subtree of this tree so that it's a special tree. In...
31,100
The GbAaY Kingdom (PT07C) Jiajia is the king of the GbAaY Kingdom. He always squeezes his 20 ministers as coolies. There are n cities and m two-way roads connecting cities in the kingdom. Because of the increasing cost of fuel, he wants to simplify the road system in the GbAaY Kingdom. Thus, so...
31,101
Let us count 1 2 3 (PT07D) Given two integer n , p . 4 kinds of query is needed to solve: Counting the number of labeled unrooted trees with n nodes. Counting the number of labeled rooted trees with n nodes. Counting the number of unlabeled rooted trees with n nodes. Counting the number of unlabeled ...
31,102
A short vacation in Disneyland (PT07F) After a lot of exams at school, Amber and his friends Ahyangyi, Dragon have a short vacation in Hong Kong Disneyland. Many interesting places they want to visit there: resort, castle,... . In each place and between them, there are special bidirectional rails, so that the visitors...
31,103
Colorful Lights Party (PT07G) ACRush and his friends want to open a party to celebrate the good result of THU in ICPC 2007. They will use all halls in THU for their party. There are 2 kinds of hall: the small and the large one. In each hall, there is an electronic light system, which forms a tree topology to reduce re...
31,104
Search in XML (PT07H) The XML (eXtensible Markup Language) is gaining popularity as a new standard for data representation and exchange on the internet. XML provides a text-based means to describe and apply a tree-based structure to information. The XML document consists of nested elements, some of which usually ...
31,105
Query on a tree III (PT07J) You are given a node-labeled rooted tree with n nodes. Define the query ( x , k ): Find the node whose label is k -th largest in the subtree of the node x . Assume no two nodes have the same labels. Input The first line contains one integer n (1 ≤ n ≤ 10 5 ). The ne...
31,106
Whac-a-Mole (MOLE) While visiting a traveling fun fair you suddenly have an urge to break the high score in the Whac-a-Mole game. The goal of the Whac-a-Mole game is to... well... whack moles. With a hammer. To make the job easier you have first consulted the fortune teller and now you know the exact appearance ...
31,107
Ranklist Sorting (RSORTING) You are given the scores of several players in a competition. Your task is to create a ranklist of the players, sorted in decreasing order by score. Unfortunately, the data structure used for the list of players supports only one operation, which moves a player from position i to posi...
31,108
Help Blue Mary Please! (Act III) (BLUEEQ3) Background This morning Blue Mary wrote some equations on a piece of paper and left it on her desk. After solving some problems in SPOJ, she found that her classmate H.L. replaced all characters on the paper with some other ones. H.L. told her he replaced the same character...
31,109
Making Jumps (MKJUMPS) A knight is a piece used in the game of chess. The chessboard itself is square array of cells. Each time a knight moves, its resulting position is two rows and one column, or two columns and one row away from its starting position. Thus a knight starting on row r, column c – which we’ll deno...
31,110
Mobiles (MOBILE2) You have been asked to buy a gift for your baby brother, Ike. However, you have noticed that Ike has a very particular taste in gifts. He only likes gifts that are configured in his particular style. You have found a shop that sells mobiles. A mobile is a multi-layered decoration that is typic...
31,111
Backup Files (BACKUP) You run an IT company that backs up computer data for large offices. Backing up data is not fun, and so you design your system so that the different offices can back up each others' data while you sit at home and play computer games instead. The offices are all situated along a single street. Y...
31,112
Zoo (ZOO) The pride of the Asia-Pacific region is the newly constructed Great Circular Zoo. Situated on a small Pacific island, it consists of a large circle of different enclosures, each containing its own exotic animal as illustrated below. You are in charge of public relations for the zoo, which means it is y...
31,113
Can you answer these queries II (GSS2) Being a completist and a simplest, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at all. So he always fails in contests. When having a contest, Yang Zhe looks at the score of every prob...
31,114
Trees (TREEOI14) Byteasar has a cottage. Lately, he has bought n trees and had them planted all in one row. Byteasar does not, however, like the order which the trees have been planted in. It particularly annoys him that tall and short ones have been mixed up, and the composition does not meet his aesthetic criteria...
31,115
Another Mathematical Problem (AMATH) Given two numbers n (1 ≤ n < 10 100 ) and k (1 ≤ k ≤ 100), you are to determine whether there exists a positive integer T which satisfies that for every positive integer a, n a+T -n a is divisible by 10 k . Input Multiple test cases. Each test case contains two space-separated...
31,116
The Great Indian Wedding (GIWED) A wedding is to be organized in a rectangular park of dimensions M by N . Some parts of the park are covered by K rectangular carpets. These carpets, produced by ItSucks Corporation are revolutionary self cleaning carpets - they suck any liquid they come in contact with! The...
31,117
Ambitious Manager (AMBM) The Bogus Corporation distributes salary to its employees in a weird manner. The salary is distributed every K days, and instead of same salary for each day, the salary for the i th day is a i . An ambitious young manager, fresh from Institute of Mismanagement , observes that people us...
31,118
The Explosion (EXPLOSN) The day of 6.XII.2003 in Megabyteland began calm and quietly as any other day. Some people went to work, some - to school, some - to store to buy food. Drivers were traditionally stuck in traffic jams, drinking coffee and reading morning newspaper. Suddenly the regularity of this day was distur...
31,119
Fusion Cube (FUSION) The Bogus Corporation claims to have solved the energy crisis by devising a method to perform controlled fusion reaction! The set up consists of a cube of side length N meters, which contain K point sources of electrons. Each of the sources can be configured to emanate an electron along any of the...
31,120
Text Generator (GEN) LoadingTime has been given a task these days. He is required to write a tool called Text Generator. This software is widely used among the kids who are under seven. It generates an article with the size of a given number L for users. If an article contains at least one word which the users know, w...
31,121
Halloween treats (HALLOW) Every year there is the same problem at Halloween: Each neighbor is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a child will get nothing if it is too late. To avoid conflicts, the children have decided they ...
31,122
Royal Treasury (TREASURY) Once upon a time in a kingdom far far away, the royal treasury started getting emptier and emptier. The king decided to change the situation and he invented a new system of cooperation with in the office of the royal treasurer. The clerks of the office are supposed to form pairs (in order to ...
31,123
Cylinder (CYLINDER) Using a sheet of paper and scissors, you can cut out two faces to form a cylinder in the following way: Cut the paper horizontally (parallel to the shorter side) to get two rectangular parts. From the first part, cut out a circle of maximum radius. The circle will form the bottom of the c...
31,124
Expressions (EXPRESS) Arithmetic expressions are usually written with the operators in between the two operands (which is called infix notation). For example, (x+y)*(z-w) is an arithmetic expression in infix notation. However, it is easier to write a program to evaluate an expression if the expression is writte...
31,125
Frequent values (FREQUENT) You are given a sequence of n integers a 1 , a 2 ... a n in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j ( 1 ≤ i ≤ j ≤ n ). For each query, determine the most frequent value among the integers a i ... a j . Input...
31,126
Grocery store (GROCERY) A cashier in a grocery store seems to have difficulty in distinguishing the multiplication symbol and the addition symbol. To make things easier for him, you want to buy goods in such a way that the product of their prices is the same as the sum of their prices. Of course, if you buy on...
31,127
Logic II (LOGIC2) Some day in 2003 in Byteland began calm and quietly as any other day. Some people went to work, some to school, some to store to buy food. Drivers were traditionally stucked in traffic jams, drinking coffee and reading morning newspaper. Suddenly the regularity of this day was disturbed by huge explo...
31,128
A Very Easy Problem! (EASYPROB) Input There's no input. Output Output some form of these numbers: 137, 1315, 73, 136, 255, 1384, 16385, one per line in the listed order. Example The first two lines of the CORRECT output file are: 137=2(2(2)+2+2(0))+2(2+2(0))+2(0) 1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+...
31,129
Hard Problem (HARDP) [This space is intentionally left blank.] Input Multiple test cases. Each contains a single integer N (1 ≤ N ≤ 50). Input terminates by EOF. Output For each test case, output one line contains the answer. See the example. Example Input: 8 9 10 Output: 8=90*(0+0+0+0+45-3+20-42+...
31,130
Coconuts (COCONUTS) A group of n castle guards are voting to determine whether African swallows can carry coconuts. While each guard has his own personal opinion on the matter, a guard will often vote contrary to his beliefs in order to avoid disagreeing with the votes of his friends. You are given a list of gu...
31,131
Grandpa’s Rubik Cube (GRC) Documento sin título A very well-known toy/pastime, called Rubik's cube, consists of a cube as shown in Figure 1a, where letters stand for colors (e.g. B for blue, R for red,...). The goal of the game is to rotate the faces of the cube in such a way that at the end each face has ...
31,132
Will Indiana Jones Get There (WIJGT) Indiana Jones is in a deserted city, annihilated during a war. Roofs of all houses have been destroyed and only portions of walls are still standing. The ground is so full of mines that the only safe way to move around the city is walking over the remaining walls. The mission of ou...
31,133
Ohgas' Fortune (OFORTUNE) The Ohgas are a prestigious family based on Hachioji. The head of the family, Mr. Nemochi Ohga, a famous wealthy man, wishes to increase his fortune by depositing his money to an operation company. You are asked to help Mr. Ohga maximize his profit by operating the given money during a specif...
31,134
Polygonal Line Search (PLSEARCH) Multiple polygonal lines are given on the xy-plane. Given a list of polygonal lines and a template, you must find out polygonal lines which have the same shape as the template. A polygonal line consists of several line segments parallel to x-axis or y-axis. It is defined by a list ...
31,135
Numeral System (NSYSTEM) Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system. The letters "m", "c", "x" and "i" correspond to 1000, 10...
31,136
Traveling by Stagecoach (TRSTAGE) Once upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in this problem is to write a program which determines the route for him. There are several citie...
31,137
Earth Observation with a Mobile Robot Team (EOWAMRT) A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication de...
31,138
Cleaning Robot (CLEANRBT) Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture. Consider the room floor paved with square tiles whose size fits the cleaning robot (1 × 1). There are 'clean tiles' and 'dirty tiles', and the robot can change a 'dirty tile' to a 'clea...
31,139
ACM (ACronymMaker) (ACMAKER) The sadists who design problems for ACM programming contests often like to include the abbre- viation “ACM” somewhere in their problem descriptions. Thus, in years past, the World Finals has had problems involving “Apartment Construction Management,” the “Atheneum of Culture and Movies,...
31,140
Countdown (CDOWN) Ann Sister owns a genealogical database service, which maintains family tree history for her clients. When clients login to the system, they are presented with a variety of services: searching, printing, querying, etc. One recent question that came up which the system was not quite prepared for was...
31,141
The Game of Efil (GAMEFIL) Almost anyone who has ever taken a class in computer science is familiar with the “Game of Life,” John Conway’s cellular automata with extremely simple rules of birth, survival, and death that can give rise to astonishing complexity. The game is played on a rectangular field of cells, ea...
31,142
Queens, Knights and Pawns (QKP) You all are familiar with the famous 8-queens problem which asks you to place 8 queens on a chess board so no two attack each other. In this problem, you will be given locations of queens and knights and pawns and asked to find how many of the unoccupied squares on the board are not u...
31,143
Reliable Nets (RELINETS) You’re in charge of designing a campus network between buildings and are very worried about its reliability and its cost. So, you’ve decided to build some redundancy into your network while keeping it as inexpensive as possible. Specifically, you want to build the cheapest network so that if...
31,144
Square Count (SQCOUNT) Little Bobby Roberts, age 8, has been dragged to yet another museum by his parents. While they while away the hours studying Etruscan pottery and Warhol soup cans, Bobby must depend on himself for entertainment. Having a mathematical bent, he recently started counting all the square tiles on t...
31,145
Swamp Things (SWTHIN) Hugh F. Oh, in his never-ending quest to prove the existence of extraterrestrials, has gotten hold of a number of nighttime photographs taken by a research group that is examining glowing swamp gas. Hugh wants to see if any of the photos show, not swamp gas, but Little Grey Men in glowing suits...
31,146
Two Ends (TWENDS) In the two-player game “Two Ends”, an even number of cards is laid out in a row. On each card, face up, is written a positive integer. Players take turns removing a card from either end of the row and placing the card in their pile. The player whose cards add up to the highest number wins the game....
31,147
Permalex (PRMLX) Given a string of characters, we can permute the individual characters to make new strings. If we can impose an ordering on the characters (say alphabetic sequence), then the strings themselves can be ordered and any given permutation can be given a unique number designating its position in that ord...
31,148
Funny scales (SCALE) Kinh_Can has a set of precious weights P 1 , P 2 ... P N in which the mass of the i th weight is P i = 3 i-1 , and a balance with 2 scales. On a nice day, Kinh_Can decided to show off his set of precious weights to his friends, and said that he can put them in equilibrium with any weight as lo...
31,149
Another Necklace Problem (NCKLCE) T Corporation is a company which produces colorful necklaces. The necklaces designed by them are unique and fashionable, and because of the price, they are popular with the youth. Now, T Corporation intends to design a self-help Producing System. This system includes hardware and ...
31,150
Can you answer these queries III (GSS3) You are given a sequence A of N (N ≤ 50000) integers between -10000 and 10000. On this sequence you have to apply M (M ≤ 50000) operations: modify the i-th element in the sequence or for given x y print max{A i + A i+1 + .. + A j | x ≤ i ≤ j ≤ y }. Input The first line ...
31,151
Life, the Universe, and Everything II (RP) This problem tests your mathematic knowledge and your programming ability very much. Your task is to calculate the number of different Minimum Spanning Trees (MSTs) of a special undirected unweighted graph. The graph has n nodes numbered from 1 to n, and there is an edge betw...
31,152
Bee Maja (BMJ) Documento sin título Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive consists of many hexagonal honey combs where the honey is stored in. But bee Maja has a problem. Willi told her where she can meet him, but because Willi is a male drone and Maja is...
31,153
Counting Triangles (TRICOUNT) We define the LEVEL of a triangle as in the following illustrative image: Task: Your task is very easy. All you have to do is to count all triangles in the biggest one (Level N). Input The first line of the input contains an integer T (T ≤ 10000) - the number of test cases and T ...
31,154
The Importance (IMPORT1) Given an undirected weighted graph { V , E }. Your task to calculate the importance of each node. The importance of a node v (I(v)) can be defined as follow: C s,t is the number of different shortest paths from s to t, C s,t (v) is the number of different shortest paths from s to t th...
31,155
Exchange (EXCHANGE) There are 3 kinds of money in a planet far away from the earth: Mone, Luck, and Rpin. There's a money exchange company in this planet. You must go to this company if you want to do some money exchange, and, more autocratically, this company regulate the exchange rate of each pair of these 3 kinds o...
31,156
Common Permutation (CPRMT) Given two strings of lowercase letters, a and b , print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b . Input Input file contains several lines of...
31,157
Counting Triangles II (TCOUNT2) We define the LEVEL of a triangle as in the following illustrative image: And we continue defining the LEVEL of a hexagon. It's called level N hexagon if it’s joined by 6 triangles, each one is a level N triangle. Task: All you have to do is to count all triangles in the “level...
31,158
Counting Triangles III (TCOUNT3) Have you felt bored when counting triangles? Like TRICOUNT and TCOUNT2, we define the LEVEL of a triangle as in the following illustrative image: And now we will continue defining the LEVEL of a hexagram. It's called level N hexagram if it’s joined by 12 triangles, each one is a ...
31,159
Yet Another Equation (EQU2) Consider the equation x 2 - n y 2 = 1 where n is some integer. Find the smallest strictly positive integer solutions ( x , y ) for a given n . Input The number of test cases t (around 30), followed by a list of t values of n (2 ≤ n ≤ 1000). You can assume th...
31,160
Tetris 3D (TETRIS3D) The authors of the game "Tetris" have decided to make a new, three-dimensional version, in which cuboids would fall down on a rectangular platform. The blocks fall down separately in a certain order, just like in the two-dimensional game. A block falls down until it reaches an obstacle: the platfo...
31,161
Evaluate the polynomial (POLEVAL) Your task consists of evaluate a polynomial of degree n ( 0 <= n <= 999 ) represented by its n+1 coefficients of the form: p n (x) = c n x n + c n-1 x n-1 + … + c 2 x 2 + c 1 x + c 0 in each one of the k ( 1 <= k <= 100 ) points x 1 , x 2 , …, x k . Th...
31,162
Sequence Partitioning II (SEQPAR2) Given a sequence of N ordered pairs of positive integers ( A i , B i ), you have to partition it into several contiguous parts. Let p be the number of these parts, whose boundaries are ( l 1 , r 1 ), ( l 2 , r 2 ), ... ,( l p , r p ), which satisfy l i = r i- 1...
31,163
Divisor Summation (Hard) (DIVSUM2) Given a natural number n (1 <= n <= 1e16), please output the summation of all its proper divisors. Definition: A proper divisor of a natural number is the divisor that is strictly less than the number. e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor sum...
31,164
Yet Another N-Queen Problem (NQUEEN) After solving Solution to the n Queens Puzzle by constructing, LoadingTime wants to solve a harder version of the N-Queen Problem. Some queens have been set on particular locations on the board in this problem. Can you help him?? Input The input contains multiple test case...
31,165
Find The Determinant II (DETER2) In this problem you have to calculate the determinant of an N x N matrix whose entries are given by m[i][j] = gcd(i,j) k , 1 ≤ i,j ≤ N. Here gcd(i,j) denotes the greatest common divisor of i and j. As the determinant D can grow very large, you have to print D%1000003. Input ...
31,166
All Discs Considered (ALL) Operating systems are large software artefacts composed of many packages, usually distributed on several media, e.g., discs. You probably remember the time when your favourite operating system was delivered on 21 floppy discs, or, a few years later, on 6 CDs. Nowadays, it will be shipped o...
31,167
Boolean Logic (BOOLE) Propositions are logical formulas consisting of proposition symbols and connecting operators. They are recursively defined by the following rules: All proposition symbols (in this problem, lower-case alphabetic characters, e.g., a and z ) are propositions. If P is a proposition, ...
31,168
DNA Laboratory (DNALAB) Having started to build his own DNA lab just recently, the evil doctor Frankenstein is not quite up to date yet. He wants to extract his DNA, enhance it somewhat and clone himself. He has already figured out how to extract DNA from some of his blood cells, but unfortunately reading off...
31,169
IOICamp Sequence (ICAMPSEQ) Let's say we have 4 N-elements sequences of real numbers: A[], B[], C[], D[] . Funtion F(i, j) is defined: F(i, j) = |A i - A j | + |B i - B j | + |C i - C j | + |D i - D j | (1 ≤ i, j ≤ N). Your task is very easy: you have to find the maximum of F(i, j). Input The first line:...
31,170
Code (CODE) KEY Inc., the leading company in security hardware, has developed a new kind of safe. To unlock it, you don't need a key but you are required to enter the correct n -digit code on a keypad (as if this were something new!). There are several models available, from toy safes for children (with a 2-digit cod...
31,171
In Danger (DANGER) Flavius Josephus and 40 fellow rebels were trapped by the Romans. His companions preferred suicide to surrender, so they decided to form a circle and to kill every third person and to proceed around the circle until no one was left. Josephus was not excited by the idea of killing himself, so he ca...
31,172
Run Length Encoding (ENCONDIN) Your task is to write a program that performs a simple form of run-length encoding, as described by the rules below. Any sequence of between 2 to 9 identical characters is encoded by two characters. The first character is the length of the sequence, represented by one of the cha...
31,173
Fractan (FRACTAN) To play the "fraction game" corresponding to a given list f 1 , f 2 ... f k of fractions and starting integer N , you repeatedly multiply the integer you have at any stage (initially N ) by the earliest f i in the list for which the answer is integral. Whenever there is no such f i , the gam...
31,174
Huffman´s Greed (GREEDULM) In the following we define the basic terminology of trees. A tree is defined inductively: It has a root which is either an external node (a leaf), or an internal node having a sequence of trees as its children. An internal node is also called the parent of the roots of its child ...
31,175
Binary Search Heap Construction (HEAPULM) Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal nodes have each assigned a priority (a number) such that the priority of each internal node is less than the p...
31,176
Text Generater II (GEN2) HL , HJ and FGD set problem for ZMY everyday. The title of each problem bores them very much. The title is a string which consists only lower case letters. Its length is L , and, of course, the title must contain their names (hl, hj, fgd) as consecutive substrings. More apparently, N ...
31,177
Greedy Hydra II (DRAGON2) The problem description is the same as the problem DRAGON . Input The first line contains 3 integers N (1 <= N <= 3000), M (2 <= M <= N), K (1 <= K <= N), separated by single spaces. The N fruits are numbered 1..N, and the biggest fruit is always numbered 1. N-1 lines follow, each contai...
31,178
Cardsharper (CARD) Zenek is a well known (at least in Byteotia) card-sharper. He spent most of his best years practicing one card shuffle with his deck of n cards, which for simplicity we will call 1, 2, ..., n . Unfortunately, it turns out that knowing this one card shuffle a is not enough to earn a good living....
31,179
Assistance Required (ASSIST) After the 1997/1998 Southwestern European Regional Contest (which was held in Ulm) a large contest party took place. The organization team invented a special mode of choosing those participants that were to assist with washing the dirty dishes. The contestants would line up in a queue, o...
31,180
The Bottom of a Graph (BOTTOM) We will use the following (standard) definitions from graph theory. Let $V$ be a nonempty and finite set, its elements being called vertices (or nodes). Let $E$ be a subset of the Cartesian product $V \times V$, its elements being called edges. Then $G = (V, E)$ is called a directed g...
31,181
Fixed Partition Contest Management (CONTEST) A technique used in early programming contest strategies involved partitioning the available intellectual capacity of a team into a number of members with each member having a fixed amount of intelligence, different members potentially having different amounts. The sum of t...
31,182
Drink, on Ice (DRINK) A good drink is always served on ice. That said, the amount of ice is what makes the difference. If it is too much, the drink will be well cooled, however, this is a bit of fraud as there could be less ice (and more Vodka for example). On the other hand, if there is too little ice the drink is...
31,183
Edge (EDGE) For products that are wrapped in small packings it is necessary that the sheet of paper containing the directions for use is folded until its size becomes small enough. We assume that a sheet of paper is rectangular and only folded along lines parallel to its initially shorter edge. The act of folding al...
31,184
Fold (FOLD) Read the statement of problem E: Edge to understand how to fold a sheet of paper and how to interpret the input. We define a "stripe" to be a maximally large part of the sheet that has no folding line going through. Since the turns occur at equidistant places, all stripes are congruent. In this p...
31,185
Genetic Code (GENETIC) The connections between mathematics and biology are complicated. Most of the time they do not run along nice-looking links that merrily join at first glance, but they are abstract and not always easily established. Lake Vostok - about 14000 square kilometers large, up to 650 meters deep...
31,186
Largest Rectangle in a Histogram (HISTOGRA) A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectangles with the heights 2, 1, 4, 5, 1,...
31,187
Nuclear Plants (ORZ) The Great Plain of Algorithmia plays an extremely important role in the agriculture of the Bandulu Kingdom: this is the only place where barley (Hordeum vulgare), an essential ingredient of beer, can be produced. Unfortunately, it is not possible to grow barley on the full area of the plain, as se...
31,188
Longest Common Substring (LCS) A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the set of lowercase letters. Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string. Now your task is simple, for two given s...
31,189
Longest Common Substring II (LCS2) A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the set of lowercase letters. Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string. Now your ...
31,190
Problems Collection (Volume X) (WA) These ten problems come from Chinese National Olympiad in Mathematics - Province Contest. Problem 1 Polynomial P(x)=x 5 +a 1 x 4 +a 2 x 3 +a 3 x 2 +a 4 x+a 5 , and we know when k=1, 2, 3, 4, P(k)=2007*k. Calculate P(10)-P(-5). Problem 2 The sum of 100 positive integers a 1 , a...
31,191
Free tour II (FTOUR2) After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, Travel Agent SPOJ goes on with another discount tour. The tour will be held on ICPC island, a miraculous one on the Pacific Ocean. We list N places (indexed from 1 to N ) where the visit...
31,192
Sudoku (SUDOKU2) Oh no! Bill just realized that the sudoku puzzle he had spent the last ten minutes trying to solve essentially was last week's puzzle, only rotated counterclockwise. How cheap! Couldn't the magazine afford to make a new one every week? Of course, he had no way of knowing about this before he start...
31,193
The SetStack Computer (SETSTACK) Background from Wikipedia: Set theory is a branch of mathematics created principally by the German mathematician Georg Cantor at the end of the 19th century. Initially controversial, set theory has come to play the role of a foundational theory in modern mathematics, in the sense ...
31,194
Pie (PIE) My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that lo...
31,195
Ticket to Ride (TICKET) Ticket to Ride is a board game for up to 5 players. The goal of the game is to set up train lines (and to thwart the opponents' attempts at setting up their train lines). At the beginning of play, each player is assigned four train lines. A player may choose to discard as many of these f...
31,196
The Bookcase (BOOKCASE) No wonder the old bookcase caved under the massive piles of books Tom had stacked on it. He had better build a new one, this time large enough to hold all of his books. Tom finds it practical to have the books close at hand when he works at his desk. Therefore, he is imagining a compact sol...
31,197
Printer Queue (PQUEUE) The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to get a single page of output. Because some jobs are more important than others, the Hacker G...
31,198
Prime Path (PPATH) The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a matter of security to change such things every now and then, to keep the enemy in the dark. — But ...
31,199