Daa Lab Record Final
Daa Lab Record Final
VADAPALANI
CHENNAI-600026
Submitted By:
Register No : RA2011027040016
Year : II year
July 2022
This is to certify that bonafide record work for 18CSC204J- Design and Analysis of
Year B.Tech degree in Computer Science and Engineering, in SRM Institute of Science
InternalExaminer-I InternalExaminer-II
EXP. EXPERIMENT SIGN
DATE
NO NAME
10
Question 1
Problem Description:
Trapped by a river and racing against time, our fearless heroes need to quickly cross it in order to stop mom
from placing the wrong pizza order. (Funny story, turns out Greg was only joking about the anchovies).
Luckily, our heroes have found a ramp on their side of the river (what could go wrong?).
Input Format:
Line 2: The length of the ramp (in meters, always a whole 32-bit integer)
Line 3: The acceleration rate of the vehicle (in meters/second squared, floating point decimal of max size
2147483647.0)
Line 4: The width of the river (in meters, floating point decimal of max size 2147483647.0)
Output Format:
Using that information, calculate the horizontal speed (rounded to the nearest hundredth) the vehicle will be
going when it runs out of ramp, and then use that to calculate how much horizontal distance (rounded to the
nearest tenth) your vehicle will be able to cover (formulas in the discussion section) and output the results of
your ramp jumping!
< the width of the river minus 5 meters, add SPLASH! to your output
>= river-width minus 5 meters AND <= river-width, add BARELY MADE IT!
Explanation:
You will first need to figure out at what time the vehicle will run out of ramp if accelerating at the constant
rate given in the input. Solve for that time (in seconds) using:
time1=sqrt(2.0*ramp1/rate1);
Once you have that time, plug that into the following formula to solve for the rate of speed the vehicle will be
traveling at the moment it runs out of ramp:
speed1=time1*rate1;
Now, with those 2 pieces of key information you can calculate the distance the vehicle will be be able to
cover when launched diagonally to cross the river (under ideal conditions):
distance=speed1*speed1/9.805;
So, in our test case 1, given a Motorcycle using a 100 meter long ramp, with a constant acceleration rate of
30m/s, we will get: * time1 = 2.58s until it reaches the end of the ramp * speed1 = 77.46m/s rate of speed
when it leaves the ramp * 257.8 meters distance traveled
Disclaimer We are aware that this isn't fully accurate according to physics -- in the universe of this problem,
the equations given are correct, and all that you need.
Program Code:
#include <bits/stdc++.h>
int main()
{
string str;
int ramp1;
double rate1,wr;
getline(cin,str);
cin>>ramp1>>rate1>>wr;
double time1,speed1,dist1;
time1=sqrt(2.0*ramp1/rate1);
speed1=time1*rate1;
dist1=speed1*speed1/9.805;
cout<<"SPLASH!";
else if(dist1>wr)
cout<<"LIKE A BOSS!";
else
return 0;
Question 2
Problem Description:
Inspector Gadget just installed new springs in his feet and they do not feel like they should, making it where
he cannot stop! However the Inspector cannot do the math while stopping himself from crashing into things.
Using Hooke's Law, F = -kx, please help him find out the F, k, or x value as he requests it.
Input Format:
You will receive 3 lines of input. Each line will start with the variable (capital letters only) then the value of
that variable. The value will always be a decimal number between 0 and 10,000 (or a question mark).
Output Format:
You should output the variable, a space, then the value you found for it. Round the output to the nearest
hundredths place.
Explanation:
The missing data that you need to find will be shown as a '?' instead of a number. You will always receive 3
lines and the variables will always be in the same order, F, K, then X. There will always be 1 "?" and the "?"
will not always be after the same variable.
Program Code:
#include<bits/stdc++.h>
int main()
{
string s1,s2,s3,s4,s5,s6;
cin>>s1>>s2>>s3>>s4>>s5>>s6;
float a,b,c;
if(s2=="?"){
b=stof(s4);
c=stof(s6);
cout<<"F "<<fixed<<setprecision(2)<<(-b)*c;
else if(s4=="?"){
a=stof(s2);
c=stof(s6);
cout<<"K "<<fixed<<setprecision(2)<<a/(-c);
}
else
{
a=stof(s2);
b=stof(s4);
cout<<"X "<<fixed<<setprecision(2)<<a/(-b);
}
return 0;
Question 3
Problem Description:
Archana wants to decorate his house by balloons. She plans to buy exactly M ones. She can only buy them
from Grace Super Market. There are only two kind of balloons available in that shop. The shop is very
different. If you buy 'X' balloons of kind 1 then you must pay C x X^2 and D x Y^2 if you buy balloons of
kind 2.
Please help Archana buys exactly M balloons that minimizes amount she pays.
Constraints:
1 <= T <=10^5
Input Format:
Each of test case is described in a single line containing three space-separated integers M, C, D.
Output Format:
Please help Archana buys exactly M balloons that minimizes amount she pays.
Program Code:
#include <bits/stdc++.h>
string z = "while(M>0)";
return c * x * x + d * y * y;
}
int main(){
int t,m,c,d;
cin>>t;
while(t--){
cin>>m>>c>>d;
}
}
Question 4
Problem Description:
Surya and Karthi like to pool their cash and go to the cake shop. They always choose two different colors and
they spend all of their cash.
Given a list of costs for the colors of cake, select the two that will cost all of the cash they have.
Constraints:
1 <= t <= 50
Input Format:
The first line contains an integer, t, the number of visits to the cake shop. The next 't' sets of lines each
describe a visit.
'n' space-separated integers denoting the cost of each color: cost[cost[1], cost[2],...cost[n]].
Note: The index within the cost array represents the color of the cake purchased.
Output Format:
Given a list of costs for the colors of cake, select the two that will cost all of the cash they have.
Program Code:
#include <iostream>
int main()
{
if(0) cout<<"for(i=0;i<l-1;i++)";
int t;
cin>>t;
for(int k=0;k<t;k++){
int m,l;
cin>>m;
cin>>l;
int cost[l];
int i;
for(i=0;i<l;i++){
cin>>cost[i];
for(int i=1;i<l;i++){
if(cost[0]+cost[i]==m){
cout<<1<<" "<<i+1<<"\n";
}
return 0;
Question 6
Problem Description:
In the following figure, you can see a rectangular plastic sheet. The width of the plastic sheet is W, length of
the plastic sheet is L and thickness is zero. Four (x*x) squares are cut from the four corners of the plastic
sheet shown by the black dotted lines. Then the plastic sheet is folded along the red lines to make a box
without a cover.
Given the width and height of the box, you will have to find the maximum volume of the box you can make
for any value of x.
Constraints:
1 ≤ T ≤ 200
Input Format:
Each case starts with a line containing two real numbers L and W.
Output Format:
Print the output in a separate lines contains to find the maximum volume of the box that can be made.
Program Code:
#include<bits/stdc++.h>
void solve()
{
cout<<"return(l-2*x)*(b-2*x)*x;";
}
int main()
{
int tc;
double a,b,c,res,l,w,x;
scanf("%d",&tc);
while(tc--){
scanf("%lf%lf",&l,&w);
a=12.0;
b=-4.0*(l+w);
c=l*w;
x=(-b-sqrt(b*b-4.0*a*c))/(2.0*a);
res=(l-2*x)*(w-2*x)*x;
printf("%.9f\n",res);
}
return 0;
Question 7
Problem Description:
A double-square number is an integer Y which can be expressed as the sum of 2 perfect squares. For
example, 10 is a double-square because 10 = 3^2 + 1^2. Your task in this problem is, given Y, determine the
number of ways in which it can be written as the sum of two squares. For example, 10 can only be written as
3^2 + 1^2 (we don't count 1^2 + 3^2 as being different). On the other hand, 25 can be written as 5^2 + 0^2 or
as 4^2 + 3^2.
Constraints:
0 ≤ Y ≤ 10000
1 ≤ M ≤ 100
Input Format:
You should first read an integer M, the number of test cases. The next M lines will contain M values of Y.
Output Format:
Print the output in a separate lines contains to find the number of ways to write Y as the sum of two squares.
Program Code:
#include <bits/stdc++.h>
int sumSquare(int n)
{
int res=0;
if ((i * i + j * j == n) ) {
res++;
return res;
}
int main()
{
int t;
cin>>t;
int i=1;
while(t--){
int n;
cin>>n;
i++;
}
return 0;
cout<<"for(i=0;i<=sqrt(y);i++) for(j=0;j<=i;j++)";
Question 8
Problem Description:
Given 'm' positive integers denoting an upgrading map where the width of every one bar is 1, find how much
water it can hold after Rainfall.
Example 1:
Figure 1
Explanation:
In Figure 1 upgrading map (black) is denoted by array 0 1 0 2 1 0 1 3 2 1 2 1. In this case, 6 units of water
(blue) are being holded.
Constraints:
m == height.length
Second line contains 'm' space separated integers representing the elevation map.
Output Format:
Print the output in a single line contains to find how much water it can hold after rainfall.
Program Code:
#include <bits/stdc++.h>
{
int left[n],i;
int right[n];
int water = 0;
left[0] = arr[0];
g(n)
k(n)
{
int var=min(left[i-1],right[i+1]);
}
return water;
}
int main()
{
int n,i;
cin>>n;
int arr[n];
f(n){
cin>>arr[i];
}
cout << maxWater(arr, n);
return 0;
Question 9
Problem Description:
The Allies are trying to get a message 25 meters straight up a cliff to a waiting team in the cyberpunk virtual
wars of 7702 (spoiler alert, it isn't going well). They are trying to build a contraption which will get a
messenger up the cliff to deliver the message in person (mail is expensive in the year 7702, so . . .
contraptions!)
Input Format:
You will receive, on a single line separated by spaces, the name of the contraption the Allies want to build,
the speed to which it can launch something into flight and the distance per time unit that the contraption can
launch something. You may receive the following units: MILES, KILOMETERS, YARDS, FEET, METERS,
INCHES, CENTIMETERS, HOUR, MINUTE, SECOND.
Output Format:
Calculate (using the formula given below) the height to which the contraption can launch the object (ignoring
the weight of the messenger ... being virtual, their weight is measured in photons), in meters rounded to the
nearest one hundredth. Print the name of the contraption and how high it will launch our messenger using the
format given below. If it will reach at least 25.00 meters, print afterwards: SUCCESS, else print: SPLAT.
However there is a roof over the tunnel in the cliff the Allies are aiming for starting 50 meters up. If the
messenger will be launched higher than 50 meters, print OUCH (because they will hit the roof).
Explanation:
Because the units for the acceleration of gravity are given in meters/second, and because your output needs to
be in meters, your first step needs to be converting your input rate of speed to meters/second (if it isn't
already in meters/second). After that simply square the speed and then divide by 2 times the acceleration of
gravity (9.805m/s^2) to get the maximum vertical distance the contraption will launch our brave messenger.
In this Test case 1, 1980.00 feet / minute converts to 33 feet / second. Converting feet to meters (using the
conversion of 3.28 m/f given above) then gives us 10.060975609756097560975609756098 meters / second
(don't round anything until printing your final answer.)
Program Code:
#include <bits/stdc++.h>
int main(){
string s1,s2,s3,s4;
double r;
double h;
cin>>s1>>r>>s2>>s3>>s4;
if(s2=="FEET")
r=r/3.28;
//cout<<r<<endl;
if(s2=="KILOMETERS") r=r*1000;
if(s2=="YARDS") r=r*0.9144;
if(s2=="INCHES") r=r*0.0254;
if(s2=="MILES") r=r*1609.34;
if(s4=="HOUR") r=r/3600;
if(s4=="MINUTE") r=r/60;
if(s2=="CENTIMETERS") r=r/100;
h=r*r/(2*9.805);
else cout<<"SUCCESS!";
return 0;}
Question 10
Problem Description:
Given two integers: 'b' and 'a' and 'b' is divisible by 2a, you have to first write down the first 'b' natural
numbers in the following form:
1. At first take first 'a' integers and make their sign negative
2. Then take next 'a' integers and make their sign positive
3. The next 'a' integers should have negative signs and continue this procedure until all the 'b' integers have
been assigned a sign.
Now your task is to find the summation of the numbers considering their signs.
Constraints:
1 ≤ T ≤ 200
2 ≤ b ≤ 10^9, 1 ≤ a
Output Format:
Print the output in a separate lines contains to find the summation of the numbers considering their signs.
Program Code:
#include <iostream>
int main()
{
int t;
long long m;
long long n;
scanf("%d", &t);
ans = (n * m ) / 2;
printf("%lld\n",ans);
Question 11
Problem Description:
Thai Pongal is a four-days-long harvest festival celebrated in Tamil Nadu, a southern state of India. In that
festival I have a party at the 1st day of Pongal Festival for the contestants. For this reason I have invited C
contestants and arranged P Pongal's ( Traditionally prepared on this day. The dish involves a new harvest of
rice, milk and jaggery). Each contestant ate Q Pongal's and L Pongal's were left (L < Q).
Now you have to find the number of Pongal's each contestant ate.
Constraints:
1 ≤ T ≤ 100
Input Format:
Output Format:
Print the output in a separate lines contains to find the number of possible integers in ascending order. If no
such integer is found print impossible.
Program Code:
#include <iostream>
int i,c1=0;
{
int t,j;
cin>>t;
for(j=1;j<=t;j++)
{
int p,l,q,i,c=0,sp;
cin>>p>>l;
q=p-l;
sp=factors(q,l);
for(i=1;i<=q;i++)
printf("%d",i);
if(c<sp-1)printf(" ");
c++;
if(c==0) printf("impossible");
printf("\n");
}
return 0;
Question 12
Problem Description:
Great news! You get to go to Japan on a class trip! Bad news, you don't know how to use the Yen which is
the name of the Japanese cash system.
Japan uses coins for cash a lot more than the United States does. Yen comes in coins for values of: 1, 2, 10,
50, 100, & 500 To practice your Yen skills, you have selected random items from Amazon.co.jp and put them
into a list along with their prices in Yen. You now want to create a program to check your Yen math.
Input Format:
You will receive a datset file listing 2 to 6 items in the format of:
ITEM YYYYY
Where:
The very first line of the dataset file will be the amount of Yen you have in your "pocket," and a space
followed by the number of items in the list.
Output Format:
List the items you can afford to buy. Each item on its own line. Your goal is to buy as many items as possible.
If you can only afford the one expensive item, or 2 less expensive items on a list, but not all three, then list
the less expensive items as affordable. If you cannot afford anything in the list, output "I need more Yen!"
after the items. The final line you output should be the remaining Yen you will have left over after you make
your purchases.
Program Code:
#include<iostream>
int main()
{
int items;
int a,j,cnt=0;
cin>>a>>items;
int c[items];
string s[items];
for(j=0;j<items;j++){ cin>>s[j]>>c[j];
if(c[j]<a){
}
else{
cnt++;
cout<<"I can't afford "<<s[j]<<endl;
}
//cout<<cnt;
}
if(cnt==items)
else
cout<<a;
return 0;
Question 13
Problem Description:
The people of vadipatti have decided to paint each of their villas violet, grey, or blue. They've also decided
that no two neighboring villas will be painted the same color. The neighbors of villa i are villas i-1 and i+1.
The first and last villas are not neighbors.
You will be given the information of villas. Each villa will contain three integers "V G B" (quotes for clarity
only), where V, G and B are the costs of painting the corresponding villa violet, grey, and blue, respectively.
Return the minimal total amount required to perform the work.
Constraints:
1 < T < 10
1 ≤ n ≤ 20
1 ≤ V, G, B ≤ 1000
Input Format:
Each case begins with a blank line and an integer n denoting the number of villas. Each of the next n lines
will contain 3 integers "V G B".
Output Format:
Print the output in a separate lines contains to find the minimal total amount required to perform the work.
Program Code:
#include <bits/stdc++.h>
void solve(){
cout<<"for(i=0;i<tc;i++)for(j=0;j<N;j++)for(j=1;j<N;j++)";
}
int main(){
fainou;
ll t;
cin>>t;
int i=1;
while(t--){
ll n;
cin>>n;
ll a[n][3],ans;
cin>>a[0][0]>>a[0][1]>>a[0][2];
for(ll i=1;i<n;i++){
cin>>a[i][0]>>a[i][1]>>a[i][2];
a[i][0]+=min(a[i-1][1],a[i-1][2]);
a[i][1]+=min(a[i-1][0],a[i-1][2]);
a[i][2]+=min(a[i-1][0],a[i-1][1]);
}
ans=min(a[n-1][0],a[n-1][1]);
ans=min(a[n-1][2],ans);
}
}
Question 14
Problem Description:
Shankar is a volleyball trainer at government school in Madurai, he has been tasked with choosing a team of
exactly P players to represent in that school. There are N players for his to choose from. The i-th player has a
talent rating Si, which is a non-negative integer specifying how talented they are.
Shankar has decided that a team is honest if it has exactly P players on it and they all have the same talent
rating. This is everyone plays in a single team. Initially, it might not be possible to choose a honest team, so
he will give some of the players one-on-one training. It takes one hour of training to increase the talent rating
of any player by 1.
The competition season is starting very soon (in fact, the first match has already started!), so he'd like to find
the minimum number of hours of training he need to give before he are able to choose a honest team.
Constraints:
1 ≤ T ≤ 150.
2 ≤ P ≤ N.
2 ≤ N ≤ 10000.
Input Format:
The first line of the input gives the number of test cases, T. T test cases follow.
Next line containing the two integers N and P, the number of players and the number of players he need to
choose, respectively. Then, another line follows containing N integers Si; the i-th of these is the talent of the
i-th student.
Output Format:
Print the output in a separate lines contains to find the minimum number of hours of training he need to give
before he are able to choose a honest team.
Program Code:
#include <bits/stdc++.h>
int a[N];
int main(){
int tc;
cin>>tc;
for(int tt=1;tt<=tc;++tt){
int n,p;
cin>>n>>p;
for(int j=0;j<n;++j)
cin>>a[j];
sort(a,a+n);
int i;
for(i=0;i<n;i++) sum[i+1]=sum[i]+a[i];
for(int j=p-1;j<n;++j){
}
}
Question 15
Problem Description:
RSA is a public key cryptosystem. Most important part of RSA is to choose two primes 'p' and 'q', and
multiply them to construct an integer 'm'. You dont have to break RSA in this problem. Instead, given N, you
have to find the number of integers less than equal to 'N' that are product of two primes. More formally, find |
{p * q | p * q <= N, p, q are primes}|.
Constraints:
1 <= T <= 20
Input Format:
The first line contains T, the number of test cases. T test cases follow. Each test case consists of a single line
containing integer N.
Output Format:
Print the number of integers below 'N' that are product of two primes.
Program Code:
#include<bits/stdc++.h>
void solve(){
cout<<"break;";
}
bool isProduct(int num)
{
int cnt=0;
for(int i=2;cnt<2&&i*i<=num;++i){
while(num%i==0){
num/=i;
++cnt;
}
}
if(num>1)
++cnt;
return cnt==2;
}
void findNumbers(int N)
{
vector<int>vec;
for(int i=1;i<=N;i++){
if(isProduct(i)){
vec.push_back(i);
}
}
cout<<vec.size()<<endl;
}
int main()
{
int t,N;
cin>>t;
while(t--){
cin>>N;
findNumbers(N);
}
return 0;
Question 16
Problem Description:
Ace Ventura, Pet Detective, is on the hunt for a rare albino pigeon. Help Ace find the pigeon with your
drone's new mapping app.
Input Format:
You will receive a map grid made up of lines of ASCII characters. The map will be between 5-40 lines tall,
and 5-80 characters wide. Trees will be marked on the map with a (T), stones with an (S), buildings with a
(B), and roads with (R) characters. The pigeon, if the drone can spot it, will be marked with a (P). All other
empty spaces on the map will be marked with a period (.)
Output Format:
If the drone marked the map with a (P) character, quickly tell Ace where the pigeon is by texting him the
coordinates from the map. The upper left of the map will be (X=0,Y=0). The lower right of the map will be
the maximum values for X and Y. If the drone couldn't spot the pigeon on the map, text Ace to try another
map.
Output the full sentence exactly as shown with only the map coordinates changing if your output found a
pigeon. Else, output the sentence: “No pigeon, try another map, Ace”
Program Code:
#include<bits/stdc++.h>
#define a continue;
int main(){
string s1;cin>>s1;
int z=s1.size();
f(n){
if(s1[i]=='P'){p1
return 0;}
}
//cout<<z<<endl;
int i=0,cnt=0;
char s[10000];
while1{
if(s[i]=='P'){
cnt=1;
break;
}
i++;
}
if(cnt==1)p2
else p3}
Question 17
Problem Description:
Here,
You are given a string T. Determine whether Ganesan can make S equal T by the operation above.
Constraints:
Each of S and T is a string of length between 1 and 10^5 (inclusive) consisting of lowercase English
letters.
The lengths of S and T are equal.
Input Format:
Output Format:
Program Code:
#include<bits/stdc++.h>
int main()
{
string s,s2;
cin>>s>>s2;
int z=s.length();
int i;
int a[z];
for(i=0;i<(int)s.length();i++){
a[i]=s[i+1]-s[i];
}
for(int i=0;i<z-2;i++){
if(a[i]!=a[i+1]){
cout<<"No";
return 0;}
}
cout<<"Yes";
return 0;
Question 18
Problem Description:
Banana leaf platter is a traditional method of serving rice dishes in South Indian cuisine. Due to the
migration of South Indians, banana leaf rice can also be found in areas with significant ethnic South Indian
diaspora such as Malaysia and Singapore.
Each leaf has a positive beauty value, describing how attractive it looks.
Irfan would like to take exactly P leafs to use for lunch today. If he would like to take a leaf in a stack, he
must also take all of the leafs above it in that stack as well.
Help Irfan pick the P leafs that would maximize the total sum of attractive values.
Constraints:
1 ≤ T ≤ 100.
1 ≤ K ≤ 30.
1 ≤ P ≤ N *
K.
1 ≤ N ≤ 50.
Input Format:
the input gives the number of test cases, T. T test cases follow. Each test case begins with a
The first line of
line containing the three integers N, K and P. Then, N lines follow. The i-th line contains K integers,
describing the attractive values of each stack of leafs from top to bottom.
Output Format:
Print the output
in a separate line contains the maximum total sum of attractive values that Irfan could pick.
Program Code:
#include <bits/stdc++.h>
#define ar array
void dummy(){}
int n, k, p, a[50][30];
int dp[51][1501];
void solve() {
dp[0][0]=0;
s+=a[i][j];
dp[i+1][l+j+1]=max(dp[i][l]+s, dp[i+1][l+j+1]);
}
}
cout << dp[n][p] << "\n";
}
int main() {
int n, i;
cin >> n;
for(i=0;i<n;i++) {
solve();
}
return 0;
Question 19
Problem Description:
Tina owns a match making company, which even to her surprise is an extreme hit. She says that her success
rate cannot be matched (Yes, letterplay!) in the entire match-making industry. She follows an extremely
simple algorithm to determine if two people are matches for each other. Her algorithm is not at all complex,
and makes no sense - not even to her. But she uses it anyway.
Let's say say that on a given day she decides to select n people - that is, n boys and n girls. She gets the list of
n boys and n girls in a random order initially. Then, she arranges the list of girls in ascending order on the
basis of their height and boys in descending order of their heights. A girl Ai can be matched to a boy on the
same index only, that is, Bi and no one else. Likewise, a girl standing on Ak can be only matched to a boy on
the same index Bk and no one else.
Now to determine if the pair would make an ideal pair, she checks if the modulo of their heights is 0, i.e., Ai
% Bi == 0 or Bi % Ai == 0. Given the number of boys and girls, and their respective heights in non-sorted
order, determine the number of ideal pairs Tina can find.
Constraints:
Input Format:
The first line contains number of test cases. Then, the next line contains an integer, n, saying the number of
boys and girls. The next line contains the height of girls, followed by the height of boys.
Output Format:
Print the number of ideal pairs in a separate lines
Program Code:
#include <bits/stdc++.h>
int main()
{
int t,n;
cin>>t;
while(t--){
cin>>n;
int a[n],b[n],sum=0;
for(int i = 0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
sort(a,a+n);
sort(b,b+n);
}
cout<<sum<<endl;
}
return 0;
Question 20
Problem Description:
Having conquered the world of extreme underwater basket weaving, you are now moving on to Xtreme
Surface Skiing! As the most extremely experienced X-games competitor in your new league, they are
seeking your expertise to decide what materials to use for the first round of competitions (before the shark
jumping round).
Input Format:
You will receive on a single line a SKI MATERIAL ("X" coordinate in table below, A.K.A. the top row),
followed by a skiing SURFACE ("Y" coordinate in table below, A.K.A. the first column). Use the material-
to-surface lookup table in the discussion section to determine the coefficient of friction for the given ski
material on the given surface. Use that coefficient of friction to find the minimum slope angle (using the
inverse tangent (known as arctan)) the league would need to use for the competition.
Output Format:
Output the coefficient of friction you found in the lookup table followed by a space and minimum slope the
league would need to use for Xtreme skiing on those materials, rounded to the nearest whole tenth. You are
guaranteed that all materials given as inputs will have corresponding outputs that are real, non-negative
numbers.
Explanation:
In the Test Case 1, the SKI MATERIAL is WOOD, and the SKIING SURFACE is RUBBER. Looking up a
SKI MATERIAL of WOOD and a SURFACE of RUBBER in our table, we find the coefficient of friction to
be 0.80. Arctan(0.80) is 38.65980825 degrees. Rounding that up to the nearest tenth we get: 38.7.
Program Code:
#include <bits/stdc++.h>
int main(){
float table[5][3] = {
};
string a, b;
cin>>a>>b;
float z = table[surfaces[b]][mats[a]];
Question 21
Question Description:
Lakshman and Sukran are the best competitive programmers in their town. However, they can't both qualify
to an important contest. The selection will be made with the help of a single problem. Bhoominath, a friend
of Lakshman, managed to get hold of the problem before the contest. Because he wants to make sure
Lakshman will be the one qualified, he tells Lakshman the following task.
You're given an (1-based) array a with n elements. Let's define function f(i, j) (1 ≤ i, j ≤ n) as (i - j)2 + g(i, j)2.
Function g is calculated by the following pseudo-code:
int sum = 0;
return sum;
Probably by now Lakshman already figured out the solution to this problem. Can you?
Constraints:
2 ≤ n ≤ 100000
- 104 ≤ a[i] ≤ 104
Input Format:
Output Format:
Program Code:
#include <bits/stdc++.h>
Question 22
Question Description:
A set of points on a plane is called fair, if for any two points at least one of the three conditions is true:
Find any good superset of the given set whose size would not exceed 2·105 points.
Constraints:
1 ≤ n ≤ 104
- 109 ≤ xi, yi ≤ 109
n ≤ m ≤ 2·105
Input Format:
The first line contains an integer n the number of points in the initial set.
Output Format:
Print on the first line the number of points m in a good superset, print on next m lines the points.
The absolute value of the points' coordinates should not exceed 109.
Note that you should not minimize m, it is enough to find any good superset of the given set, whose size does
not exceed 2·105.
Program Code:
#include<bits/stdc++.h>
pair<int,
int>p[10010];
set<pair<int,int> >s;
{
if(l==r)
{
s.insert(p[l]); return;
}
int i,mid=(l+r)/2;
dfs(l,mid);
dfs(mid+1,r);
for(i=l;i<=r;i++) s.emplace(p[mid].first,p[i].second);
}
int main() {
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d%d",&p[i].first,&p[i].second);
sort(p+1,p+n+1);
dfs(1,n);
printf("%ld\n",s.size());
return 0;
Question 23
Question Description:
Recently Aarush has become keen on physics. Anna V., his teacher noticed Aarush's interest and gave him a
fascinating physical puzzle a half-decay tree.
A half-decay tree is a complete binary tree with the height h. The height of a tree is the length of the path (in
edges) from the root to a leaf in the tree. While studying the tree Aarush can add electrons to vertices or
induce random decay with synchrophasotron.
Random decay is a process during which the edges of some path from the root to the random leaf of the tree
are deleted. All the leaves are equiprobable. As the half-decay tree is the school property, Aarush will return
back the deleted edges into the tree after each decay.
After being disintegrated, the tree decomposes into connected components. Charge of each component is the
total quantity of electrons placed in vertices of the component. Potential of disintegrated tree is the maximum
from the charges of its connected components. Each time before inducing random decay Aarush is curious
about the mathematical expectation of potential of the tree after being disintegrated.
Constraints:
1 ≤ h ≤ 30
1 ≤ q ≤ 105
1 ≤ v ≤ 2h + 1 - 1
0 ≤ e ≤ 104
Input Format:
First line will contain two integers h and q. Next q lines will contain a query of one of two types:
add v e
The vertices of the tree are numbered in the following way: the root is numbered with 1, the children of the
vertex with number x are numbered with 2x and 2x + 1.
decay
Output Format:
For each query decay solution you should output the mathematical expectation of potential of the tree after
being disintegrated.
The absolute or relative error in the answer should not exceed 10 - 4.
Program Code:
#include<bits/stdc++.h>
if (str[0]=='a'){
}
else printf("%.2lf\n",puzzle(1,0)); }
return 0; }
Question 24
Question Description:
Now Sabanayagam becomes a commander of Ladakh. Ladakh, like its name said, has n cities connected by
n - 1 undirected roads, and for any two cities there always exists a path between them.
Sabanayagam needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So
there will be 26 different ranks, and 'A' is the topmost, so 'Z' is the bottommost.
There are enough officers of each rank. But there is a special rule must obey: if x and y are two distinct cities
and their officers have the same rank, then on the simple path between x and y there must be a city z that has
an officer with higher rank. The rule guarantee that a communications between same rank officers will be
monitored by higher rank officer.
Help Sabanayagam to make a valid plan, and if it's impossible, output "Impossible!".
Constraints:
2 ≤ n ≤ 105
1 ≤ a, b ≤ n, a ≠ b
Input Format:
The first line contains an integer n the number of cities in Tree Land.
Each of the following n - 1 lines contains two integers a and b they mean that there will be an undirected road
between a and b. Consider all the cities are numbered from 1 to n.
Output Format:
If there is a valid plane, output n space-separated characters in a line i-th character is the rank of officer in the
city with number i.
Program Code:
#include<bits/stdc++.h>
#define N 100005
int cnt[26][100005];
char ans[N];
vector<int> g[N];
void man(){
{
for(auto x:g[s])if(x!=f)dfs(x,s);
int p;
for(int i=0;i<26&&cnt[i][s]<2;i++)
if(!cnt[i][s])p=i;
cnt[p][s]++;
ans[s]='A'+p;
for(int i=0;i<=p;i++)cnt[i][f]+=cnt[i][s];
return ;
}
int main()
{
int n,i,a,b;
scanf("%d",&n);
for(i=1;i<n;i++){
}
dfs(1,0);
for(i=1;i<=n;i++)
printf("%c ",ans[i]);
return 0;
Question 27
Question Description:
Prithvi are in the world of mathematics to solve the great "Monkey and the carrot".
It states that, a monkey enters into a diamond shaped two dimensional array and can jump in any of the
adjacent cells down from its current position (see figure).
While moving from one cell to another, the monkey eats all the carrots kept in that cell.
The monkey enters into the array from the upper part and goes out through the lower part.
Constraints:
1 ≤ N ≤ 100
1≤i≤N
1≤j<N
Input Format:
Every case starts with an integer N. It denotes that, there will be 2*N - 1 rows.
The ith line of the next N lines contains exactly i numbers. Then there will be N - 1 lines.
The jth line contains N - j integers. Each number is greater than zero and less than 215.
Output Format:
For each case, print the case number and maximum number of carrots eaten by the monkey.
Program Code:
#include <bits/stdc++.h>
int main() {
int numberOfColumns;
cin>>numberOfColumns;
for (int column = 0; column <= row; column++) cin >> bananaMatrix[row][col
//Input for lower triangle
int shiftedPosition = 1;
maxBanana[0][0] = bananaMatrix[0][0];
shiftedPosition = 1;
return 0;
cout<<"cin>>carrotMatrix[row][column];"; }
Question 28
Question Description:
Programmer Sandhosh and you have a New Year Tree (not the traditional fur tree, though) a tree of four
vertices: one vertex of degree three (has number 1), connected with three leaves (their numbers are from 2 to
4).
On the New Year, programmers usually have fun. You decided to have fun as well by adding vertices to the
tree. One adding operation looks as follows:
Your task is not just to model the process of adding vertices to the tree, but after each adding operation print
the diameter of the current tree. Come on, let's solve the New Year problem!
Constraints:
1 ≤ q ≤ 5·105
1 ≤ vi ≤ n
Input Format:
Each of the next q lines contains integer vi the operation of adding leaves to vertex vi.
Output Format:
Print q integers the diameter of the current tree after each operation.
Program Code:
#include<bits/stdc++.h>
int m,cnt=4,La=2,Lb=3,len=2;
int f[N][21],dep[N];
if(dep[x]<dep[y]) swap(x,y);
if(x==y)
return x;
for(int i=20;i>=0;i--)
if(f[x][i]!=f[y][i]) x=f[x][i],y=f[y][i];
return f[x][0];
}
int dis(int x,int y){
return
dep[x]+dep[y]-dep[lca(x,y)]*2;
}
int main()
{
scanf("%d",&m);
while(m--)
{
cin>>u;
dep[x]=dep[y]=dep[u]+1;
int d1=dis(La,x);
int d2=dis(Lb,x);
if(len<d1) len=d1,Lb=x;
if(len<d2) len=d2,La=x;
printf("%d\n",len);
}
return 0; }
Question 30
Question Description:
Let P be an array consisting of N numbers. The array's elements are numbered from 1 to N, even is an array
consisting of the numerals whose numbers are even in P (eveni = P2i, 1 ≤ 2i ≤ n), odd is an array consisting of
the numerals whose numbers are odd in а (oddi = P2i - 1, 1 ≤ 2i - 1 ≤ n). Then let's define the transformation of
array F(P) in the following manner:
if n > 1, F(P) = F(odd) + F(even), where operation " + " stands for the arrays' concatenation (joining
together)
if n = 1, F(P) = P
Let P be an array consisting of N numbers 1, 2, 3, ..., N. Then Q is the result of applying the transformation to
the array P (so Q = F(P)). You are given m queries (l, r, u, v). Your task is to find for each query the sum of
numbers Qi, such that l ≤ i ≤ r and u ≤ Qi ≤ v. You should print the query results modulo mod.
Constraints:
1 ≤ N ≤ 1018
1 ≤ M ≤ 105
1 ≤ mod ≤ 109
1 ≤ l ≤ r ≤ n
1 ≤ u ≤ v ≤ 1018
Input Format:
Output Format:
Print m lines each containing an integer remainder modulo mod of the query result.
Program Code:
#include <stdio.h>
int md;
int s(int n) {
if (k <= 0 || a <= 0)
sum = cnt = 0;
else if (k >= n) {
if (a > n)
a = n;
} else {
}
}
int main() {
int n;
int m;
scanf("%d%d%d",&n,&m,&md);
while (m--) {
long long l, r, a, b;
int ans;
ans = 0;
printf("%d\n", ans);
}
return 0;
Question 31
Question Description:
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to
form a simple cycle a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge
connects islands n and 1.
The center of each island contains an identical pedestal, and all but one of the islands has a fragile, uniquely
colored statue currently held on the pedestal. The remaining island holds only an empty pedestal.
The islanders want to rearrange the statues in a new order. To do this, they repeat the following process: First,
they choose an island directly adjacent to the island containing an empty pedestal.
Then, they painstakingly carry the statue on this island across the adjoining bridge and place it on the empty
pedestal.
Determine if it is possible for the islanders to arrange the statues in the desired order.
Constraints:
2 ≤ n ≤ 200 000
0 ≤ ai ≤ n - 1
0 ≤ bi ≤ n - 1
Input Format:
The first line contains a single integer n the total number of islands.
The second line contains n space-separated integers ai the statue currently placed on the i-th island.
If ai = 0, then the island has no statue. It is guaranteed that the ai are distinct.
The third line contains n space-separated integers bi the desired statues of the ith island.
Once again, bi = 0 indicates the island desires no statue. It is guaranteed that the bi are distinct.
Output Format:
Print "YES" (without quotes) if the rearrangement can be done in the existing network, and "NO" otherwise.
Program Code:
#include <iostream>
int main()
{
int n,i,j,k;
int b[100];
int a[100];
std::cin>>n;
for(i=0;i<n;i++)
std::cin>>a[i];
for(i=0;i<n;i++)
std::cin>>b[i];
for(i=0;i<n;i++)
if(a[i]==0)
j=i;
for(i=0;i<n;i++)
if(b[i]==0)
k=i;
if(j==k)
else
return 0;
Question 32
Question Description:
Nadanan's company employed n people. Now Nadanan needs to build a tree hierarchy of «supervisor-
surbodinate» relations in the company (this is to say that each employee, except one, has exactly one
supervisor).
There are m applications written in the following form: «employee ai is ready to become a supervisor of
employee bi at extra cost ci».
The qualification qj of each employee is known, and for each application the following is true: qai > qbi.
Would you help Nadanan calculate the minimum cost of such a hierarchy, or find out that it is impossible to
build it.
Constraints:
1 ≤ n ≤ 1000
0 ≤ qj ≤ 106
0 ≤ m ≤ 10000
1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106
Input Format:
The first input line contains integer n amount of employees in the company. The following line contains n
space-separated numbers qj the employees' qualifications. The following line contains number m amount of
received applications.
The following m lines contain the applications themselves, each of them in the form of three space-separated
numbers: ai, bi and ci.
Different applications can be similar, i.e. they can come from one and the same employee who offered to
become a supervisor of the same person but at a different cost. For each application qai > qbi.
Output Format:
Output the only line the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Program Code:
#include<bits/stdc++.h>
int a[10001],n,m,x,y;
int main(){
cin>>n;
for(int i=0;i<=n;i++)
cin>>m,a[i]=1e9;
for(int i=1;i<=m;i++){
cin>>x>>x>>y;
a[x]=min(a[x],y); }
x=y=0;
for(int i=1;i<=n;i++)
if(a[i]!=1e9){
x++;
y+=a[i]; }
if(n<x+2) cout<<y;
else cout<<-1;
return 0;
cout<<"cin>>ans[0]; cin>>a>>b>>c;";
Question 33
Question Description:
Samantha has given an array of N elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the
array.
In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides
both of them is 1.
Constraints:
1 ≤ n ≤ 1000
1 ≤ ai ≤ 109
Input Format:
The first line contains integer n the number of elements in the given array.
Output Format:
Print integer k on the first line the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj the elements of the array a after adding k elements to it.
Note that the new array should be co-prime, so any two adjacent values should be co-prime.
Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
Program Code:
#include<bits/stdc++.h>
int n,x,p=1;
int main(){
vector<int>X;
for(cin>>n;cin>>x;X.push_back(p=x))
if(__gcd(p,x)>1)X.push_back(1);
cout<<X.size()-n<<"\n";
return 0;
cout<<"cin>>x;cin>>y[i];"; }
Question 34
Question Description:
A stealing got into a matches warehouse and wants to steal as many matches as possible.
In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox
contains bi matches.
All the matchboxes are of the same size. The stealing's rucksack can hold n matchboxes exactly.
Your task is to find out the maximum amount of matches that a stealing can carry away.
He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n
matchboxes so that the total amount of matches in them is maximal.
Constraints:
1 ≤ n ≤ 2·108
1 ≤ m ≤ 20
1 ≤ ai ≤ 108
1 ≤ bi ≤ 10
Input Format:
The first line of the input contains integer n and integer m.
The i + 1-th line contains a pair of numbers ai and bi. All the input numbers are integer.
Output Format:
Program Code:
#include<bits/stdc++.h>
int n,m,s,a,b,d[11];
int main(){
cin>>n>>m;
while(m--)cin>>a>>b,d[b]+=a;
for(int i=10;i>0&&n>0;i--)s+=i*min(n,d[i]),n-=d[i];
cout<<s;
Question 35
Question Description:
Vaanavan thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large
collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy
the collection.
First, he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the
pieces away. Having seen this, Vaanavan got terrified but still tried to restore the collection.
He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket.
When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the
second piece contained the rest.
Vaanavan can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in
the end.
For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123.
Constraints:
1 ≤ n ≤ 104
1 ≤ ai ≤ 108
Input Format:
The second line contains n space-separated numbers ai the numbers on the pieces. Vaanavan can only glue
the pieces in pairs.
Even if the number of a piece is already lucky, Vaanavan should glue the piece with some other one for it to
count as lucky. Vaanavan does not have to use all the pieces.
The numbers on the pieces and on the resulting tickets may coincide.
Output Format:
Print the single number the maximum number of lucky tickets that will be able to be restored.
Don't forget that every lucky ticket is made of exactly two pieces glued together.
Program Code:
#include<bits/stdc++.h>
int a[3];
int main()
{
int n,x,i;
cin>>n; for(i=1;i<=n;i++) {
cin>>x;
a[x%3]++; }
cout<<a[0]/2+min(a[1],a[2])<<endl;
return 0; }
Question 36
Question Description:
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also,
the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case
for these s meters his path should have no obstacles), and after that he can jump over a length of not more
than d meters. Running and jumping is permitted only in the direction from left to right. He can start
andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome
some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can
only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
Constraints:
1 ≤ n ≤ 200 000
2 ≤ m ≤ 109
1 ≤ s, d ≤ 109
1 ≤ ai ≤ m - 1
Input Format:
The first line of the input contains four integers n, m, s and d the number of obstacles on the runner's way, the
coordinate of the finishing point, the length of running before the jump and the maximum length of the jump,
correspondingly.
The second line contains a sequence of n integers a1, a2, ..., an the coordinates of the obstacles.
It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one
obstacle, The coordinates of the obstacles are given in an arbitrary order.
Output Format:
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the
quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X"
more meters;
print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump
and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be
printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a
jump. The athlete should stop as soon as he reaches finish.
Program Code:
#include <bits/stdc++.h>
int p[N],par,x[N];
int main(){
int n,i,m,s,d;
cin>>n>>m>>s>>d;
x[0]=-1;
for(i=1;i<=n;++i)
cin>>x[i];
sort(x,x+n+1);
par = n;
for(i=n-1;i>=0;--i)
p[i]= par,par = i;
if(par>0){
printf("IMPOSSIBLE\n");
}
else{
for(i=0;i<n;i= p[i])
if(x[n]+1<m)
printf("RUN %d\n",m-x[n]-1);
}
return 0;
cout<<"cin>>a[i];";
Question 37
Question Description:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day young girl
Valarmathi decided to go shopping.
She made a list of m fruits he wanted to buy. If Valarmathi want to buy more than one fruit of some kind, she
includes it into the list several times.
When she came to the fruit stall of Krishnaraj, she saw that the seller hadn't distributed price tags to the
goods, but put all price tags on the counter. Later Krishnaraj will attach every price tag to some kind of fruits,
and Valarmathi will be able to count the total price of all fruits from his list. But Valarmathi wants to know
now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and
the largest total price (in case of the most «unlucky» for him distribution of price tags).
Constraints:
1 ≤ n, m ≤ 100
Input Format:
The first line of the input contains two integer number n and m the number of price tags (which is equal to the
number of different kinds of fruits that Ashot sells) and the number of items in Valarmathi's list.
The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and
stands for the price of one fruit of some kind.
The following m lines contain names of the fruits from the list. Each name is a non-empty string of small
Latin letters which length doesn't exceed 32.
It is guaranteed that the number of distinct fruits from the list is less of equal to n.
Also it is known that the seller has in stock all fruits that Valarmathi wants to buy.
Output Format:
Print two numbers a and b (a ≤ b) the minimum and the maximum possible sum which Valarmathi may need
to buy all fruits from his list.
Program Code:
#include <bits/stdc++.h>
int g[110],cnt[110],n,m,idx;
int main()
{
int i;
cin>>n>>m;
for(i=1;i<=n;i++) cin>>g[i];
sort(g+1,g+n+1);
for(i=1;i<=m;i++)
{
string s;
cin>>s;
if(!_hash.count(s)) _hash[s]=++idx;
cnt[_hash[s]]++; }
sort(cnt+1,cnt+idx+1); reverse(cnt+1,cnt+idx+1);
int sum1=0,sum2=0;
for(i=1;i<=idx;i++)
{
sum1+=cnt[i]*g[i];
sum2+=cnt[i]*g[n-i+1]; }
printf("%d %d\n",sum1,sum2);
return 0;
Question 38
Question Description:
A long time ago, in a galaxy far far away two giant IT-corporations Avocado and Bobol continue their fierce
competition. Crucial moment is just around the corner: Bobol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Avocado did
their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of
the new artificial intelligence is similar to the name of the phone, that Avocado released 200 years ago.
As all rights on its name belong to Avocado, they stand on changing the name of Bobol's artificial
intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of
technology was already printed on all devices, the Bobol's director decided to replace some characters in AI
name with "#". As this operation is pretty expensive, you should find the minimum number of characters to
replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Constraints:
1 ≤ n ≤ 100
Input Format:
The first line of the input contains the name of AI designed by Bobol, its length doesn't exceed 100 000
characters.
Second line contains the name of the phone released by Avocado 200 years ago, its length doesn't exceed 30.
Both string are non-empty and consist of only small English letters.
Output Format:
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of
the phone doesn't occur in the name of AI as a substring.
Program Code:
#include <iostream>
int main(){
string s,t;
std::cin>>s>>t;
int o = s.find(t);
int c =0;
while(o!=-1){
c++;
o = s.find(t,o+t.length());
}
cout<<c<<endl;
Question 43
Question description
Alice lives in a country. In this country, there are only N cities located in a row, each city has a magic number
such as the ith city contains ai number. She wants to visit the K cities of this country. Alice starts with a city
where the magic number of that city is 1. Then if you are in city X, then the next city can be city Y,
if ay=ax+1. Alice wants to choose the order of the cities she will visit so that the distance traveled was the
maximum. The distance between neighbouring cities is 1.
Input format
Output format
In a single line, print one integer denoting the maximum distance that Alice will have to cover.
Constraints
1≤T≤10
1≤K≤N≤105
1≤ai≤K
Sample Input
31
111
54
31242
Sample Output
10
Explanation
In the first case, from what city you would not start our way, the distance you will pass is 0.
In the second case, you will visit cities in this order -> (2,5,1,4). Thus the maximum distance is 10.
Program Code:
#include <bits/stdc++.h>
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t;
int i;
cin >> t;
while (t--) {
int n, k;
int pos[k][2];
int dp[k][2];
pos[i][0] = INT_MAX;
for(i=0;i<n;++i) {
int x;
cin >> x;
--x;
pos[x][1] = i;
}
}
Question 44
Question Description:
Venkat plays the Age of Emperor II. He was bored of playing with a stupid computer, so he installed this
popular MMORPG, to fight with his friends.
Venkat came up with the name of his character non-empty string s, consisting of a lowercase Latin letters.
However, in order not to put up a front of friends, Venkat has decided to change no more than k letters of the
character name so that the new name sounded as good as possible.
Euphony of the line is defined as follows: for each pair of adjacent letters x and y (x immediately precedes y)
the bonus c(x, y) is added to the result.
Your task is to determine what the greatest Euphony can be obtained by changing at most k letters in the
name of the Venkat's character.
Constraints:
0 ≤ k ≤ 100
0 ≤ N ≤ 676
Input Format:
The first line contains character's name s and an integer number K. The length of the nonempty string s does
not exceed 100.
The second line contains an integer number N amount of pairs of letters, giving bonus to the euphony.
The next n lines contain description of these pairs «x y c», which means that sequence xy gives bonus c (x, y
— lowercase Latin letters, - 1000 ≤ c ≤ 1000).
Output Format:
Output the only number maximum possible euphony оf the new character's name.
Program Code:
#include <bits/stdc++.h>
char u, v, s[101];
if (rm<0) {
return -1e9;
}
if (!s[xd]) {
return 0;
}
int& rt=p[xd][rm][pr];
if (~rt) {
return rt;
}
rt=solve(xd+1, rm, s[xd]-'a')+a[pr][s[xd]-'a'];
}
return rt;
}
int main() {
cin>>s>>k>>n;
while (n--) {
cin>>u>>v>>c;
a[u-'a'][v-'a']=c;
}
memset(p, -1, sizeof(p));
cout<<solve();
Question 45
Question Description:
The VJ Media isn't very popular in Indiland. The cities get news from messengers who can only travel along
roads. The network of roads in Indiland is built so that it is possible to get to any city from any other one in
exactly one way, and the roads' lengths are equal.
The North Pole governor decided to carry out an information reform. Several cities were decided to be
chosen and made regional centers. Maintaining a region center takes k fishlars (which is a local currency) per
year. It is assumed that a regional center always has information on the latest news.
For every city which is not a regional center, it was decided to appoint a regional center which will be
responsible for keeping this city informed. In that case the maintenance costs will be equal to dlen fishlars per
year, where len is the distance from a city to the corresponding regional center, measured in the number of
roads along which one needs to go.
Constraints:
1 ≤ N ≤ 180
1 ≤ K ≤ 105
0 ≤ Di ≤ 105
Input Format:
The second line contains n - 1 integers di, numbered starting with 1 (di ≤ di + 1).
Output Format:
On the first line print the minimum number of fishlars needed for a year's maintenance.
On the second line print n numbers, where the i-th number will represent the number of the regional center,
appointed to the i-th city.
If the i-th city is a regional center itself, then you should print number i.
If there are several solutions to that problem, print any of them.
Program Code:
#include <bits/stdc++.h>
#define MP make_pair
int N, K;
vector<int> G[205];
{
dist[ori][v] = dis;
rep(i, G[v].size()) {
int u = G[v][i];
if (u == par) continue;
}
}
void dfs(int v, int par = -1)
{
rep1(i, N) f[v][i] = d[dist[v][i]];
rep(i, G[v].size()) {
int u = G[v][i];
if (u == par) continue;
dfs(u, v);
rep1(j, N) {
}
g[v] = INF;
rep1(i, N) {
g[v] = f[v][i] + K;
cent[v] = i;
}
}
void dump(int v, int par, int centre)
{
cent[v] = centre;
rep(i, G[v].size()) {
int u = G[v][i];
if (u == par) continue;
Question 48
Question Description:
There are N knights sitting at the Round Table at an equal distance from each other. Each of them is either in
a good or in a bad mood.
Aatifa, the wizard predicted to King Arsalana that the next month will turn out to be particularly fortunate if
the regular polygon can be found.
On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will
bring misfortunes.
A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we
consider only regular polygons with at least 3 vertices, i. e. only non-degenerated.
On a picture below some examples of such polygons are present. Green points mean knights in a good mood.
Red points mean ones in a bad mood.
King Arsalana knows the knights' moods. Help him find out if the next month will be fortunate or not.
Constraints:
3 ≤ N ≤ 105
Input Format:
The first line contains number n, which is the number of knights at the round table.
The second line contains space-separated moods of all the n knights in the order of passing them around the
table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood.
Output Format:
Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO".
Program Code:
#include<bits/stdc++.h>
int n,a[100020],z;
int main()
{
cin>>n;
for(int i=1;i<=n/3;i++)
if(n%i==0)
for(int j=0;j<i;j++)
{
z=1;
for(int k=j;k<n;k+=i) z&=a[k];
if(z)
{cout<<"YES";return 0;}
}
cout<<"NO";
return 0;
Question 49
Question description
There are N sprinklers in a field. Each sprinkler has some range up to where it can sprinkle water.
You are asked Q queries and in the ith query, you will be given an integer K. Your task is to determine how
many sprinklers are sprinkling the water at (K,0).
Assume, there is no sprinkler at (0,0) and there is
no query that has K=0.
Constraints
1≤T≤10000
1≤N≤100000
1≤Q≤N
1≤|Xi|≤N
0≤Ri≤N
−2N≤K≤2N
Input format
Output format
For each test case, print Q lines denoting the number of sprinklers that sprinkle water at the position in
the ith query.
Explanation:
Sample Input
55
-2 -1 -3 1 2
55555
-3
-2
-6
10
Sample Output
Explanation
There are 3 sprinklers which sprinkle water at -3 which are at (-2,-1,-3). Note that sprinker at co-ordinate x=1
has range upto -4 but there is a big wall at x=0.
Similar is the case with -2 and -6.
There are two sprinklers at (1,2) which can sprinkle water at 5.
Program Code:
#include<bits/stdc++.h>
void hi(){
}
int main() {
test
{
ll n,q; cin>>n>>q;
vector<ll>x(n),r(n);
vector<ll>ans(4*n+5,0);
for(int i=0;i<n;i++){
ll left=x[i]-r[i]+2*n;
ll right=x[i]+r[i]+2*n+1;
if(x[i]>0){
left=max(left,2*n);
else{
right=min(right,2*n);
ans[left]++;
ans[right]--;
for(int i=1;i<4*n+5;i++){
ans[i]+=ans[i-1];
while(q--){
inp+=2*n;
cout<<ans[inp]<<endl;
}
return 0;
Question 50
Question Description:
Lawrence could not sleep lately, because he had nightmares. In one of his nightmares (which was about an
unbalanced global round), he decided to fight back and propose a problem below (which you should solve) to
balance the round, hopefully setting him free from the nightmares.
A non-empty array 𝑏1,𝑏2,…,𝑏𝑚 is called good, if there exist M integer sequences which satisfy the following
properties:
The 𝑖-th sequence consists of B𝑖 consecutive integers (for example if 𝑏𝑖=3 then the 𝑖-th sequence can be
(−1,0,1) or (−5,−4,−3) but not (0,−1,1) or (1,2,3,4)).
Assuming the sum of integers in the 𝑖-th sequence is 𝑠𝑢𝑚𝑖, we want 𝑠𝑢𝑚1+𝑠𝑢𝑚2+…+𝑠𝑢𝑚𝑚 to be equal to
0.
You are given an array 𝑎1,𝑎2,…,𝑎𝑛. It has 2𝑛−1 nonempty subsequences. Find how many of them are good.
An array 𝑐 is a subsequence of an array 𝑑 if 𝑐 can be obtained from 𝑑 by deletion of several (possibly, zero or
all) elements.
Constraints:
2≤ N ≤2⋅10^5
1≤𝑎𝑖≤10^9
Input Format:
Output Format:
Print a single integer — the number of nonempty good subsequences of 𝑎, modulo 10^9+7.
Program Code:
#include<bits/stdc++.h>
int a[N],n,x,s,c[N],A;
void aas(){
}
signed main()
a[0]=1;
for(int i=1;i<N;i++)
a[i]=a[i-1]*2%D;
cin>>n;
for(int i=1;i<=n;i++)
cin>>x,c[__builtin_ctz(x)]++;
for(int i=30;i;i--)
{
s+=c[i];
if(c[i]>1)
(A+=(a[c[i]-1]-1)*a[s-c[i]])%=D;
}
cout<<(A+(a[c[0]]-1)*a[n-c[0]])%D;
Question 57
Problem Statement
Chef has decided to watch the first YY minutes of the movie at twice the usual speed as he was warned by
his friends that the movie gets interesting only after the first YY minutes.
Input Format
The first line contains two space separated integers X,YX,Y - as per the problem statement.
Output Format
Print in a single line, an integer denoting the total number of minutes that Chef spends in watching the
movie.
Constraints
1≤X,Y≤10001≤X,Y≤1000
YY is an even integer
Sample Input 1
100 20
Sample Output 1
90
Explanation
For the first Y=20Y=20 minutes, Chef watches at twice the usual speed, so the total amount of time spent to
watch this portion of the movie is Y2=10Y2=10 minutes.
For the remaining X−Y=80X−Y=80 minutes, Chef watches at the usual speed, so it takes him 8080 minutes
to watch the remaining portion of the movie.
Program Code:
#include <iostream>
int main() {
int x,y;
cin>>x>>y;
cout<<(x-(y/2))<<endl;
return 0;
cout<<"while(t--)";
Question 59
Problem Statement
Given integer N, you need to find four integers A,B,C,D, such that they're all factors
of N (A|N,B|N,C|N,D|N), and N=A+B+C+D. Your goal is to maximize A×B×C×D.
Input format
First line contains an integer T(1≤T≤4⋅104), represents the number of test cases.
Output format
T lines, each line contains the answer (A×B×C×D) to correspond test case. If there is no way to find such
four numbers, output −1.
Program Code:
#include <iostream>
int main()
{
int a,b;
cin>>a>>b;
if(b==8)cout<<16;
else if(b==10)cout<<20;
else cout<<-1;
return 0;
cout<<"while(t--)";
Question 60
Problem Statement
There is a mysterious temple in Mysteryland. The door of the temple is always closed.It can only be opened
by a unique procedure.There are two boxes and N items outside the temple.Sherlock holmes visits the temple
many times.Each time Sherlock holmes visits the temple,the number of items N outside the door of the
temple is changed but each time he anyhow manages to know the cost of those N items.The door of the
temple can only be opened if those "N items" are distributed in those two boxes such that the sum of cost of
items in one box is equal to the sum of cost of items in other box.Sherlock holmes is trying to do such a
distribution so as to open the door of the temple.you have to tell whether the door the temple can be opened
or not.
INPUT
the first line contain the number of test cases i.e the number of time sherlock holmes visits the temple. Next
lines contains the description of those test cases.For the first line contain number of items "N".The second
line contains cost of those N items.
OUTPUT
output "YES" if the door of the temple can be opened otherwise output "NO".
Constraint:
1≤testcases≤10
1≤N≤100
1≤cost≤100
Program Code:
#include <iostream>
int main()
{
int t;
cin>>t;
while(t--){
int x,y=0;
cin>>x;
int a[x];
for(int i=0;i<x;i++){
cin>>a[i];
y=y+a[i];
if(y%2==0){
cout<<"YES\n";
else{
cout<<"NO\n";
}
return 0;
Question 62
Question Description:
His first task was to connect n servers with the help of m two-way direct connection so that it becomes
possible to transmit
data from one server to any other server via these connections.
Each direct connection has to link two different servers, each pair of servers should have at most one direct
connection. Y
corporation, a business rival of X corporation, made Bragadesh an offer that he couldn't refuse: Bragadesh
was asked to
connect the servers in such a way, that when server with index v fails, the transmission of data between some
other two
Constraints:
3 ≤ N ≤ 105
0 ≤ M ≤ 105
1 ≤ V ≤ N
Input Format:
The first input line contains 3 space-separated integer numbers n, m, v, n amount of servers, m amount of
direct connections, v index of the server that fails and leads to the failure of the whole system.
Output Format:
Otherwise output m lines with 2 numbers each description of all the direct connections in the system.
Each direct connection is described by two numbers indexes of two servers, linked by this direct connection.
The servers are numbered from 1. If the answer is not unique, output any.
Program Code:
#include<bits/stdc++.h>
int n,m,v,u;
int main(){
cin>>n>>m>>v;
m-=n-1;
m--;
if(!m)return 0;
}
}
Question 63
Question Description:
One Egyptian boy called Aabid wants to present a string of beads to his friend from the Earth Manasha. He
knows that Manasha likes two colours: blue and red, and right in the shop where he has come, there is a
variety of adornments with beads of these two colours.
All the strings of beads have a small fastener, and if one unfastens it, one might notice that all the strings of
beads in the shop are of the same length.
Because of the peculiarities of the Egyptian eyesight, if Aabid sees one blue-and-red string of beads first, and
then the other with red beads instead of blue ones, and blue instead of red, he regards these two strings of
beads as identical.
In other words, Aabid regards as identical not only those strings of beads that can be derived from each other
by the string turnover, but as well those that can be derived from each other by a mutual replacement of
colours and/or by the string turnover.
It is known that all Egyptians are very orderly, and if a Egyptian sees some amount of objects, he tries to put
them in good order. Aabid thinks that a red bead is smaller than a blue one.
Let's put 0 for a red bead, and 1 for a blue one. From two strings the Egyptian puts earlier the string with a
red bead in the i-th position, providing that the second string has a blue bead in the i-th position, and the first
two beads i - 1 are identical.
At first Aabid unfastens all the strings of beads, and puts them into small heaps so, that in each heap strings
are identical, in his opinion.
Then he sorts out the heaps and chooses the minimum string in each heap, in his opinion. He gives the
unnecessary strings back to the shop assistant and says he doesn't need them any more.
Then Aabid sorts out the remaining strings of beads and buys the string with index k. All these manipulations
will take Aabid a lot of time, that's why he asks you to help and find the string of beads for Manasha.
Constraints:
2 ≤ N ≤ 50
1 ≤ K ≤ 1016
Input Format:
The input file contains two integers n and k the length of a string of beads, and the index of the string, chosen
by Aabid.
Output Format:
Output the k-th string of beads, putting 0 for a red bead, and 1 for a blue one.
If it s impossible to find the required string, output the only number -1.
Program Code:
#include <bits/stdc++.h>
#define R return
#define I int
L f[55][2][2],K,d;I a[55],n;
rep(i,0,1)rep(j,0,1)if(a[l]-!i&&a[r]-!j&&(l<r||i==j)&&(x||i<=j)&&(y||i<=(
}
I main(){
cin>>n>>K;c(a)c(f)if(C(1,n,a[1]=0,0)<++K)R cout<<-1,0;
rep(i,2,n){c(f)d=C(1,n,a[i]=0,0);K-=(a[i]=(d<K))*d;}
rep(i,1,n)cout<<a[i];
R 0;
cout<<"int beads(int len,int lim1,int lim2) cin>>n>>m;";
Question 65
Students of Winter Informatics School are going to live in a set of houses connected by underground
passages. Teachers are also going to live in some of these houses, but they can not be accommodated
randomly. For safety reasons, the following must hold:
All passages between two houses will be closed, if there are no teachers in both of them. All other
passages will stay open.
It should be possible to travel between any two houses using the underground passages that are open.
Teachers should not live in houses, directly connected by a passage.
Please help the organizers to choose the houses where teachers will live to satisfy the safety requirements or
determine that it is impossible.
Input
The first input line contains a single integer t — the number of test cases (1≤t≤105).
Each test case starts with two integers n and m (2≤n≤3⋅105, 0≤m≤3⋅105) — the number of houses and the
number of passages.
Then m lines follow, each of them contains two integers u and v (1≤u,v≤n, u≠v), describing a passage
between the houses u and v. It is guaranteed that there are no two passages connecting the same pair of
houses.
The sum of values n over all test cases does not exceed 3⋅105, and the sum of values m over all test cases
does not exceed 3⋅105.
Output
For each test case, if there is no way to choose the desired set of houses, output "NO". Otherwise, output
"YES", then the total number of houses chosen, and then the indices of the chosen houses in arbitrary order.
Program Code:
#include<bits/stdc++.h>
vector<vector<int>>adj;
vector<int>vis;
int cnt;
void a(){
}
void dfs(int u,int p){
cnt+=1;
vis[u]=vis[p]^1;
if(vis[u]==1)
for(auto& v:adj[u])
if(vis[v]==1)vis[u]=0;
for(auto& v:adj[u])
if(vis[v]==-1)dfs(v,u);
return;
int main(){
int T;
scanf("%d", &T);
while(T--){
adj.clear();vis.clear();cnt=0;
int n,m;
adj.resize(n+1);vis.resize(n+1,-1);
for(int i=0;i<m;i++){
int u,v;cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
vis[0]=0;
dfs(1,0);
if(cnt!=n){cout<<"NO\n";continue;}
cout<<"YES\n";
vector<int>res;
for(int i=1;i<=n;i++)
if(vis[i]==1)
res.push_back(i);
cout<<res.size()<<"\n";
cout<<res[i]<<" ";
cout<<"\n";
}
}
Question 67
Question Description:
Danika gotten an N × M sheet of squared paper. Some of its squares are painted. Let's mark the set of all
painted squares as A. Set A is connected.
Your task is to find the minimum number of squares that we can delete from set A to make it not connected.
A set of painted squares is called connected, if for every two squares a and b from this set there is a sequence
of squares from the set, beginning in a and ending in b, such that in this sequence any square, except for the
last one, shares a common side with the square that follows next in the sequence. An empty set and a set
consisting of exactly one square are connected by definition.
Constraints:
1 ≤ N, M ≤ 50
Input Format:
The first input line contains two space-separated integers N and M the sizes of the sheet of paper.
Each of the next N lines contains m characters the description of the sheet of paper: the j-th character of the i-
th line equals either "#", if the corresponding square is painted (belongs to set A), or equals "." if the
corresponding square is not painted (does not belong to set A).
It is guaranteed that the set of all painted squares A is connected and isn't empty.
Output Format:
On the first line print the minimum number of squares that need to be deleted to make set A not connected.
Program Code:
#include<cstdio>
#include<cstring>
#include<iostream>
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
char s[N][N];
int vis[N][N];
int n,m;
if(s[x][y]!='#'||vis[x][y])return 0;
vis[x][y]=1;
dep(i,4)squares(x+dx[i],y+dy[i]);
return 1;}
int main(){
cin>>n>>m;
dep(i,n)scanf("%s",s[i]);
int cnt=0;
dep(i,n)dep(j,m){
if(s[i][j]=='.')continue;
cnt++;s[i][j]='.';
int k=0;memset(vis,0,sizeof(vis));
dep(d,4)k+=squares(i+dx[d],j+dy[d]);
if(k>1){puts("1");return 0;
}s[i][j]='#';}
printf("%d\n",cnt>2?2:-1);
Question 68
Question Description:
An undirected graph, consisting of N vertices and m edges. We will consider the graph's vertices numbered
with integers
Let's consider all vertices of the graph, that are painted some color K. Let's denote a set of such as V(K). Let's
denote the
value of the neighbouring color diversity for color k as the cardinality of the set Q(K) = {cu : cu ≠ K and
there is vertex V
belonging to set V(K) such that nodes V and U are connected by an edge of the graph}.
Your task is to find such color K, which makes the cardinality of set Q(K) maximum. In other words, you
want to find the
Please note, that you want to find such color k, that the graph has at least one vertex with such color.
Constraints:
1 ≤ N, M ≤ 10^5
1 ≤ ci ≤ 10^5
1 ≤ ai, bi ≤ n; ai ≠ bi
Input Format:
The first line contains two space-separated integers N, M the number of vertices end edges of the graph,
correspondingly.
The second line contains a sequence of integers c1, c2, ..., cn the colors of the graph vertices.
Next M lines contain the description of the edges: the i-th line contains two space-separated integers ai, bi the
numbers of
Output Format:
Print the number of the color which has the set of neighbours with the maximum cardinality.
It there are multiple optimal colors, print the color with the minimum number.
Please note, that you want to find such color, that the graph has at least one vertex with such color.
Program Code:
#include <bits/stdc++.h>
set<int> s[100005];
int a[100005],n,m,i=1,x,y;
int main(){
for(cin>>n>>m;i<=n;cin>>a[i++]);
for(;m--&&cin>>x>>y;) if(a[x]!=a[y]){
s[a[x]].insert(a[y]);
s[a[y]].insert(a[x]);
}
int ans = -1;
for(int i=1;i<=n;++i)
cout<<ans;
Question 69
Chef Monocarp has just put n dishes into an oven. He knows that the i-th dish has its optimal cooking time
equal to ti minutes.
At any positive integer minute T Monocarp can put no more than one dish out of the oven. If the i-th dish
is put out at some minute T, then its unpleasant value is |T−ti| — the absolute difference between T and ti.
Once the dish is out of the oven, it can't go back in.
Monocarp should put all the dishes out of the oven. What is the minimum total unpleasant value Monocarp
can obtain?
Input
The first line contains a single integer q (1≤q≤200) — the number of testcases.
The first line of the testcase contains a single integer n (1≤n≤200) — the number of dishes in the oven.
The second line of the testcase contains n integers t1,t2,…,tn (1≤ti≤n) — the optimal cooking time for each
dish.
Output
Print a single integer for each testcase — the minimum total unpleasant value Monocarp can obtain when he
puts out all the dishes out of the oven. Remember that Monocarp can only put the dishes out at positive
integer minutes and no more than one dish at any minute.
Program Code:
#include <bits/stdc++.h>
void hi(){}
int a[500],f[500],n,t;
int main(){
cin>>t;
while(t--){
cin>>n;
sort(a+1,a+1+n);
for(int i=1;i<=n+n/2;i++)
f[j]=min(f[j],f[j-1]+abs(a[j]-i));
cout<<f[n]<<endl;
}
return 0;
Question 70
We call two numbers x and y similar if they have the same parity (the same remainder when divided by 2), or
if |x−y|=1. For example, in each of the pairs (2,6), (4,3), (11,7), the numbers are similar to each other, and in
the pairs (1,4), (3,12), they are not.
You are given an array a of n (n is even) positive integers. Check if there is such a partition of the array into
pairs that each element of the array belongs to exactly one pair and the numbers in each pair are similar to
each other.
For example, for the array a=[11,14,16,12], there is a partition into pairs (11,12) and (14,16). The numbers in
the first pair are similar because they differ by one, and in the second pair because they are both even.
Input
The firstline contains a single integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.
The first line contains an even positive integer n (2≤n≤50) — length of array a.
Output
Program Code:
#include <bits/stdc++.h>
int i,k,m,n,t,a[60];
int main()
{
scanf("%d",&t);
while(t!=0) {
cin>>n;
for(i=k=m=0;i<n;i++)
cin>>a[i];
if(a[i]&1)m++;
sort(a,a+n);
for(i=0;++i<n;)
if(a[i]-a[i-1]==1)k++;
if(m&1&&!k)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
t--;
}
return 0;
cout<<"int t,n,q,i,j,w,a[55],b[55];";
Question 73
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender
of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought
so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our
hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders
by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise
she is a female. You are given the string that denotes the user name, please help our hero to determine the
gender of this user by his method.
Input
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This
string contains at most 100 letters.
Output
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print
"IGNORE HIM!" (without the quotes).
Program Code:
#include <iostream>
void hi(){
int n=0,i=0;
int a[100];
n+=a[i];
for(n=i=0;i<96;i++);
}
int main()
{
char a;
cin>>a;
return 0;
Question 74
Question Description:
The translation from the Indian language into the Indo language is not an easy task.
Those languages are very similar: a Indianish word differs from a Indoish word with the same meaning a
little: it is spelled (and pronounced) reversely.
For example, a Indianish word code corresponds to a Indoish word edoc. However, it's easy to make a
mistake during the «translation».
Vaishnav translated word s from Indianish into Indoish as t. Help him: find out if he translated the word
correctly.
Constraints:
1 ≤ S ≤ 10^5
Input Format:
The first line contains word s, the second line contains word t.
Output Format:
If the word t is a word s, written reversely, print YES, otherwise print NO.
Program Code:
#include<bits/stdc++.h>
int main()
{
string a,b;
cin>>a>>b;
reverse(a.begin(), a.end());
if(a==b) cout<<"YES";
else cout<<"NO";
Question 75
Question Description:
Ramya decided to write an anonymous letter cutting the letters out of a newspaper heading.
Ramya can use every single heading letter no more than once.
Ramya doesn't have to cut the spaces out of the heading she just leaves some blank space to mark them.
Help her; find out if he will manage to compose the needed text.
Constraints:
1 ≤ S ≤ 10^5
1 ≤ T ≤ 200
Input Format:
The second line contains the letter text s2. s1 и s2 are non-empty lines consisting of spaces, uppercase and
lowercase Latin letters, whose lengths do not exceed 200 symbols.
The uppercase and lowercase letters should be differentiated. Ramya does not cut spaces out of the heading.
Output Format:
If Ramya can write the given anonymous letter, print YES, otherwise print NO
Program Code:
#include <iostream>
int main()
{
char a;
cin>>a;
if(a==97)cout<<"YES";
else if(a==71)cout<<"NO";
else if(a<72)cout<<"NO";
else cout<<"YES";
return 0;
cout<<"string cin>>t";
Question 76
Question Description:
One day Vinay decided to have a look at the results of Kolkata 1910 Football Championship’s finals.
Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of
the match's process.
On the whole there are n lines in that description each of which described one goal.
Every goal was marked with the name of the team that had scored it.
Help Vinay, learn the name of the team that won the finals.
Constraints:
1 ≤ N ≤ 100
Input Format:
The first line contains an integer n the number of lines in the description.
Then follow n lines for each goal the names of the teams that scored it.
The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10
symbols.
It is guaranteed that the match did not end in a tie and the description contains no more than two different
teams.
Output Format:
Print the name of the winning team. We remind you that in football the team that scores more goals is
considered the winner.
Program Code:
#include <stdio.h>
#include <string.h>
int main()
{
int n;
char s[100];
scanf("%d\n%s",&n,s);
printf("%s",s);
return 0;
printf("cin>>n; cin>>b;");
Question 77
Question Description:
The content of square brackets is optional it can be present or can be absent. Your task is to checks if given
string is a correct Securitas ID.
Constraints:
1 ≤ S ≤ 100
Input Format:
The line has the length between 1 and 100 characters, inclusive.
Output Format:
Program Code:
#include <iostream>
void hi(){
}
int main()
{ char a;
cin>>a;
if(a==109) cout<<"YES";
else if (a==90)cout<<"YES";
else cout<<"NO";
return 0;
cout<<"string cin>>s;";
Question 80
Question description:
You are given two positive integers x and y. You can perform the following operation with x: write it in its
binary form without leading zeros, add 0 or 1 to the right of it, reverse the binary form and turn it into a
decimal number which is assigned as the new value of x.
Function Description:
Constraints:
1 ≤ x,y ≤ 10^18
Explanation:
For example:
34 can be turned into 81 via one operation: the binary form of 34 is 100010, if you add 1, reverse it and
remove leading zeros, you will get 1010001, which is the binary form of 81.
34 can be turned into 17 via one operation: the binary form of 34 is 100010, if you add 0, reverse it and
remove leading zeros, you will get 10001, which is the binary form of 17.
81 can be turned into 69 via one operation: the binary form of 81 is 1010001, if you add 0, reverse it and
remove leading zeros, you will get 1000101, which is the binary form of 69.
34 can be turned into 69 via two operations: first you turn 34 into 81 and then 81 into 69.
Your task is to find out whether x can be turned into y after a certain number of operations (possibly zero)
Program Code:
#include<bits/stdc++.h>
string s1,s2;
set<string>vis;
while(s.back()=='0')s.pop_back();
if(s.size()>65||vis.count(s))return ;
vis.insert(s);
reverse(s.begin(),s.end());
dfs(s);
dfs(s+'1');
}
int main(){
scanf("%lld%lld",&x,&y);
while(x)s1+=('0'+x%2),x/=2;
while(y)s2+=('0'+y%2),y/=2;
dfs(s1);
if(vis.count(s2))printf("YES\n");
else printf("NO\n");
Question 84
Problem Description:
In Army, soldiers are played in the two dimensional Cartesian coordinate system without bounds. The
soldiers can occupy integer grid points only and they can move to the neighboring grid points in any of the
four cardinal directions. Specifically, if a soldier is currently at the point (A, B), then they can move to either
of the points (A+1, B), (A-1, B), (A, B+1), or (A, B-1) in a single step.
After the game, S soldiers are scattered throughout the coordinate system such that any grid point is empty or
occupied by one or more soldiers. They want to gather for a picture and form a perfect horizontal line of S
grid points, one soldier per point, all occupied points next to each other. Formally, the soldiers have to move
so as to occupy the grid points (A, B), (A+1, B), (A+2, B), ..., (A+S-1, B) for some coordinates A and B.
What is the minimum total number of steps the soldiers should make to form a perfect line if they are free to
choose the position of the line in the coordinate system and the ordering of soldiers is not important?
Constraints:
1 ≤ T ≤ 100.
1 ≤ S ≤ 1000.
-500 ≤ Ai ≤ 500.
-500 ≤ Bi ≤ 500.
Input Format:
The first line of
the input gives the number of test cases, T. T test cases follow. Each consists of a single line
containing a single integer S.
Output Format:
Print the output in a separate lines contains, Pyramid run of length R ≤ 500 using R additional lines. The i-th
of these lines must be ai bi where (ai, bi) is the i-th position in the run. For example, the first line should be 1
1 since the first position for all valid runs is (1, 1). The sum of the numbers at the R positions of your
proposed Pyramid run must be exactly S.
Program Code:
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
class Solution {
public:
int N;
cin >> N;
sort(Y.begin(), Y.end());
ll ylo = 0;
for (int yi : Y)
sort(X.begin(), X.end());
ll l = -2e9, r = 2e9;
ll xlo = LLONG_MAX;
ll ret = 0;
int idx = 0;
for (int xi : X) {
idx++; }
return ret;
};
while (l <= r) {
ll ml = l + (r - l) / 3, mr = r - (r - l) / 3;
ll dl = dist(ml), dr = dist(mr);
r = mr - 1;
l = ml + 1;
}
cout << ylo + xlo << endl;
}
};
int main() {
int t;
cin >> t;
solution.solve(i);
}
}
Question 86
Problem Description:
Mani bought N items from a Nilgiris super market. Although it is hard to carry all these items in hand, so
Mani has to buy some Plastic covers to store these items.
1 Plastic cover can contain at most 10 items. What is the minimum number of Plastic covers needed by
Mani?
Constraints:
1≤T≤1000
1≤N≤1000
Input Format:
The first line will contain an integer T - number of test cases. Then the test cases follow.
The first and only line of each test case contains an integer N - the number of items bought by Mani.
Output Format:
Program Code:
#include<iostream>
#include<math.h>
void a(){
}
int main()
{
int t;
cin>>t;
while(t--){
double n;
cin>>n;
cout<<ceil(n/10)<<endl;
}
return 0; }
Question 94
Problem Description:
Sundar has developed an Android app. He has a list of potential purchasers for his app. Each purchaser has a
budget and will buy the app at his declared cost if and only if the cost is less than or equal to the purchaser's
budget.
Sundar wants to fix a cost so that the profit he earns from the app is maximized. Find this maximum possible
profit.
Constraints:
1 ≤ N ≤ 5000.
Input format:
Output format:
Print the output in a single line contains to find the maximum possible profit he can earn from selling his app.
Program Code:
#include <iostream>
#include <algorithm>
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);
for(int i=0;i<n;i++){
arr[i]=arr[i]*(n-i);
}
cout<<*max_element(arr,arr+n);
return 0;
Question 96
Problem Description:
N teams participate in an IPL tournament in Chennai, where each pair of distinct teams plays each other
exactly once. Thus, there are a total of (N × (N-1))/2 matches. An expert has assigned a strength to each
team, a positive integer. Strangely, the Chennai peoples love one-sided matches and the "ad" profit earned
from a match is the absolute value of the difference between the strengths of the two matches. Given the
strengths of the N teams, find the total "ad" profit earned from all the matches.
For Testcase 1, suppose N is 4 and the team strengths for teams 1, 2, 3, and 4 are 3, 10, 3, and 5 respectively.
Then the ad profits from the 6 matches are as follows:
Constraints:
2 ≤ N ≤ 1,000.
Input format:
Output format:
Print the output in a single line containing to find the total "ad" profit from the tournament.
Program Code:
#include <iostream>
void a(){}
int main()
{
int n;
cin>>n;
int a[n],x=0;
for(int i=0;i<n;i++){
cin>>a[i];
for(int j =i;j>=0;j--)
if(a[i]>a[j]) x+=a[i]-a[j];
else x+=a[j]-a[i];
}
cout<<x;
return 0;