Sir @zappelectro, I used recursion as you said, but still gets TLE,
code
Please tell me where I did wrong.
Sir @zappelectro, I used recursion as you said, but still gets TLE,
code
Please tell me where I did wrong.
Sorry,What do you meant by AC ?
Accepted
//Try this c++14 code .Hope this will help you
#include <iostream>
#include <cmath>
using namespace std;
int pow(int b, int p)
{
int result=1;
for(int i=0;i<p;i++)
result = result*b;
return result;
}
int distance(int x, int y, int s)
{
float time,d=pow(x,2)+pow(y,2);
return time=sqrt(d)/s;
}
int main()
{
int c,x,y,s,time;
cout<<"enter number of cars passing through origin : ";
cin>>c;
int arr[c];
for(int i=0;i<c;i++)
{
cout<<"Enter x : ";
cin>>x;
cout<<"Enter y : ";
cin>>y;
cout<<"Enter speed : ";
cin>>s;
arr[i]=distance(x,y,s);
}
int flag=0;
for(int i=0;i<c;i++)
{
for(int j=i+1;j<c;j++)
{
if(arr[i]==arr[j])
flag++;
}
}
cout<<"\n"<<flag;
}
Just refer to this.
Can anyone send me the solution of 4th question of Mockvite 2 held on 17-18th july 2020
?
๐๐๐ญ ๐ญ๐ก๐ ๐๐ฎ๐ฅ๐ฅ ๐ช๐ฎ๐๐ฌ๐ญ๐ข๐จ๐ง ๐๐๐ฌ๐๐ซ๐ข๐ฉ๐ญ๐ข๐จ๐ง ,๐๐ข๐ฌ๐๐ฎ๐ฌ๐ฌ๐ข๐จ๐ง๐ฌ ๐๐ง๐ ๐ฌ๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง๐ฌ ๐จ๐ ๐ญ๐ก๐ ๐ฆ๐จ๐๐ค๐๐ข๐ญ๐ ๐ ๐๐๐๐ ๐ก๐๐ซ๐:
Swayamvar: Swayamvar | TCS MockVita 2 2020 | By CodingHumans
Death Battle: Death Battle | TCS MockVIta 2 2020 | By CodingHumans |
Grooving Monkey: Grooving Monkeys | TCS MockVIta 2 2020 | By CodingHumans |
Petrol Pump: Petrol Pump |TCS MockVIta 2 2020 | By CodingHumans |
Dole CAdbury: Dole Out Cadbury | TCS MockVIta 2 2020 | By CodingHumans |
Digit Pairs: Digit Pairs | TCS MockVIta 2 2020 | By CodingHumans |
import java.util.*;
public class PetrolPump
{
private static int[] StrToInt(String src)
{
String[] t=src.split(" ");
int[] res=new int[t.length];
for (int i=0;i<t.length;i++ )
res[i] = Integer.parseInt(t[i]);
return res ;
}
public static void main(String[] args)
{
Scanner ip=new Scanner(System.in);
int a[]=new int[50];
String vals=ip.nextLine();
a=StrToInt(vals);
int n,m=0;
n=a.length;
for(int k=0;k<n;k++)
m=m+a[k];
int b[][]=new int[n+1][m+1];
int i,j;
for(i=0;i<=n;i++)
b[i][0]=1;
for(i=1;i<=m;i++)
b[0][i]=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
b[i][j]=b[i-1][j];
if(a[i-1]<=j)
b[i][j]=b[i][j] | b[i-1][j - a[i-1]];
}
}
int sum=m;
for(i=m/2;i>=0;โi)
{
if(b[n][i]==1)
{
sum=m-i;
break;
}
}
System.out.println(sum);
ip.close();
}
}
For d=16 and v=2, LHS part is not equal to RHS. Before posting anything on the discussion forum, think twice. 
float time,d=pow(x,2)+pow(y,2);
time=sqrt(d)/s;
Sorry my bad. First of all see this distance formula this came from Pythagoras theorem and second equation is about speed = distance/time.
Little suggestion instead of judging others try to focus on yourself first. You have no rights to say โthink before posting something on the discuss forumโ. We all have mind and we are all sharing our thoughts sometime they may go wrong also. 
I am sorry but that wasnโt rude. I expected bit more clear explanation from a four starrer, instead of stating โIts straightforward nothing to explain here. If you see carefully. d/(v * v) = sqrt(d)/sqrt(v * v) = sqrt(d)/vโ.
Of course, thatโs the formula of time, but your statement is literally stating LHS and RHS are equal. Instead, the explanation should have been like this:
We are supposed to sort based on times. But we should be careful while sorting Floating point values as there is precision loss sometimes. So, instead of taking sqrt(d)/v, we should take d/(v^2) as both are increasing functions and d/(v*2) will be more precise to takeโฆ
I am sorry if I hurted you.
Brother I said that I am wrong but you sound rude. Ask anybody in this discussion.
And if you are comparing stars here then I clap for you.
Please check time taken both code in picture below.
I tried mockvita 2 question C โDole Out Cadburyโ, in both python and cpp.
In python
In cpp
Same code in both. Same time complexity.
Bro learn at least 3 languages c(must) / c++(or java) / python for Codevita
Dates for Codevita 2020 announed -
Zone 1 : 8th Aug (3pm) to 9th aug (3pm)
Zone 2 : 15th Aug (3pm) to 16th aug (3pm)
in mockvita round 2 i have solved first four problem so you can guess by comparing my rating and number of question solved by me as a reference i dont have the solution because i have solved it on tcs platform but problem can be of sequence , dp , may be sometime graph but the loved math based question.
surely 2 math problems will be there , one dp and one graph too.
hey @ssrivastava990 after mockvita 2 i am not able to log in it keeps showing log in after 15 mins โฆ
thanks for this. I sat thinking 9th.
hey man weight for starting of codevita . there website is not up to the mark you face problem in login during the contest also so login on there website when you got a mail related to codevita