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