Sie sind auf Seite 1von 16

Archives of the High School Programming League Problems Archive

fourth problemset

Editors:
ukasz Kuszner Damir Ferizovic Przemek Komosa Yandry Perez Piotr Turek Duko Obradovi
Last updated: 2012-03-13 18:00:45

Preface
This electronic material contains a set of algorithmic problems, forming the archives of the High School Programming League Problems Archive (http://www.spoj.pl/HSPLARCH/), fourth problemset. The document can be accessed at the following URLs: in PostScript format: http://www.spoj.pl/HSPLARCH/problems/fourth.ps in Portable Document Format: http://www.spoj.pl/HSPLARCH/problems/fourth.pdf These resources are constantly updated to synchronise with the ever-changing hypertext version of the problems, and to include newly added problems. If you have obtained this document from another source, it is strongly recommended that you should download the current version from one of the aforementioned URLs. Enjoy problem-solving at the High School Programming League Problems Archive!
Disclaimer from the Editors. Despite our best efforts, it is possible that this document contains errors or that some of the content differs slightly from its original hypertext form. We take no responsibility for any such faults and their consequences. We neither authorise nor approve use of this material for any purpose other than facilitating problem solving at the Sphere Online Judge site; nor do we guarantee its fitness for any purpose whatsoever. The layout of the problems in this document is the copyright of the Editors named on the cover (as determined by the appropriate footers in the problem description). The content is the copyright of the respective Editor unless the copyright holder is otherwise stated in the resource section. The document as a whole is not protected by copyright, and fragments of it are to be regarded independently. No responsibility is taken by the Editors if use or redistribution of this document violates either their or third party copyright laws. When referring to or citing the whole or a fragment of this document, please state clearly the aforementioned URLs at which the document is to be found, as well as the resources from which the problems you are referring to originally came. Remarks concerning this document should be sent to the following e-mail address: contact@spoj.pl.

Table of Contents
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. Problem HS11DIVS (9486. Count the numbers!) Problem HS11INV2 (9497. Another Investment) Problem HS11EXPR (9499. Problem with an expression) Problem HS11CTPR (9537. Caterpillars) Problem HS11WRTP (9544. Winter Trip) Problem HS11CNSM (9602. Coins on the Matrix) Problem HS11BULH (9719. Building allowance) Problem HS11STRM (9733. String manipulation) Problem HS11MCTP (9735. More Caterpillars) Problem HS11SNTW (9736. Social Network Existence) Problem HS11SNI (9762. Social Networks Resistance) Problem HS11MEGA (9823. Megalopolis) Problem HS11IO (10041. Inside or outside) Problem HS11BST (10177. Search Tree) Problem HS11SNI2 (10216. Social Networks Resistance II) Problem HS11POK (10269. O - Poker) Problem HS11SEQ (10407. Sequences) Problem HS11PART (10423. Half of a Set) Problem HS11LFSR (10434. Linear Feedback Shift Register) Problem HS11SPDW (10483. Speedway)

SPOJ Problem Set (fourth)

9486. Count the numbers!


Problem code: HS11DIVS
[IMAGE] For given integers a and b your task is to find how many integers in the range [a,b] are divisible by a number x, and have the additional property that the sum of their digits lies in the range [l,r] for given l,r.

Input
In the first line youre given a and b ( 1 <= a <= b < 10^100 ). In the second line youre given three positive integers x ( 1 <= x <= 10 ), l, r ( 1 <= l <= r <= 1,000 ).

Output
In the first and only line output the result modulo 1,000,000,007.

Example
Input:1 1005 10 50Output:5

Scoring
By solving this problem you score 10 points. Added by: Damir Ferizovic Date: 2011-08-31 Time limit: 2s Source limit:50000B Languages: All except: CLOJ PERL 6 Resource: High School Programming League 2011/12

SPOJ Problem Set (fourth)

9497. Another Investment


Problem code: HS11INV2
[IMAGE] In n successive years Robert made n investments, one per year. Now, he would like to verify how effective his investments were and to calculate the annualized rate of return for them.

Input
The first line of input contains one integer 1< n <10 - the number of years to be considered. In the next n lines you are given the amount (with two digits of precision) of Roberts investment in each of the consecutive years - one amount in each line. The last line contains one number: Y>0 - the total value of all of Roberts investments after n years, with two digits of precision.

Output
Output the internal rate of return (IRR), assuming that annual investment period lengths were equal, as a percentage value with two digits of precision. Example 1
Input: 4 1000.00 1000.00 1000.00 1000.00 7000.00 Output: 23.69

Example 2
Input: 3 3 2 2 3 Output: -34.63

Scoring
By solving this problem you score 10 points. Added by: ukasz Kuszner Date: 2011-09-05 Time limit: 1s Source limit:50000B Languages: All except: CLOJ PERL 6 Resource: High School Programming League

SPOJ Problem Set (fourth)

9499. Problem with an expression


Problem code: HS11EXPR
[IMAGE] Consider a mathematical expression where you just have 2 types of operations: multiplication and division. The operands are either positive integers or the factorial of a positive integer. For example, a valid expression would be: 2*5!*10!/11!. Given such an expression, you have to calculate the prime factorization of it and to print it as the result. All primes should be in increasing order and their exponents should be non-zero (not necessarily positive) integers.

Input
In the first and only line you are given the expression. The sum of all integers which appear in the expression is less than or equal 1,000,000.

Output
Output the desired factorization. The output p 0 ^a 0 *p 1 ^a 1 .....p n ^a n , where p 0 < p 1 < ... p n . must be in the following form:

Example
Input:2*5!*10!/11!Output:2^4*3^1*5^1*11^-1

Scoring
By solving this problem you score 10 points. Added by: Damir Ferizovic Date: 2011-09-05 Time limit: 2s Source limit:50000B Languages: All except: CLOJ ICK PERL 6 Resource: High School Programming League 2011/12

SPOJ Problem Set (fourth)

9537. Caterpillars
Problem code: HS11CTPR
[IMAGE] There are two kinds of caterpillars: vertical and horizontal ones. A vertical caterpillar looks like this:
### ..# ### # #.. ### ..# [ --- here the first segment starts [ --- here the first segment ends

[ --- the rest depends on the caterpillars height

While a horizontal caterpillar looks like this:


#.##[ middle segments of ].###. #.#.[ a horizontal ].#.#. ###.[ caterpillar ]##.##

Print a caterpillar according to a given specification.

Input data specification


Input consists of one letter V for vertical caterpillars or H for horizontal ones and an integer 2 < n < 20 - the caterpillar size in segments.

Output data specification


Caterpillar as in the example below.

Example 1
Input: V3 Output: ### ..# ### #.. ### ..#

Example 2
Input: H6 Output: #.###.###.## #.#.#.#.#.#. ###.###.###.

Scoring
By solving this problem you score 10 points. Added by: ukasz Kuszner Date: 2011-09-13 Time limit: 1s Source limit:50000B Languages: All except: CLOJ ICK PERL 6 Resource: High School Programming League

SPOJ Problem Set (fourth)

9544. Winter Trip


Problem code: HS11WRTP
[IMAGE] Julia and Robert are going to spend some time on vacation in a faraway skiing resort of their dreams. Unfortunately, their free time and funds are very limited (so typical, isnt it?). Still, since the vacation resort has already been booked in advance, they must arrange the trip there and back. I will do it. - said Robert, and after a few minutes of browsing the web he proudly presented their itinerary. This is too expensive, we cannot afford it! - complained Julia, looking at it - let me try. Julias suggestion for their trip was much cheaper, but unfortunately their travel would take up too much time. This is completely unacceptable - said Robert. After some discussion, they have decided to approach the problem as follows: 1. They cannot spend more than k$ on travel. 2. They want to travel along the shortest possible way, as long as the first condition is true. Having the above in mind, Julia and Robert have decided to ask you for help. First, they would like to solve the simplified case in which arrival/departure times are not taken into account, and all transport connections between points are bidirectional.

Input
In the first line, you are given start and end - the names of the starting and the destination points, respectively. In the next line, you are given: k <= 10 9 - the maximum travel cost and m<= 4 * 10 6 the number of connections. Each of the following m lines contains: code name 1 name 2 cost time describing the connection from place name 1 to place name 2 and the cost and time corresponding to i. The number of different names is <= 10 6 ; cost i <= 1000; time i <= 10 6 . You can assume that there is always a path which fulfills the criteria, for which the total time does not exceed 10 9 . Names used in the description are sequences of at most 32 characters of the Latin alphabet written in both lower and upper case.

Output
First output c, the number of connections which you will use in your solution. In the following c lines output: code - the code of the i-th connection, and in the final line: total_cost total_time (the total cost and time of the whole travel).

Scoring
For each test case: score = some_constant - total_time if total_cost <= k or 0 otherwise, where the some_constant is a test case specific positive integer. The number of points given in the ranking is scaled so that it is equal to 10 for the contestant whose solution has the highest score, and is proportionally less for all solutions with lower scores.

Example 1
Input: Wilamowo Burszewo 7 5 aA Wilamowo Boleszyn 6 2 KRC Wilamowo Burszewo 8 3 SsRS Boleszyn Burszewo 2 4 bbb Wilamowo Boleszyn 4 6 adsK Wilamowo Burszewo 5 12 Output: 2 bbb SsRS 6 10 Score: If the some_constant is equal to 12 then the score is equal to 12-10=2 points.

More information about test cases

test number the number of names the number of connections 0 1 2 3 4 5 6 7 8 9 100 300 1000 1500 6000 100 300 1000 1500 6000 206 623 2070 3109 12384 210 634 2119 3223 12780

Note
For the first weeks of the series all submissions to this problem will be visible to all users and tested on 5 data sets only. For the last week of the series, submissions will be visible to the submitting contestant, only, and tested on all 10 data sets. (Earlier solutions will also be extended to all 10 data sets.) Added by: Przemek Komosa Date: 2011-09-14 Time limit: 1s-5s Source limit:50000B Languages: All except: CLOJ ICK PERL 6 Resource: High School Programming League

(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();

SPOJ Problem Set (fourth)

10483. Speedway
Problem code: HS11SPDW
Given a vehicle and an oval circuit surface you are requested to compute a route around the track for a vehicle, making it as fast as possible. The track is bounded by two ellipses: the outer one and the inner one. You must keep the vehicle inside the outer ellipse and outside the inner ellipse. The centers of both ellipses are placed in the same point (0, 0). The lengths of the semi-axes are: hIW - the length of the semi-axis parallel to the x-axis of the inner ellipse hIH - the length of the semi-axis parallel to the y-axis of the inner ellipse hOW - the length of the semi-axis parallel to the x-axis of the outer ellipse hOH - the length of the semi-axis parallel to the y-axis of the outer ellipse Your vehicle is very simple and at every moment it is able to perform only one action among the two: to turn_left - the vehicle turns left by the angle a and slows down (decelerates). to speed_up - the vehicle accelerates keeping the previous direction. Acceleration and deceleration rates are parameters of the vehicle: acc, dec.

Simulation
The simulation proceeds in steps. At the beginning (step 0) the vehicle is placed at point (0, (hIH + hOH)/2) with initial velocity = [-1, 0]. The coordinates and velocity of your vehicle in the next steps depend on the previous coordinates, its velocity, and the command it is following. The vehicle coordinates in the (n+1)-th step are simply coordinates in the n-th step plus velocity (where velocity is a vector, thus addition is performed separately for the horizontal and vertical coordinates). If the n-th action is speed_up, than the vehicles velocity in the (n+1)-th step is: (|velocity| + acc) / |velocity|) velocity. If the n-th action is turn, than the vehicles velocity in the (n+1)-th step is: (|velocity| - dec) / |velocity|) velocity R, where R is the two-dimensional rotation matrix by adegrees. You control your vehicle by two commands: s for speed_up and t for turn_left. We will assume that the vehicle never stops and if you command it to stop (or something close to stop, that is you give the command t while the vehicles speed is at most dec+0.0001), the vehicle will accelerate anyway. Simulate the process using the single-precision floating-point variables (e.g. float in C, C++, Java, ...).

Input
The first line contains the number of test cases t. Each of the following t lines contains: 4 integers 10 < hIW, hIH, hOW, hOH < 1000, hIW<hOW and hIH<hOH (describing the arena), and 3 positive numbers acc, dec, a describing the vehicle.

Output
For each test case output the number k of steps which could have led from the initial vehicle position to the completion of one lap of the track and in the next line, the description of those steps (please consult the example below) or one word NO if you do not want to solve this particular test case.

Scoring
The score awarded to your program for a given test case is computed as 1000-k. The score awarded for a given test set is computed as a maximum of 0 and the sum of scores for individual test cases. The overall score of the program is the sum of scores obtained for correctly solved tests. The number of points given in the ranking is scaled so that it is equal to 10 for the registered contestant whose solution has the highest score, and proportionally less for all solutions with lower scores.

Example
Input: 2 300 150 450 300 0.3 0.7 15.0 300 150 320 170 0.3 0.3 5.0 Output: 142 sssssssssssssssssssssssstsssssstsssssstssssstsssssssstsst ssstsstssststssssstsssstssssssssssssssssstssssststsstssts tststsssstsststssssstsssssss [the whole string in one line] NO Scoring: test1 1000-142=858 points test2 skipped set score: 858 points.

The trace for the above route is available here.

Input data

n 1 2 3 4 5 6 7 t 1 6 10 10 10 10 10 k >40 >70 >100 >350 ?? ?? ?? l 2s 2s 2s 2s 5s 5s 5s

(some cases might be unsolvable)

n t k l

test set number the amount of test cases in the test set the expected number of steps to be taken time limit

Please note
Till the last week of the series, all submitted codes will be visible to all users and tested on temporary data sets only. For the last week of the series, submissions will be visible to the submitting contestant, only, and tested on the full set of test cases. After the deadline datasets will be slightly modified and all solutions will be rejudged. Please do not submit more than 100 times to this problem (all submissions starting with the 101st will be ignored). Added by: ukasz Kuszner Date: 2012-01-26 Time limit: 2s-5s Source limit:50000B Languages: All except: CLOJ ICK PERL 6 Resource: High School Programming League

Das könnte Ihnen auch gefallen