Solution of 11219 - How old are you?

Problem Description
source:http://uva.onlinejudge.org/external/112/11219.html

- Here are the filled form. - Thank you. Let me check... hum... OK, OK, OK... Wait, how old are you? - 20. Did I forget to fill it?
- No. It says here that you’ll be born next month! The year is wrong...
- Oh... Sorry!

The process is going to be automatic and to avoid some human errors there will be a calculated field that informs the age based in the current date and the birth date given. This is your task, calculate the age, or say if there’s something wrong.

Input The first line of input gives the number of cases, T (1 ≤ T ≤ 200). T test cases follow. Each test case starts with a blank line, then you will have 2 lines corresponding to the current date and the birth date, respectively. The dates are in the format DD/MM/Y Y Y Y , where DD is the day, MM the month and Y Y Y Y the year. All dates will be valid.


image

Solution of 12403 - Save Setu

Problem Description
source: https://uva.onlinejudge.org/external/124/p12403.html

Rahaduzzaman Setu, (Roll - 12) of 13th batch, CSE, University of Dhaka is tremendously ill. He has been suffering from Multi Drug Resistant TB for a long time. Now, his left lung is damaged and beyond repair. No medicine is working on his body to ease his pain. It is urgent to operate on his left lung so that the disease doesn’t spread to his right lung. It can either be removed through surgery or transplanted. He comes from a modest family and it is difficult and impossible for them to bare his medical expenses anymore. Because of the money needed (12 million BDT) to transplant, it is his family’s decision to go with the surgery (3 million BDT). We must help them financially by raising money. But we must not be confined with that amount only to do the surgery. We must go for the Transplant. Our target will be to collect as much as possible to help our friend. If anyone wants to contribute now, please send me your contribution or contact me. Please contribute as much as you can to save a life that you saw every week for the first two years of your University life. Please contribute as per your abilities. Our combined effort may save a life. For more information, consult the link below

image

Algorithm of 11526 - H(n)

Problem Description Link
Algorithm
The problem is not difficult but we need to consider the problem of time limit exceeded, e.g. we are computing n/n, n/n-1, .....there are so many ones and twos,... these can be computed in one step. We can observe the number of 1, 2, 3.....the number of j is n/j - n/(j+1).  so when the number is small and many, we use the n/j - n/(j+1) method. for numbers big and few, just use the original method. We can set the break point at sqrt(n). Do not repeat the values around sqrt(n). Try to avoid division by 0 and sqrt of negative numbers.

Example:
if n=5 series is 5/1 + 5/2 + 5/3 + 5/4 + 5/5
    then sqrt(5)=2 need loop two times
    5/1-5/2=3 means 1 get 3 times, so SUM=3*1=3
    5/2-5/3=1 means 2 get 1 times, so SUM=3+2*1=5
    so last 4 (3+1) steps complete from the series ,so now we nedd calculate first 1 step
image

Solution of 11526 - H(n)

Problem Description
source: https://uva.onlinejudge.org/external/115/11526.html

What is the value this simple C++ function will return? 

long long H(int n){ 
    long long res = 0;
    for( int i = 1; i <= n; i=i+1 ){
        res = (res + n/i);
    } 
    return res; 
} 

image

Solution of 10523 - Very Easy !!!

Problem Description
source:https://uva.onlinejudge.org/external/105/10523.html

Most of the times, the students of Computer Science & Engineering of BUET deal with bogus, tough and very complex formulae. That is why, sometimes, even for a easy problem they think very hard and make the problem much complex to solve. But, the team members of the team “BUET PESSIMISTIC” are the only exceptions. Just like the opposite manner, they treat every hard problem as easy and so cannot do well in any contest. Today, they try to solve a series but fail for treating it as hard. Let them help.

image

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

Algorithm of 10127 - Ones

Problem Description Link
Algorithm


This is a very simple but tricky problem. If you want to calculate the sequence of one by increasing ONE, then two things can be happened.
1) If your data type is even long double (in C it is the highest data type), it can not hold the sequence and because of overflow you will get WA.
2) If your data type is string then you will get "time limit exceeded". To avoid these problems we need to follow a trick here.

The Algorithm

input (it will be the input of the problem) 
dividend=1
one=1 (in this variable finally we get how many one will be in the sequence)
image

Algorithm of 713 - Adding Reversed Numbers

Problem Description Link
Algorithm
This is the simple string related problem. You can solve easily using your defined string adding function. you need first
reverse the string that you entered and add two string. after adding print the result reveser order. You must
 Omit any leading zeros in the output.
You no need reverse the inputs if you adding atart from left most. but you nee create same length two string by insert 0.
For Example:
a=4358
b=754
length not same so create same length add 0 in b at right most
b=7540
 now add
a=4358
b=7540
-----------
r=1998 this is the result

if a=305 and b= 794

add
 a=305
 b=794
---------------
r= 0001 so you need avoid all leftmost 0 s, so 1 is the result.
image

Solution of 713 - Adding Reversed Numbers

Problem Description
source: https://uva.onlinejudge.org/external/7/713.html

The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.

 Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros. 

image

Algorithm of 847 - A Multiplication Game

Problem Description Link
Algorithm
It is a quite hard to find this rule to solve this problem... however if Stan and Ollie plays perfect game, then Stan will always try to multiply p with 9 and Ollie will always try to multiply p with 2... and so on, so just simulate the process  (i.e. for n, you multiply by 9, then multiply by 2, then multiply by 9... etc until p>= n), then check whose turn can make p becomes greater or equal to p and output the winner name.
image

Solution of 847 - A Multiplication Game

Problem Description
source:https://uva.onlinejudge.org/external/8/847.html

Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner is who first reaches p ≥ n. 

Input and Output

 Each line of input contains one integer number n. For each line of input output one line either 

image

Algorithm of 401 - Palindromes

Problem Description Link
Algorithm:
This is a simple problem to solve this problem you need to read carefully.
However you can follow this technique to solve this problem.
1. At first you need 3 array for input string , reverse string and mirror string.
2. get input string
3. put value in reverse string array from input string . Last value of input string insert into
    first value of reverse string and so on.
4. put value in mirror string from input string reverse order
    when insert character in follow condition
    if input string character is E then insert 3 and vise versa
    if input string character is L then insert J and vise versa
    if input string character is S then insert 2 and vise versa
    if input string character is Z then insert 5 and vise versa
5. Check reverse string with input string if same put a falg rf=1;
6. for mirror check
    Check mirror string with input string character by character
    if get B,C,D,F,G,K,N,P,Q,R,4,6,7,9 in input string then this sting not mirror string
    otherwise it is mirror so flag mp=1;
N.B: in this problem O and 0(zero) are same.
7. for print check
    if(rp==0 && mp==0)
            printf("%s -- is not a palindrome.\n\n",input);
        else if(rp==1 && mp==0)
            printf("%s -- is a regular palindrome.\n\n",input);
        else if(rp==0 && mp==1)
            printf("%s -- is a mirrored string.\n\n",input);
        else if(rp==1 && mp==1)
            printf("%s -- is a mirrored palindrome.\n\n",input);
image

Solution of 401 - Palindromes

Problem Description
source:https://uva.onlinejudge.org/external/4/401.html

A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string “ABCDEDCBA” is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left. A mirrored string is a string for which when each of the elements of the string is changed to its reverse (if it has a reverse) and the string is read backwards the result is the same as the original string. For example, the string “3AIAE” is a mirrored string because ‘A’ and ‘I’ are their own reverses, and ‘3’ and ‘E’ are each others’ reverses. A mirrored palindrome is a string that meets the criteria of a regular palindrome and the criteria of a mirrored string. The string “ATOYOTA” is a mirrored palindrome because if the string is read backwards, the string is the same as the original and because if each of the characters is replaced by its reverse and the result is read backwards, the result is the same as the original string. Of course, ‘A’, ‘T’, ‘O’, and ‘Y’ are all their own reverses. A list of all valid characters and their reverses is as follows.

Programming Challenges by Steven S. Skiena and Migual A. Revilla

This book has been designed to serve as a textbook for three types of courses:
•Algorithm courses focusing on programming.
•Programming courses focusing on algorithms.
•Elective courses designed to train students to participate in competitions such
as the Association for Computing Machinery (ACM) International Collegiate
Programming Contest and the International Olympiad in Informatics.

Pedagogical features of this book include:
1. Complements Standard Algorithm Texts.
2. Provides Complete Implementations of Classical Algorithms.
3. Integrated Course Management Environment .
4. Help for Students at All Levels.





To Download This Book Click Here

Discrete mathematics and its applications 6th Edition

A  discrete  mathematics course  has more than  one purpose.  Students  should learn  a particular
set of  mathematical facts and how to apply them; more importantly,  such a course should  teach
students  how to  think  logically  and  mathematically.  To  achieve  these  goals,  this  text  stresses
mathematical  reasoning  and the  different  ways  problems  are  solved.  Five  important  themes
are  interwoven in  this  text: mathematical reasoning, combinatorial analysis, discrete structure s,
algorithmic thinking, and applications and  modeling. A successful discrete mathematics  course
should carefully blend and balance all five themes.
1.  Mathematical Reasoning.
2.  Combinatorial Analysis.
3.  Discrete Structures.
4.  Algorithmic  Thinking.
5.  Applications and  Modeling
To Download This Book Click Here

Algorithm of 10189 - Minesweeper

Problem Description Link
Algorithm:
In this problem if you compare with "." and increase the adjacent value it is more time consume and get garbage value when row=0 or row=n
 in this case no have 8 adjacent value.
 so you can compare with "*" and generate another 2D value array that contain only value.
 if get "*" in input array then increase the all adjacent value and store that value in value array.
After generating the all value check from input array if character is "*" then print the "*" otherwise print from value array for this position.
image

Solution of 10189 - Minesweeper

Problem Description
source:https://uva.onlinejudge.org/external/101/10189.html

Have you ever played Minesweeper? It’s a cute little game which comes within a certain Operating System which name we can’t really remember. Well, the goal of the game is to find where are all the mines within a M × N field. To help you, the game shows a number in a square which tells you how many mines there are adjacent to that square. For instance, supose the following 4 × 4 field with 2 mines (which are represented by an ‘*’ character): 

*... 
.... 
.*.. 
.... 
If we would represent the same field placing the hint numbers described above, we would end up
with:
*100 
2210 
1*10 
1110
As you may have already noticed, each square may have at most 8 adjacent squares.


image

Algorithm of 10533 - Digit Primes

Problem Description Link

Algorithm:

This is a simple prime related problem
if a number is a prime then check that if sum of prime digit also prime then this digit is called digit prime
For example the prime number 41 is a digit prime because 4+1=5 and 5 is a prime number. 17 is not a digit prime because 1+7 = 8, and 8 is not a prime number.
But to solve this problem if you follow ittarative way then you may got TLE.
so you must generate prime and digit-prime before goe input.
and follow this technique.
1.pre calculate number of digit primes from 1 to 1000000
2. when you get t1 & t2 , number of digit primes t2 subtract number of digit primes t1-1
3. if t1 = 10, t2 = 100 . Number of digit primes at 10 is 4 and number of digit primes at 100 is 14
so dprime[100] - dprime[10-1] = 14 - 4 = 10
4. print the difference.

image

Solution of 10533 - Digit Primes

Problem Description
source:https://uva.onlinejudge.org/external/105/10533.html

A prime number is a positive number, which is divisible by exactly two different integers. A digit prime is a prime number whose sum of digits is also prime. For example the prime number 41 is a digit prime because 4 + 1 = 5 and 5 is a prime number. 17 is not a digit prime because 1 + 7 = 8, and 8 is not a prime number. In this problem your job is to find out the number of digit primes within a certain range less than 1000000. 

Input 

First line of the input file contains a single integer N (0 < N ≤ 500000) that indicates the total number of inputs. Each of the next N lines contains two integers t1 and t2 (0 < t1 ≤ t2 < 1000000). 

Output 

image

Algorithm of 406 - Prime Cuts

Problem Description Link
Algorithm:

This is a prime related problem . In this problem you need to   generate the  prime number from 1 to N.
Where 1 also a prime number in this problem .
After generate the all prime number from 1 to N count the prime numbers check.
 I f prime numbers are even then print the center (c*2) primes  .
I f prime numbers are odd then print the center (c*2-1) primes  .
If center (c*2) for even or (c*2-1) for odd excite the list of all prime numbers then print all prime from 1 to N
For example.
image

Solution of 406 - Prime Cuts

Problem Description
source:https://uva.onlinejudge.org/external/4/406.html

A prime number is a counting number (1, 2, 3, . . .) that is evenly divisible only by 1 and itself. In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between (and including) 1 and N. Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the 2C prime numbers from the center of the list if there are an even number of prime numbers or 2C − 1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

Input 

Each input set will be on a line by itself and will consist of 2 numbers. The first number (1 ≤ N ≤ 1000) is the maximum number in the complete list of prime numbers between 1 and N. The second number (1 ≤ C ≤ N) defines the 2C prime numbers to be printed from the center of the list if the length of the list is even; or the 2C − 1 numbers to be printed from the center of the list if the length of the list is odd.

image

Solution of 12342 - Tax Calculator

Problem Description
source:https://uva.onlinejudge.org/external/123/12342.html

People of a certain country have a little interest in paying tax. This is not the case that they do not love the country or they do not want to obey the law, but the problem is the complex calculations for payable tax. Most of the people do not understand the rule and some lawyers take high charges to help(?) them. So, most of the people just avoid paying tax. Realizing this, the Government decided to automate the taxpaying system and appointed you to program a tax calculator that takes a persons yearly income as input and calculate the payable tax for him. Here is the rule for calculate payable tax for an individual:
1. The first 180,000/- of income is tax free.
2. Next 300,000/- will have 10% tax.
3. Next 400,000/- will have 15% tax.
4. Next 300,000/- will have 20% tax.
5. The rest will have 25% tax.

Solution of 12068 - Harmonic Mean

Problem Description
source:https://uva.onlinejudge.org/external/120/12068.html

Input 

The first line of the input file contains an integer S (0 < S < 501), which indicates how many sets of inputs are there. Each of the next S lines contains one set of input. The description of each set is given below: Each set starts with an integer N (0 < N < 9), which indicates how many numbers are there in this set. This number is followed by N integers a1, a2, a3 . . . aN−1, aN (0 < ai < 101). 

Algorithm of 12043 - Dvisor

Problem Description Link
Algorithm:
In this problem if you use more loop in main program to determine the number of divisor and sum of divisor may be you get time limit exit .
so before test case you must generate two array for divisor and sum_of_divisor and and finally use a loop l
i=a to b and check that if any value i mod k is zero then add div+=divisor[i] and sum+=sum_of_divisor[i];
To generate divisor[] and sum_of_divisor[] you can use siv method
that method is bellow :
at first you must set each element 1 in divisor[] and sum_of_divisor[] after then
image

Solution of 12043 - Dvisor

Problem Description
source:https://uva.onlinejudge.org/external/120/12043.html


Let us define the functions d(n) and σ(n) as 
d(n) = number of divisors of n 
σ(n) = summation of divisors of n 

Here divisors of n include both 1 and n. For example divisors of 6 are 1, 2, 3 and 6. So d(6) = 4 and σ(n) = 12. 
Now let us define two more function g(a, b, k) and h(a, b, k) as 

g(a, b, k) = ∑ i d(i) 
h(a, b, k) = ∑ i σ(i) 

Where a ≤ i ≤ b and i is divisible by k. 

image

Solution of 12015 - Google is Feeling Lucky

Problem Description
source:https://uva.onlinejudge.org/external/120/12015.html

Google is one of the most famous Internet search engines which hosts and develops a number of Internetbased services and products. On its search engine website, an interesting button ‘I’m feeling lucky’ attracts our eyes. This feature could allow the user skip the search result page and goes directly to the first ranked page. Amazing! It saves a lot of time. The question is, when one types some keywords and presses ‘I’m feeling lucky’ button, which web page will appear? Google does a lot and comes up with excellent approaches to deal with it. In this simplified problem, let us just consider that Google assigns every web page an integer-valued relevance. The most related page will be chosen. If there is a tie, all the pages with the highest relevance are possible to be chosen. Your task is simple, given 10 web pages and their relevance. Just pick out all the possible candidates which will be served to the user when ‘I’m feeling lucky’.

Input 

The input contains multiple test cases. The number of test cases T is in the first line of the input file. For each test case, there are 10 lines, describing the web page and the relevance. Each line contains a character string without any blank characters denoting the URL of this web page and an integer Vi denoting the relevance of this web page. The length of the URL is between 1 and 100 inclusively. (1 ≤ Vi ≤ 100) 

Output 

For each test case, output several lines which are the URLs of the web pages which are possible to be chosen. The order of the URLs is the same as the input. Please look at the sample output for further information of output format.

Sample Input


www.youtube.com 1 
www.google.com 2 
www.google.com.hk 3 
www.alibaba.com 10 
www.taobao.com 5 
www.bad.com 10 
www.good.com 7 
www.fudan.edu.cn 8 
www.university.edu.cn 9 
acm.university.edu.cn 10 
www.youtube.com 1 
www.google.com 2 
www.google.com.hk 3 
www.alibaba.com 11 
www.taobao.com 5 
www.bad.com 10 
www.good.com 7 
www.fudan.edu.cn 8 
acm.university.edu.cn 9 
acm.university.edu.cn 10 

Sample Output 

Case #1: www.alibaba.com www.bad.com acm.university.edu.cn 
Case #2: www.alibaba.com

Solution
#include<stdio.h>

int main()
{
    int t, i, j, k, max, value[15];
    char url[12][105];
    while(scanf("%d",&t)==1)
    {
        for(i=1;i<=t;i++)
        {
            max=0;
            for(j=1;j<=10;j++)
            {
                scanf("%s%d",&url[j], &value[j]);
                if(value[j]>max)
                    max=value[j];
            }
            printf("Case #%d:\n",i);
            for(k=1;k<=10;k++)
            {
                if(max==value[k])
                    printf("%s\n",url[k]);
            }
        }
    }
    return 0;
}
image

Solution of 11995 - I Can Guess the Data Structure!

Problem Description
source:https://uva.onlinejudge.org/external/119/p11995.pdf

There is a bag-like data structure, supporting two operations: 

1 x      Throw an element x into the bag. 
2         Take out an element from the bag. 

Given a sequence of operations with return values, you’re going to guess the data structure. It is a stack (Last-In, First-Out), a queue (First-In, First-Out), a priority-queue (Always take out larger elements first) or something else that you can hardly imagine! 

Algorithm of 11995 - I Can Guess the Data Structure!

Problem Description Link
Algorithm:
for this problem n=number of line x=element  you can use STL stack , queue, priority_queue
and when get 1 insert data each STL and increase  value for each STL variable(i.e s, q,p)
when get 2 chaeck
    1. for stack check stack not empty and stack top element = x 
        if condition true the pop from stack.
    2. for que  check queue not empty and queue front = x
        if condition true the pop from queue.
    3. for priority queue check priority_queue not empty and  priority_queue top=x
        if condition true the pop from priority_queue.
for each pop increase value that data(ie. s for stack pop ..)
image

Solution of 11984 - A Change in Thermal Unit

Problem Description
source:https://uva.onlinejudge.org/external/119/p11984.html

Measuring temperature and temperature differences are common task in many research and applications. Unfortunately, there exists more than one unit of measuring temperatures. This introduces a lot of confusion at times. Two popular units of measurements are Celsius(C) and Fahrenheit (F). The conversion of F from C is given by the formula

                             F = (9 / 5) * C + 32

In this problem, you will be given an initial temperature in C and an increase in temperature in F. You would have to calculate the new temperature in C.

image

Solution of 11970 - Lucky Numbers

Problem Description
source:https://uva.onlinejudge.org/external/119/p11970.html

Every person has its own numbers that he considers lucky. Usually the numbers are fixed like 3 or 7 and do not depend on anything. This lucky number model seems to be very primitive for John, so he decided to upgrade it for his own use. Maybe more complex model will bring more luck to him? John has added a dependency for lucky numbers on specific integer N (for example N can be ordinal number of day in year or some other meaning). For each N John considers some number X lucky if and only if fraction X/√( N − X) value is integer and greater than zero. 

Input 

The number of tests T (T ≤ 100) is given on the first line. T lines follow, each of them contains one integer N (1 ≤ N ≤ 109 ) described above. 

image

Solution of 11965 - Extra Spaces

Problem Description
source:https://uva.onlinejudge.org/external/119/p11965.html

In programming multiple whitespaces are used to only to make code more readable, so mostly all programming languages totally ignore multiple spaces in code (except for some esoteric ones). In general there are different types of whitespace characters: space itself, tabs, newline symbol, various control characters, etc. Tabs and spaces bring one or the biggest holywar to a programmers world as there is no common rule what to use for code indentation — tab or space characters. In this holywar you stand for tab side and your project code convention requires to use only them for code indentation. However you have recently spotted that someone is using space characters instead of it. Four spaces and tab character look the same in our text editor, so you have decided to write a parser that will change all consequent space characters to one. After that you would be able to determine amount of corrupted code.

image

Solution of 11946 - Code Number

Problem Description
source:https://uva.onlinejudge.org/external/119/p11946.html

Adrian and Maria are relatives that live in different towns. As they inhabit a rural area, it is very difficult for them to keep in touch. One way they found to overcome their communication problem was to send a line through their parents that used to visit each other.

 The point is that Adrian and Maria did not want that their parents read their messages, and they decided to create a secret code for the messages. The code is not very sophisticated, but you should keep in mind Adrian and Maria are just children. 

In general, the meaning of a message is based on changing some letters by numbers. Each message is composed by several lines using uppercase letters of the English alphabet, space and punctuation symbols: dot and comma. The letters that are changed by numbers can be seen in the following example; this change is the same for all messages between Adrian and Maria. 

Message in “Code Number”:

image

Solution of 11942 - Lumberjack Sequencing

Problem Description
source:https://uva.onlinejudge.org/external/119/p11942.html

Another tale of lumberjacks?. Let see . . . 

The lumberjacks are rude, bearded workers, while foremen tend to be bossy and simpleminded. The foremen like to harass the lumberjacks by making them line up in groups of ten, ordered by the length of their beards. The lumberjacks, being of different physical heights, vary their arrangements to confuse the foremen. Therefore, the foremen must actually measure the beards in centimeters to see if everyone is lined up in order. 

Your task is to write a program to assist the foremen in determining whether or not the lumberjacks are lined up properly, either from shortest to longest beard or from longest to shortest. 

Input 

image

Algorithm of 11936 - The Lazy Lumberjacks

Algorithm:

This is a geometric problem . you  can solve this problem easily . you can follow this stapes
1. At first you need three value for three sides (ie. a, b, c)
     N.B.: three sides can formed a triangle if and only if third side is greater than summation of    other two side   .
     where third side is largest value among three sides value .(i.e.:  5, 9, 6 where third side is 9).
2. if possible formed a triangle then you need print
     OK
3. Otherwise print
         Wrong!!
image

Solution of 11936 - The Lazy Lumberjacks

Problem Description
source:https://uva.onlinejudge.org/external/119/11936.html

Once upon a time in a far, far away forest, there was a team of lazy lumberjacks. Since they were too lazy to cut trees, they were always figuring out ways to sneak out of work. Their foreman, on the other side, was always trying to put them all to work. 
After a lot of discussions the foreman and the lumberjacks came to an agreement: they will work, but only if the area of the forest assigned to each one was a triangle. If it was any other shape they will be free not to work that week. The idea was to give each lumberjack three numbers representing the length of each of the triangles side. If the numbers were correct and form a triangle, the lumberjacks had to work, else, they were free to leave and not work. 
Since our lumberjacks are as cunning as they are lazy, they convince the foreman to let them determine the surface and the site in the forest were they will work. As a result, the lumberjacks keep passing the foreman sets of numbers that could not form the sides of a triangle. After a while, the foreman began to suspect and decide to write a program that validates the input of each lumberjack. Now when the lumberjacks decide to pass wrong numbers they get a fine of $1000.00 (more than a day’s salary). Your job is to write the program that the foreman has to use to determine if the numbers (all integers) passed by the lumberjacks can be the sides of a triangle. If they can, you have to print ‘OK’ else you have to print ‘Wrong!!

image

Solution of 11934 - Magic Formula

Problem Description
source: https://uva.onlinejudge.org/external/119/p11934.html

You are given a quadratic function, 
                           f(x) = ax2 + bx + c 
You are also given a divisor d and a limit L. How many of the function values f(0), f(1), . . . , f(L) are divisible by d? 

Input

 Input consists of a number of test cases. Each test case consists of a single line containing the numbers a b c d L (−1000 ≤ a, b, c ≤ 1000, 1 < d < 1000000, 0 ≤ L < 1000). 
Input is terminated by a line containing ‘0 0 0 0 0’ which should not be processed. 

SOlution of 11877 - The Coco-Cola Store

Problem Description
source:https://uva.onlinejudge.org/external/118/11877.html

Once upon a time, there is a special coco-cola store. If you return three empty bottles to the shop, you’ll get a full bottle of coco-cola to drink. If you have n empty bottles right in your hand, how many full bottles of coco-cola can you drink? 

Input 

There will be at most 10 test cases, each containing a single line with an integer n (1 ≤ n ≤ 100). The input terminates with n = 0, which should not be processed. 

image

Algorithm of 11876 - N + NOD (N)

Problem Description Link
Algorithm:
To solve this problem you should generate divisor and NOD sequence before get input otherwise you may get time limit exit
NOD value sequence generate by this produce :
Nodvalue[i]=Nodvalue[i-1]+dividor[Nodvalue[i-1]];

when you get input just find the index of value A and B
and difference of index B and A is O/P.
you can use binarry search for find speedy  index of A and B .
image

Solution of 11876 - N + NOD (N)

Problem Description
source:https://uva.onlinejudge.org/external/118/11876.uva

Consider an integer sequence N where, 

N0 = 1 
Ni = Ni−1 + NOD(Ni−1) for i > 0 
        Here, NOD(x) = number of divisors of x. 
        So the first few terms of this sequence are 1 2 4 7 9 12 18 ... 

Given two integers A and B, find out the number of integers in the above sequence that lies within the range [A, B]. 

Solution of 11875 - Brick Game

Problem Description
source:https://uva.onlinejudge.org/external/118/11875.html

There is a village in Bangladesh, where brick game is very popular. Brick game is a team game. Each team consists of odd number of players. Number of players must be greater than 1 but cannot be greater than 10. Age of each player must be within 11 and 20. No two players can have the same age. There is a captain for each team. The communication gap between two players depends on their age difference, i.e. the communication gap is larger if the age difference is larger. Hence they select the captain of a team in such a way so that the number of players in the team who are younger than that captain is equal to the number of players who are older than that captain. Ages of all members of the team are provided. You have to determine the age of the captain.

image

Solution of 11805 - Bafana Bafana

Problem Description
source:https://uva.onlinejudge.org/external/118/11805.html

Team practice is very important not only for programming contest but also for football. By team practice players can learn cooperating with team mates. For playing as a team improvement of passing skill is very important. Passing is a great way of getting the ball upfield and reduces the risk of giving the ball away.
   Carlos Alberto Parreira, the coach of Bafana Bafana, also wants his players to practice passing a lot. That’s why, while in the training camp for soccer world cup 2010, every day he asks all of the players who are present in practice to stand in a circle and practice passing. If N players are in practice, he gives each of the players a distinct number from 1 to N, and asks them to stand sequentially, so that player 2 will stand in right side of player 1 and player 3 will stand in right side of player 2, and so on. As they are in a circle, player 1 will stand right to player N.
   The rule of passing practice is, Parreira will give the ball to player K, and practice will start. Practice will come to an end after P passes. In each pass, a player will give the ball to his partner who is in his immediate right side. After P passes, the player who owns the ball at that moment will give the ball back to Parreira.
    Parreira wants to be ensured that his players practice according the rule. So he wants a program which will tell him which player will give him the ball back. So after taking the ball from the same person he can be happy that, the players play according to the rules. Otherwise he will ask them to start from beginning.

image

Algorithm of 11799 - Horror Dash

Problem Description Link
Algorithm:
In this problem you are to find out the minimum speed
that the clown must maintain so as not to get caught
even if they keep on running forever.

so if you can find the maximum speed then it is the
minimum speed to continue the race
so
1. get input t(test case)
2. get input n(number of students)
3. speed of each students (speed)
    if(speed>max)
        max=speed;
4. print the max.
image

Solution of 11799 - Horror Dash

Problem Description
source:https://uva.onlinejudge.org/external/117/p11799.html

It is that time of the year again! Colorful balloons and brightly colored banners spread out over your entire neighborhood for just this one occasion. It is the annual clown’s festival at your local school. For the first time in their lives, students from the school try their hands at being the best clown ever. Some walk on long poles, others try to keep a crowd laughing for the day with stage comedy, while others still try out their first juggling act — some ‘master clowns’ even teach these juggling tricks to visitors at the festival. 

As part of the festival, there is a unique event known as the “Horror Dash”. At this event, N (1 ≤ N ≤ 100) students dressed in the scariest costumes possible start out in a race to catch a poor clown running on the same track. The clown trips over, loses his mind, and does all sorts of comical acts all while being chased round and round on the track. To keep the event running for as long as possible, the clown must run fast enough not to be caught by any of the scary creatures. However, to keep the audience on the edge of their seats, the clown must not run too fast either. This is where you are to help. Given the speed of every scary creature, you are to find out the minimum speed that the clown must maintain so as not to get caught even if they keep on running forever.

Solution of 11777 - Automate the Grades

Problem Description
source:https://uva.onlinejudge.org/external/117/p11777.html

The teachers of “Anguri Begam Uccha Biddalya”, a school located in the western region of Sylhet, currently follows a manual system for grading their students. The manual process is very time consuming and error prone. From the next semester they have decided to purchase some computers so that the whole grading process can be automated. And yes, you guessed it — they have hired you to write a program that will do the job. 

The grading of each course is based on the following weighted scale: 

• Term 1 — 20% 
• Term 2 — 20% 
• Final — 30% 
• Attendance — 10% 
• Class — Tests 20% 

The letter grades are given based on the total marks obtained by a student and is shown below: 

• A ≥ 90% 
• B ≥ 80% & ¡ 90% 
• C ≥ 70% & ¡ 80% 
• D ≥ 60% & ¡ 70% 
• F < 60% 

Solution of 11764 - Jumping Mario

Problem Descriptio
source:https://uva.onlinejudge.org/external/117/11764.html

Mario is in the final castle. He now needs to jump over few walls and then enter the Koopa’s Chamber where he has to defeat the monster in order to save the princess. For this problem, we are only concerned with the “jumping over the wall” part. You will be given the heights of N walls from left to right. Mario is currently standing on the first wall. He has to jump to the adjacent walls one after another until he reaches the last one. That means, he will make (N − 1) jumps. A high jump is one where Mario has to jump to a taller wall, and similarly, a low jump is one where Mario has to jump to a shorter wall. Can you find out the total number of high jumps and low jumps Mario has to make?

Algorithm of 11743 - Credit Check

Problem Description Link
Algorithm:
This is a simple you just see the following example
For example, using the number 5181 2710 9900 0012:

   1.  Double the appropriate digits (5181 2710 9900 0012) to obtain the values:(5*2) 10,  (8*2)16,  (2*2)4, (1*2) 2, (9*2) 18, (0*2) 0, (0*2) 0, (1*2)2.
   2.  (10)->(1+0) , (16)->(1+6), 4, 2, (18)->(1+8), 0, 0, 2
    Add up the digits of these values to get (1+0) + (1+6) + 4 + 2 + (1+8) + 0 + 0 + 2 = 25. The sum of the undoubled digits is 1+1+7+0+9+0+0+2 = 20, so the total is 20+25=45.
   3.  45 does not end in a 0, so this credit card number is invalid.
image

Solution of 11743 - Credit Check

Problem Description
source:https://uva.onlinejudge.org/external/117/p11743.html



These days, it has become commonplace to make purchases over the internet using a credit card. However, because credit card numbers are relatively long, it is easy to make a mistake while typing them in. In order to quickly identify errors like typos, most e-commerce websites use a checksum algorithm to verify credit card numbers. One popular checksum algorithm is the Luhn algorithm, which can detect any single-digit error as well as many common multiple-digit errors: 

Algorithm of 11727 - Cost Cutting

Problem Description Link
ALgorithm:
This problem determine the medium salary that not lowest or highest.
let a, b and c are salaries and avg is medium salary that
we determine.
1. get input testcase
2. get input a, b, c
3.
           if((b>a and b<c)||(b<a and b>c))
                avg=b;
            else if((c>a and c<b)||(c<a and c>b))
                avg=c;
            else
                avg=a;
4.print the avg.
image

Solution of 11727 - Cost Cutting

Problem Description
source:https://uva.onlinejudge.org/external/117/11727.html



Company XYZ have been badly hit by recession and is taking a lot of cost cutting measures. Some of these measures include giving up office space, going open source, reducing incentives, cutting on luxuries and issuing pink slips. 
They have got three (3) employees working in the accounts department and are going to lay-off two (2) of them. After a series of meetings, they have decided to dislodge the person who gets the most salary and the one who gets the least. This is usually the general trend during crisis like this. You will be given the salaries of these 3 employees working in the accounts department. You have to find out the salary of the person who survives. 

Solution of 11723 - Numbering Roads

Problem Description
source:https://uva.onlinejudge.org/external/117/p11723.html



In my country, streets dont have names, each of them are just given a number as name. These numbers are supposed to be unique but that is not always the case. The local government allocates some integers to name the roads and in many case the number of integers allocated is less that the total number of roads. In that case to make road names unique some single character suffixes are used. So roads are named as 1, 2, 3, 1A, 2B, 3C, etc. Of course the number of suffixes is also always limited to 26 (A, B, . . . , Z). For example if there are 4 roads and 2 different integers are allocated for naming then some possible assignments of names can be:

Solution of 11715 - Car

Problem Description
source: https://uva.onlinejudge.org/external/117/p11715.html

You are in a car and going at the speed of u m/s. Your acceleration a is constant. After a particular time t, your speed is v m/s and your displacement is s. Now you are given some (not all of them) values for the given variables. And you have to find the missing parameters. 

Input 

The input file may contain multiple test cases. Each test case can be one of the 

1 u v t 
2 u v a 
3 u a s 
4 v a s 

image

Solution of 11713 - Abstract Names

Problem Description
source:https://uva.onlinejudge.org/external/117/11713.html

Some of you may have noticed that in certain computer games, particularly the ones based on sports, the spelling of names are mutated so that they are not an exact duplicate of the real entity. This is done to avoid hassles of taking permission from each player as well as any patent issues. In this problem, you will be given a pair of names, one of which is that of a player in real life and the second found in a game. You will have to determine if the two names are same, that is the second one is obtained by mutating the first. 
Two names are considered same if they are of same length and they only vary at positions where vowels occur. That means, a name which can be obtained by replacing zero or more vowels by other vowels to obtain a new name are considered same, provided they have same length. For example, both polo and pola are same as pele but not pelet or bele. 

image

Solution of 11689 - Soda Surpler

Problem Description
source:https://uva.onlinejudge.org/external/116/11689.html


Tim is an absolutely obsessive soda drinker, he simply cannot get enough. Most annoyingly though, he almost never has any money, so his only obvious legal way to obtain more soda is to take the money he gets when he recycles empty soda bottles to buy new ones. In addition to the empty bottles resulting from his own consumption he sometimes find empty bottles in the street. One day he was extra thirsty, so he actually drank sodas until he couldn’t afford a new one.

Solution of 11677 - Alarm Clock

Problem Description
source:https://uva.onlinejudge.org/external/116/11677.html

Daniela is a nurse in a large hospital, which causes her working shifts to constantly change. To make it worse, she has deep sleep, and a difficult time to wake up using alarm clocks. 
       Recently she got a digital clock as a gift, with several different options of alarm sounds, and she has hope that it might help solve her problem. But, lately, she’s been very tired and want to enjoy every single moment of rest. So she carries her new clock to every place she goes, and whenever she has some spare time, she tries to sleep, setting her alarm clock to the time when she needs to wake up. But, with so much anxiety to sleep, she ends up with some difficulty to fall asleep and enjoy some rest.
       A problem that has been tormenting her is to know how many minutes of sleep she would have if she felt asleep immediately and woken up when the alarm clock ringed. But she is not very good with numbers, and asked you for help to write a program that, given the current time and the alarm time, find out the number of minutes she could sleep.
image

Algorithm of 11636 - Hello World!

Problem Description Link
Algorithm:
This is a simple problem just read carefully.
however you can follow this technique.
when you copy the existing line and pest them you get double line means for 1 time of copy you get double line.
1. get input n
2. let line=1; and copy=0
3. while line less than n
    line+=lene;
    copy+=1;
4. print the copy
image

Solution of 11636 - Hello World!

Problem Description
source:http://uva.onlinejudge.org/external/116/11636.html

When you first made the computer to print the sentence “Hello World!”, you felt so happy, not knowing how complex and interesting the world of programming and algorithm will turn out to be. Then you did not know anything about loops, so to print 7 lines of “Hello World!”, you just had to copy and paste some lines. If you were intelligent enough, you could make a code that prints “Hello World!” 7 times, using just 3 paste commands. Note that we are not interested about the number of copy commands required. A simple program that prints “Hello World!” is shown in Figure 1. By copying the single print statement and pasting it we get a program that prints two “Hello World!” lines. Then copying these two print statements and pasting them, we get a program that prints four “Hello World!” lines. Then copying three of these four statements and pasting them we can get a program that prints seven “Hello World!” lines (Figure 4). So three pastes commands are needed in total and Of course you are not allowed to delete any line after pasting. Given the number of “Hello World!” lines you need to print, you will have to find out the minimum number of pastes required to make that program from the origin program shown in Figure 1.

Solution of 11614 - Etruscan Warriors Never Play Chess

Problem Description
source:https://uva.onlinejudge.org/external/116/11614.html

A troop of Etruscan warriors is organized as follows. In the first row, there is only one warrior; then, the second row contains two warriors; the third row contains three warriors, and so on. In general, each row i contains i warriors. 
         We know the number of Etruscan warriors of a given troop. You have to compute the number of rows in which they are organized. 
        Please note that there may be some remaining warriors (this could happen if they are not enough to form the next row). For example, 3 warriors are organized in 2 rows. With 6 warriors you can form 3 rows; but you can also form 3 rows with 7, 8 or 9 warriors. 

image