Skip to content

Commit 10aafb0

Browse files
committed
Day 7
1 parent bde3ee5 commit 10aafb0

File tree

7 files changed

+239
-46
lines changed

7 files changed

+239
-46
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
int main()
4+
{
5+
int d1=0,v1=0,d2=0,v2=0,day=0;
6+
cin>>d1>>v1>>d2>>v2>>day;
7+
if(d1==d2)
8+
{
9+
int a=d1-1;
10+
double b=(double)day/(v1+v2);
11+
cout<<ceil(b)+a<<endl;
12+
}
13+
else if(d1<d2)
14+
{
15+
int a=d1-1;
16+
int d=d2-d1;
17+
double k=(double)day/v1;
18+
int c=ceil(k);
19+
if(c>d)
20+
{
21+
day=day-d*v1;
22+
double g= (double)day/(v1+v2);
23+
cout<<ceil(g)+d+a<<endl;
24+
}
25+
else
26+
{
27+
cout<<c+a<<endl;
28+
}
29+
}
30+
else
31+
{
32+
int a=d2-1;
33+
int d=d1-d2;
34+
double k=(double)day/v2;
35+
int c=ceil(k);
36+
if(c>d)
37+
{
38+
day=day-d*v2;
39+
double g= (double)day/(v1+v2);
40+
cout<<ceil(g)+d+a<<endl;
41+
}
42+
else
43+
{
44+
cout<<c+a<<endl;
45+
}
46+
}
47+
return 0;
48+
//cout<<d1<<" ";
49+
}
1.84 MB
Binary file not shown.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// C++ code to print all possible
2+
// subsequences for given array using
3+
// recursion
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
//void printArray(vector<int> arr, int n)
8+
//{
9+
// for (int i = 0; i < n; i++)
10+
// cout << arr[i] << " ";
11+
// cout << endl;
12+
//}
13+
14+
15+
void printSubsequences(int arr,
16+
vector<int> subarr,int k,int m,vector <vector<int> > & vect)
17+
{
18+
19+
if (arr == k+1)
20+
{
21+
int l = subarr.size();
22+
23+
// Condition to avoid printing
24+
// empty subsequence
25+
if (l != 0 && m==0)
26+
{
27+
vect.push_back(subarr);
28+
//printArray(subarr, l);
29+
return;
30+
}
31+
}
32+
else
33+
{
34+
35+
int out1=arr;
36+
int out2=-arr;
37+
arr=arr+1;
38+
39+
vector <int> subarr1=subarr;
40+
vector <int> subarr2=subarr;
41+
subarr1.push_back(out1);
42+
subarr2.push_back(out2);
43+
44+
printSubsequences(arr, subarr1,k,m-1,vect);
45+
printSubsequences(arr, subarr2,k,m,vect);
46+
47+
48+
}
49+
return;
50+
}
51+
52+
// Driver Code
53+
int main()
54+
{
55+
int t=0;
56+
cin>>t;
57+
while(t--)
58+
{
59+
int n=0,k=0;
60+
cin>>n>>k;
61+
if(n==k)
62+
{
63+
for(int i=1;i<=n;i++)
64+
cout<<i<<" ";
65+
}
66+
else
67+
{
68+
int sum=0;
69+
vector <int> output;
70+
vector<vector<int> > vect;
71+
printSubsequences(1, output,n,k,vect);
72+
for(int j=0;j<vect[0].size();j++)
73+
{
74+
cout<<vect[0][j]<<" ";
75+
}
76+
cout<<endl;
77+
}
78+
79+
}
80+
81+
//printSubsequences(1, b,3);
82+
83+
return 0;
84+
}
85+
86+
87+
1.9 MB
Binary file not shown.

CodeChef/DecemberLong/q1.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def solve(d1,d2,v1, v2, day, count):
1313

1414

1515

16-
d1, v1,d2,v2,p = input().split(" ")
16+
d1,v1,d2,v2,p = input().split(" ")
1717

1818
d1 = int(d1)
1919
v1 = int(v1)
@@ -23,22 +23,22 @@ def solve(d1,d2,v1, v2, day, count):
2323

2424

2525

26-
if(lst[0]==d2):
26+
if(d1==d2):
2727
print(math.ceil(p/(v1+v2))+d1-1)
28-
else:
29-
mini=min(d1,d2)
30-
total=0
31-
maxi= max(d1,d2)
32-
a=0
33-
b=0
34-
if(mini==d1):
35-
a=v1
36-
b=v2
37-
else:
38-
b=v1
39-
a=v2
28+
#else:
29+
# mini=min(d1,d2)
30+
# total=0
31+
# maxi= max(d1,d2)
32+
# a=0
33+
# b=0
34+
# if(mini==d1):
35+
# a=v1
36+
# b=v2
37+
# else:
38+
# b=v1
39+
# a=v2
4040

41-
print(solve(mini,maxi,a,b,p,mini-1))
41+
# print(solve(mini,maxi,a,b,p,mini-1))
4242

4343

4444

CodeChef/DecemberLong/q4.cpp

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
#include<bits/stdc++.h>
22
using namespace std;
3-
void solve(int input,int x, int output,int k,int sum)
4-
{
5-
if(input==x)
6-
{
7-
// for(int i=0;i<x;i++)
8-
// {
9-
// cout<<output[i]<<" ";
10-
// }
11-
// cout<<endl;
12-
return;
13-
}
14-
//cout<<input<<endl;
15-
int out1=input;
16-
int out2=-input;
17-
input++;
18-
//output.push_back(out1);
19-
cout<<out1<<" ";
20-
solve(input,x,out1,k--,sum+out1);
21-
///output.push_back(out2);
22-
solve(input,x,out2,k,sum+out2);
23-
return;
24-
25-
26-
}
3+
274
int main()
285
{
296
int t=0;
@@ -39,13 +16,93 @@ int main()
3916
}
4017
else
4118
{
42-
int sum=0;
43-
vector <int> output;
44-
solve(1,n,output,k,0);
45-
// for(int i=0;i<output.size();i++)
46-
// {
47-
// cout<<output[i]<<" ";
48-
// }
19+
vector <int> a;
20+
int count=0;
21+
if(n%2==0)
22+
{
23+
for(int i=1;i<n+1;i++)
24+
{
25+
if(i%2==0)
26+
{
27+
count++;
28+
a.push_back(i);
29+
}
30+
else
31+
a.push_back(-i);
32+
}
33+
}
34+
else
35+
{
36+
for(int i=1;i<n+1;i++)
37+
{
38+
if(i%2!=0)
39+
{
40+
count++;
41+
a.push_back(i);
42+
}
43+
else
44+
{
45+
//count++;
46+
a.push_back(-i);
47+
}
48+
}
49+
}
50+
int sum=0,m=1;
51+
//cout<<count<<endl;
52+
for(int i=0;i<n;i++)
53+
{
54+
sum+=a[i];
55+
if(sum>0)
56+
{
57+
if(count<k)
58+
{
59+
int diff=k-count;
60+
int g=n-1;
61+
while(g!=0)
62+
{
63+
if(a[g]<0)
64+
{
65+
count=count+1;
66+
a[g]=abs(a[g]);
67+
diff--;
68+
}
69+
if(diff==0)
70+
break;
71+
g--;
72+
73+
}
74+
}
75+
76+
if(count>k)
77+
{
78+
int diff=count-k;
79+
int g=n-1;
80+
while(g!=0)
81+
{
82+
if(a[g]>0)
83+
{
84+
count=count-1;
85+
a[g]=-(a[g]);
86+
diff--;
87+
}
88+
if(diff==0)
89+
break;
90+
g--;
91+
92+
}
93+
}
94+
if(count==k)
95+
{
96+
break;
97+
}
98+
}
99+
}
100+
//cout<<count<<" "<<k<<endl;
101+
for(int i=0;i<n;i++)
102+
{
103+
cout<<a[i]<<" ";
104+
}
105+
49106
}
50107
cout<<endl;
51108
}

CodeChef/DecemberLong/q4.exe

-9.51 KB
Binary file not shown.

0 commit comments

Comments
 (0)