Showing posts with label Volume CIII. Show all posts
Showing posts with label Volume CIII. Show all posts

Solution of 10324 - Zeros and Ones

Problem Description
source:https://uva.onlinejudge.org/external/103/10324.html

Given a string of 0’s and 1’s up to 1000000 characters long and indices i and j, you are to answer a question whether all characters between position min(i, j) and position max(i, j) (inclusive) are the same. 

Input

There are multiple cases on input. The first line of each case gives a string of 0’s and 1’s. The next line contains a positive integer n giving the number of queries for this case. The next n lines contain queries, one per line. Each query is given by two non-negative integers, i and j. For each query, you are to print ‘Yes’ if all characters in the string between position min(i, j) and position max(i, j) are the same, and ‘No’ otherwise. 

image

Solution of 10394 - Twin Primes

Problem Description
source:https://uva.onlinejudge.org/external/103/10394.html

Twin primes are pairs of primes of the form (p, p + 2). The term “twin prime” was coined by Paul Stckel (1892-1919). The first few twin primes are (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43). In this problem you are asked to find out the S-th twin prime pair where S is an integer that will be given in the input.

Input 

The input will contain less than 10001 lines of input. Each line contains an integers S (1 ≤ S ≤ 100000), which is the serial number of a twin prime pair. Input file is terminated by end of file. 
image

Solution of 10370 - Above Average

Problem Description
source:https://uva.onlinejudge.org/external/103/10370.html

It is said that 90% of frosh expect to be above average in their class. You are to provide a reality check.

Input 

The first line of standard input contains an integer C, the number of test cases. C data sets follow. Each data set begins with an integer, N, the number of people in the class (1 ≤ N ≤ 1000). N integers follow, separated by spaces or newlines, each giving the final grade (an integer between 0 and 100) of a student in the class. 

Soution of 10346 - Peter's Smokes

Problem Description
source:https://uva.onlinejudge.org/external/103/10346.html

Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette. 
         How many cigarettes can Peter have? 

Input 

Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k. The input is terminated by end of file. 

Output 

For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have. 

image

Solutio of 10340 - All in All

Problem Description
source:https://uva.onlinejudge.org/external/103/10340.html

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string. 
         Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s. 

Input 

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF. 

image

Solution of 10327 - Flip Sort

Problem Description
source:https://uva.onlinejudge.org/external/103/10327.html

Sorting in computer science is an important part. Almost every problem can be solved effeciently if sorted data are found. There are some excellent sorting algorithm which has already acheived the lower bound n · lg n. In this problem we will also discuss about a new sorting approach. In this approach only one operation (Flip) is available and that is you can exchange two adjacent terms. If you think a while, you will see that it is always possible to sort a set of numbers in this way. 
      A set of integers will be given. Now using the above approach we want to sort the numbers in ascending order. You have to find out the minimum number of flips required. Such as to sort ‘1 2 3’ we need no flip operation whether to sort ‘2 3 1’ we need at least 2 flip operations. 

image

Solution of 10300 - Ecological Premium

Problem Description
source:https://uva.onlinejudge.org/external/103/10300.html

German farmers are given a premium depending on the conditions at their farmyard. Imagine the following simplified regulation: you know the size of each farmer’s farmyard in square meters and the number of animals living at it. We won’t make a difference between different animals, although this is far from reality. Moreover you have information about the degree the farmer uses environment-friendly equipment and practices, expressed in a single integer greater than zero. The amount of money a farmer receives can be calculated from these parameters as follows. First you need the space a single animal occupies at an average. This value (in square meters) is then multiplied by the parameter that stands for the farmer’s environment-friendliness, resulting in the premium a farmer is paid per animal he owns. To compute the final premium of a farmer just multiply this premium per animal with the number of animals the farmer owns.

image