Coding Maniacs problems editorial

Hello coders, This is my first post on CodeChef discuss and the post contains solutions to our contest problems which we conducted in our college named Coding Maniacs on 14/05/2020. So if you found any mistakes do suggest me.

Contest Page: Contest Page | CodeChef

1. Two Number Game

Solution :
//coded by vishal mourya
#include<bits/stdc++.h>
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long int ll;
int main(void){
fasthoja;
ll t; cin>>t;
while(t–){
ll a,b;
cin>>a>>b;

    if( a == b ) cout<<"YES\n";
    else if( a > b ) cout<<"NO\n";
    else cout<<"YES\n";
}
return 0;

}

2. Helping Machine

Solution :
//coded by vishal mourya
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(void){
ll t; cin>>t;
while(t–){
ll n; cin>>n;
vector v(n);
ll t1=0,t2=0,t3=0;
for(ll i = 0 ; i < n ; i++ ){
cin>>v[i];

        if(v[i] == 1 || v[i] == 2)
            t1++;
        else if(v[i] == 3 || v[i] == 4)
            t2++;
        else if(v[i] == 5 || v[i] == 6)
            t3++;    
    }
    cout<<"TYPE 1 - "<<t1<<"\n";
    cout<<"TYPE 2 - "<<t2<<"\n";
    cout<<"TYPE 3 - "<<t3<<"\n";
}
return 0;

}

3. Rail Yatra

Solution :
#include <bits/stdc++.h>

using namespace std;

typedef double ld;

vector x, v;

int main()
{
cout.precision(31);
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
x.resize(n);
v.resize(n);
for (int i = 0; i < n; i++)
cin >> x[i];
for (int i = 0; i < n; i++)
cin >> v[i];
ld l = 0, r = 1e10;
for (int ui = 0; ui < 100; ui++)
{
ld med = (r + l) / (ld)(2);
ld left = -1e12, right = 1e10;
for (int i = 0; i < n; i++)
{
left = max(left, x[i] - v[i] * med);
right = min(right, x[i] + v[i] * med);
}
if (right >= left)
r = med;
else
l = med;
}
cout << fixed<<setprecision(30)<<l<<endl;
return 0;
}

4. Chef Birthday

Solution :
/*Author Sanjay shukla */
#include <bits/stdc++.h>
using namespace std;
int main()
{
int testcase;
int count,min,max;
cin>>testcase;
while((testcase–)!=0)
{
int n,len=0,i,p;
cin>>n>>p;
string a[n],query[p];
//entering a sequence of relatives
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<p;i++)
cin>>query[i];
//concatenation of strings
int j;
for(j=0;j<p;j++)
{
max=0,min=1000000;
for(i=0;i<n;i++)
{ count=0;
string result=a[i]+query[j];
//cout<<result<<endl;
int l=result.length();//length of concatenated string
len=l%10;
//cout<<len<<" ";
// this while block checks how many steps is required to convert concatenated into the first composite number(ie. FOUR)
while(len!=4)
{
switch(len)
{
case 0:
len=4;
count++;
break;
case 1:
len=3;
count++;
break;
case 2:
len=3;
count++;
break;
case 3:
len=5;
count++;
break;
case 4:
len=4;
count++;
break;
case 5:
len=4;
count++;
break;
case 6:
len=3;
count++;
break;
case 7:
len=5;
count++;
break;
case 8:
len=5;
count++;
break;
case 9:
len=4;
count++;
break;

					}//end of switch
				}//end of inner while loop
				//calculating minimum and maximum of count
				if(count<min)
				{
                    min=count;
                }
                if(count>max)
                    max=count;
                cout<<count<<" ";//this cout display all the count values for every single query on  a single line
            }//end of array
        cout<<endl;//this endl seperates count values for every single quer
        cout<<min<<" "<<max<<endl;
		}//end of while loop of query

}//end of testcase loop

}

5. Ticket Wala

Solution :
/*
coded by addy
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector vec;
#define fl(i,n) for(i=0;i<n;i++)
#define rfl(i,n) for(i=n-1;i>=0;i–)

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,i,sum1,sum2,t,even,odd,m1,m2,k,l,min1,min2,v,avg1,avg2;
cin>>t;
while(t–)
{
cin>>n;
vec a(n),b(n),c(10),f(10),s(10);
sum1=0;sum2=0;
fl(i,n)
{
cin>>a[i];//taking input of all the unit places of the tickets
}
fl(i,n)
{
cin>>b[i];//taking input of price of each ticket respectively
}
fl(i,10)
{
cin>>c[i];//tax on type of each digit
}
fl(i,n)
{
f[a[i]]++;//frequency of each digit
s[a[i]]+=b[i];//total money spent on ticket of each digit type
}
even=0;odd=0;m1=0;m2=0;
fl(i,10)
{
if((i%2)==0)
{
m1+=c[i];//calculation of sum for mean of tax of even numbers
even+=f[i];
}
else
{
m2+=c[i];//calculation of sum for mean of tax of odd numbers
odd+=f[i];
}
}
min1=n;min2=n;k=0;l=0;
if(even!=0&&odd!=0)
{
fl(i,10)
{
if(i%2==0)
{
if((f[i]<min1)&&(f[i]>0))
{
min1=f[i];
k=i;
}
}
else
{
if((f[i]<min2)&&(f[i]>0))
{
min2=f[i];
l=i;
}
}
}
avg1=(s[k]/f[k]);//avg price of no. with minimum frequency in even digit
avg2=(s[l]/f[l]);//avg price of no. with minimum frequency in odd digit
}
m1/=5;m2/=5;
fl(i,10)
{
s[i]=s[i]-f[i]*c[i];//calculating (sum of amount of each digit)-(tax on each ticket of each digit)
if(i%2!=0)
sum1+=s[i];//calculated by chef (odd units digits amount sum)
else
sum2+=s[i];//calculated by cheffa (even unit digits amount sum)
}
if(even==odd)
{
cout<<“0”<<endl;
cout<<sum1<<" “<<sum2<<endl;//output
}
else if(even==0||odd==0)
{
cout<<“0”<<endl;
cout<<sum1<<” “<<sum2<<endl;//output
}
else
{
if(even>odd)
v=(even-odd)*avg2-(even-odd)*m2;//virtual sum
else
v=(odd-even)*avg1-(odd-even)*m1;//virtual sum
cout<<“1”<<endl;
cout<<sum1+sum2<<” "<<v+sum1+sum2<<endl;
}
}
return 0;
}

Hoping to conduct more such contest in our college :slight_smile:

Thank You CodeChef for creating such a wonderful environment.