Posts

Showing posts from September, 2017

Codevita 2017 Round-1 Problem-C

Problem: CodeVita 2017 Round 1 Problem -C (download from below ...  if any problem in downloading then comment)  http://s000.tinyupload.com/?file_id=52952119059621072275 Solution : /* Author: Krishankant Ray * CodeVita 2017 Round 1 */ #include<iostream> #include<vector> using namespace std; int main () { int d,k = 0 ; string arr; cin >> d; cin >> arr; int n = arr.length(); char R[n]; for ( int f = 0 ; f < n; ) { R[f] = arr[k ++ ]; f += (( 2 * d) - 2 ); } for ( int i = 1 ; i < d - 1 ;i ++ ) { R[i] = arr[k ++ ]; for ( int j = i; j < n;) { j += (( 2 * d) - 2 - ( 2 * i)); R[j] = arr[k ++ ]; j += (( 2 * i)); if (j < n) R[j] = arr[k ++ ]; } } for ( int l = d - 1 ; l < n;l += (( 2 * d) - 2 )) { R[l] = arr[k ++ ];

CodeVita 2017 Round-1 Problem-B

Problem : Concatenating primes If you like numbers, you may have been fascinated by prime numbers. Sometimes we obtain by concatenating two primes. For example, concatenating 2 and 3, we obtain the prime 23. The aim is to find all such distinct "concatenated primes" that could be obtained by concatenating primes ≤ a given integer N.   Input Format:   Integer N Output Format: M, the number of distinct primes that could be obtained by concatenating two primes ≤ N Constraints: N ≤ 70 Example 1 Input 10 Output 4 Explanations The primes ≤ 10 are 2, 3, 5, 7. These can be used to form the following concatenated numbers: 22, 23, 25, 27, 32, 33, 35, 37, 52, 53, 55, 57, 72, 73, 75, 77. Of these, there are four primes: 23 37 53 and 73. Hence the output is 4. Example 2 Input 20 Output 17 Explanation The prime numbers up to 20 are 2 3 5 7 11 13 17 and 19. Concatenating these two at a time in all possible ways, we get the following numbers: 22 23 25 27 211 213 217 219 32 33

TCS-Codevita 2017 Round-1 Problem-A

Problem : Mountain peak sequence Consider the first three natural numbers 1, 2, 3. These can be arranged in the following ways: 2, 3, 1 and 1, 3, 2. Inboth of these arrangements, the numbers increase to a certain point and then decrease. A sequence with this property is called a "mountain peak sequence". Given an integer N, write a program to find the remainder of mountain peak arrangements that can be obtained by rearranging the numbers 1, 2, ...., N. Input Format: One line containing the integer N Output Format: An integer m, giving the remainder of the number of mountain peak arrangements that could be obtained from 1, 2, ...., N is divide by Mod Constraints : Mod = 109+7 N ≤ 109 Example 1 Input 3 Output 2 Explanation There are two such arrangements: 1, 3, 2 and 2, 3, 1 Example 2 Input 4 Output 6 Explanation The six arrangements are (1, 2, 4, 3), (1,3,4,2), (1,4,3,2), (2,3,4,1), (2,4,3,1), (3,4,2,1) Note: Please do not use packag

Codechef SEPT17 CookOff - Subsequence Equality Problem Code: LIKECS01

Problem: (Link:  https://www.codechef.com/problems/LIKECS01 ) Chef Tobby is playing a rapid fire with Bhuvan. He gives Bhuvan a string S and each time, Bhuvan has to guess whether there exists 2 equal subsequences in the string or not. Bhuvan got a perfect score in the game with Chef Tobby. However, Chef Tobby has now asked Bhuvan to write a program that will do this automatically given a string S . Bhuvan is an intelligent man but he does not know how to write a code. Can you help him? Find two different subsequences such that they are equal in their value, more formally, find two sequences of indices (a 1 , a 2 , ..., a k-1 , a k ) and (b 1 , b 2 , ..., b k-1 , b k ) such that: 1≤ a i , b i ≤ |S| a i < a i+1 for all valid i b i < b i+1 for all valid i S a i = S b i for all valid i there exist at least one i such that a i is not equal to b i Input section The first line contains T , the number of test cases. Each of the next T lines contain one

Codechef - Courses in an university - Problem Code: UNICOURS

Problem There are n courses in a university being offered. These courses are numbered from 1 to n in the increasing order of their difficulty. For each course, you can have some courses as prerequisites. The prerequisite courses for a course should be of lower difficulty than it. You are given an array a of size n , where a i denotes that there should be at least a i prerequisite courses for i-th course. The university wants to estimate the efficiency of the allocation of prerequisites of courses by maximizing the number of courses that are not prerequisites for any other course. Find out what's the maximum such number of courses possible. It is guaranteed that a i < i, thus making sure that it is possible to allocate the prerequisites for each of the course. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains an integer n .

Codechef MAY17 chef and his daily routine ( code: CHEFROUT )

Problem : https://www.codechef.com/problems/CHEFROUT Chef's daily routine is very simple. He starts his day with cooking food, then he eats the food and finally proceeds for sleeping thus ending his day. Chef carries a robot as his personal assistant whose job is to log the activities of Chef at various instants during the day. Today it recorded activities that Chef was doing at N different instants. These instances are recorded in chronological order (in increasing order of time). This log is provided to you in form of a string s of length N, consisting of characters 'C', 'E' and 'S'. If s [i] = 'C', then it means that at the i-th instant Chef was cooking, 'E' denoting he was eating and 'S' means he was sleeping. You have to tell whether the record log made by the robot could possibly be correct or not. Input The first line of the input contains an integer T denoting the number of test cases. The description of T te

ProjectEuler -01 Multiple of 3 and 5

PROBLEM :  https://www.hackerrank.com/contests/projecteuler/challenges/euler001 If we list all the natural numbers below that are multiples of or , we get and . The sum of these multiples is . Find the sum of all the multiples of or below . Input Format First line contains that denotes the number of test cases. This is followed by lines, each containing an integer, . Constraints Output Format For each test case, print an integer that denotes the sum of all the multiples of or below . Sample Input 0 2 10 100 Sample Output 0 23 2318 Explanation 0 For , if we list all the natural numbers below that are multiples of or , we get and . The sum of these multiples is . Similarly for , we get . Solution : #include <iostream> using namespace std; int main () { int t; cin >> t; while (t -- ) { long long int n, x, y, z, m3, m5, m15, sum = 0 ;

CodeChef SEPT17 Sereja and Commands (code: SEACO)

Problem: Little Chef and Sum  https://www.codechef.com/SEPT17/problems/SEACO Sereja has an array A consisting of n integers. Initially, all the elements of array are zero. Sereja writes down m commands on a piece of a paper. The commands are enumerated from 1 to m . These commands can be of the following two types of commands: l r (l ≤ l ≤ r ≤ n) — Increase all elements of the array by one, whose indices belongs to the range [l, r] l r (1 ≤ l ≤ r ≤ m) — Execute all the commands whose indices are in the range [l, r] . It's guaranteed that r is strictly less than the enumeration/number of the current command. Can you please help Sereja in executing all the commands written on this piece of paper. Input  The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line contains integers n and m . Next m lines contain Sereja's commands in the format, described in statement: t ,