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.