Codechef programming set #23
![]() |
VCS |
#37
Version Control System
Read problems statements in Mandarin Chinese and Russian as well.
A version control system(VCS) is a repository of files, often the files for the source code of computer programs, with monitored access. Every change made to the source is tracked, along with who made the change, why they made it, and references to problems fixed, or enhancements introduced, by the change.
Version control systems are essential for any form of distributed, collaborative development. Whether it is the history of a wiki page or large software development project, the ability to track each change as it was made, and to reverse changes when necessary can make all the difference between a well managed and controlled process and an uncontrolled ‘first come, first served’ system. It can also serve as a mechanism for due diligence for software projects.
In this problem we'll consider a simplified model of a development project. Let's suppose, that there are N source files in the project. All the source files are distinct and numbered from 1 to N.
A VCS, that is used for maintaining the project, contains two sequences of source files. The first sequence contains the source files, that are ignored by the VCS. If a source file is not in the first sequence, then it's considered to be unignored. The second sequence contains the source files, that are tracked by the VCS. If a source file is not in the second sequence, then it's considered to be untracked. A source file can either be or not be in any of these two sequences.
Your task is to calculate two values: the number of source files of the project, that are both tracked and ignored, and the number of source files of the project, that are both untracked and unignored.
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 the test case description contains three integers N, M and K denoting the number of source files in the project, the number of ignored source files and the number of tracked source files.
The second line contains M distinct integers denoting the sequence A of ignored source files. The sequence is strictly increasing.
The third line contains K distinct integers denoting the sequence B of tracked source files. The sequence is strictly increasing.
Output
For each test case, output a single line containing two integers: the number of the source files, that are both tracked and ignored, and the number of the source files, that are both untracked and unignored.
Constraints
- 1 ≤ T ≤ 100
- 1 ≤ M, K ≤ N ≤ 100
- 1 ≤ A1 < A2 < ... < AM ≤ N
- 1 ≤ B1 < B2 < ... < BK ≤ N
Example
Input: 2 7 4 6 1 4 6 7 1 2 3 4 6 7 4 2 2 1 4 3 4 Output: 4 1 1 1
Explanation
In the first test case, the source files {1, 4, 6, 7} are both tracked and ignored, the source file {5} is both untracked and unignored.
In the second test case, the source file {4} is both tracked and ignored, the source file {2} is both untracked and unignored.
My Solution:- import java.util.*;
- import java.util.stream.IntStream;
- class VCS {
- int b=in.nextInt();
- while(b-->0)
- {
- int count =0,count1=0;
- int n=in.nextInt();
- int m=in.nextInt();
- int k=in.nextInt();
- int arrn[]=new int[n];
- int arrk[]=new int[n];
- for(int i=0;i<m;i++)
- arrn[i]=in.nextInt();
- for(int j=0;j<k;j++)
- arrk[j]=in.nextInt();
- for(int p=1;p<=n;p++)
- {
- int op=p;
- if(IntStream.of(arrn).anyMatch(x -> x == op)&&IntStream.of(arrk).anyMatch(x -> x == op))
- count++;
- if(!(IntStream.of(arrn).anyMatch(x -> x == op))&&!(IntStream.of(arrk).anyMatch(x -> x == op)))
- count1++;
- }
- }
- }
- }
- #38
Read problems statements in Mandarin Chinese and Russian as well.
There are 100 houses located on a straight line. The first house is numbered 1 and the last one is numbered 100. Some M houses out of these 100 are occupied by cops.Thief Devu has just stolen PeePee's bag and is looking for a house to hide in.PeePee uses fast 4G Internet and sends the message to all the cops that a thief named Devu has just stolen her bag and ran into some house.Devu knows that the cops run at a maximum speed of x houses per minute in a straight line and they will search for a maximum of y minutes. Devu wants to know how many houses are safe for him to escape from the cops. Help him in getting this information.Input
First line contains T, the number of test cases to follow.First line of each test case contains 3 space separated integers: M, x and y.For each test case, the second line contains M space separated integers which represent the house numbers where the cops are residing.Output
For each test case, output a single line containing the number of houses which are safe to hide from cops.Constraints
- 1 ≤ T ≤ 104
- 1 ≤ x, y, M ≤ 10
Example
Input: 3 4 7 8 12 52 56 8 2 10 2 21 75 2 5 8 10 51 Output: 0 18 9
Explanation
Example 1 : Cops in house 12 can cover houses 1 to 68, and cops in house 52 can cover the rest of the houses. So, there is no safe house.Example 2 : Cops in house 21 can cover houses 1 to 41, and cops in house 75 can cover houses 55 to 95, leaving houses numbered 42 to 54, and 96 to 100 safe. So, in total 18 houses are safe.- My Soution:
- import java.util.Scanner;
- class COPS {
- {
- int b=in.nextInt();
- while(b-->0)
- {
- int count =0;
- int t=in.nextInt();
- int x=in.nextInt();
- int y=in.nextInt();
- int mul=x*y;
- int arr[] = new int[t];
- int arr2[] = new int[101];
- String str = "";
- for(int i=1;i<101;i++)
- {arr2[i]=1;}
- for(int i=0;i<t;i++)
- arr[i]=in.nextInt();
- for(int k=0;k<t;k++)
- {
- int negative =arr[k]-mul;
- int positive =arr[k]+mul;
- for(int nu=negative;nu<=positive;nu++)
- {
- arr2[nu]=0;
- }
- }
- for(int i=1;i<101;i++){
- if(arr2[i]==1){
- count++;
- }
- }
- }
- }
- }
Cops and the Thief Devu
#39
- The first line of input contains a single integer T, denoting the number of test cases.
- The first and only line of each test case contains a string s.
- For each test case, output a single line containing an integer — the minimum number of flips required.
- 1 ≤ T ≤ 100
- 1 ≤ n ≤ 100, where n denotes to the length of the string s.
- import java.util.Scanner;
- class colors {
- {
- int b=in.nextInt();
- while(b-->0)
- {
- n=n+"l";
- int amber=n.split("a").length;
- int brass=n.split("b").length;
- }
- }
- }
Malvika is peculiar about color of balloons
All submissions for this problem are available.
Little Malvika is very peculiar about colors. On her birthday, her mom wanted to buy balloons for decorating the house. So she asked her about her color preferences. The sophisticated little person that Malvika is, she likes only two colors — amber and brass. Her mom bought n balloons, each of which was either amber or brass in color. You are provided this information in a string s consisting of characters 'a' and 'b' only, where 'a' denotes that the balloon is amber, where 'b' denotes it being brass colored.
When Malvika saw the balloons, she was furious with anger as she wanted all the balloons of the same color. In her anger, she painted some of the balloons with the opposite color (i.e., she painted some amber ones brass and vice versa) to make all balloons appear to be the same color. As she was very angry, it took her a lot of time to do this, but you can probably show her the right way of doing so, thereby teaching her a lesson to remain calm in difficult situations, by finding out the minimum number of balloons needed to be painted in order to make all of them the same color.
Input
Output
Constraints
Example
Input: 3 ab bb baaba Output: 1 0 2
Explanation
In the first example, you can change amber to brass or brass to amber. In both the cases, both the balloons will have same colors. So, you will need to paint 1 balloon. So the answer is 1.
In the second example, As the color of all the balloons is already the same, you don't need to paint any of them. So, the answer is 0.
Good post.
ReplyDelete