-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_51.cpp
269 lines (215 loc) · 5.19 KB
/
day_51.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
Name - Himanshu Pokhriyal
Date - 15 May , 2024
Version - C++17
Ques-1 Chef And Operators
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/CHOPRT
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
long int a,b;
cin>>a>>b;
if(a>b) cout<<">"<<endl;
else if( a<b) cout<<"<"<<endl;
else cout<<"="<<endl;
}
}
Time complexity - O(t)
Space complexity - O(1)
Ques-2 Mutated Minions
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/CHN15A
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int n,k;
cin>>n>>k;
int x;
int cnt=0;
for( int i=0;i<n;i++){
cin>>x;
if((x+k)%7==0) cnt++;
}
cout<<cnt<<endl;
}
}
Time complexity - O(t)
Space complexity - O(1)
Ques-3 Reach fast
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/REACHFAST?tab=statement
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int x,y,k;
cin>>x>>y>>k;
int d=abs(x-y);
cout<<(int)(ceil((double)d/k))<<endl;
}
}
Time complexity - O(t)
Space complexity - O(1)
Ques-4 Single-use Attack
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/SINGLEUSE
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int x,y,h;
cin>>x>>y>>h;
int d=abs(x-h);
cout<<(int)(ceil((double)d/y))+1<<endl;
}
}
Time complexity - O(t)
Space complexity - O(1)
Ques-5 Get Lowest Free
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/SALE
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int a,b,c;
cin>>a>>b>>c;
cout<<(a+b+c)-min(a,min(b,c))<<endl;
}
}
Time complexity - O(t)
Space complexity - O(1)
Ques-6 Minimum number of Flips
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/MINFLIPS?tab=statement
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int n,x;
cin>>n;
int sum=0;
for( int i=0;i<n;i++){
cin>>x;
sum+=x;
}
sum=abs(sum);
if( sum == 0) cout<<"0"<<endl;
else {
if(sum%2 != 0) cout<<"-1"<<endl;
else cout<<sum/2<<endl;
}
}
}
## Why i used "sum = abs(sum)"
Try to dry run this testcase without the "sum = abs(sum)" then you will get idea of it .
5
-1 -1 -1 -1 -1
6
-1 -1 -1 -1 -1 -1
6
1 -1 -1 -1 -1 -1
Ques-7 Binary Battles
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/BIN_BAT
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int n,a,b;
cin>>n>>a>>b;
cout<<(log2(n)*a)+(log2(n)-1)*b<<endl;
}
}
Time complexity - O(t)
Space complexity - O(1)
Ques-8 Best of Two
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/DICEGAME2
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int a1,a2,a3,b1,b2,b3;
cin>>a1>>a2>>a3>>b1>>b2>>b3;
int alice_point=(a1+a2+a3)-min(a1,min(a2,a3));
int bob_point=(b1+b2+b3)-min(b1,min(b2,b3));
if(alice_point>bob_point) cout<<"Alice"<<endl;
else if( alice_point<bob_point) cout<<"Bob"<<endl;
else cout<<"Tie"<<endl;
}
}
Time complexity - O(t)
Space complexity- O(1)
Ques-9 The Lead Game
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/TLG
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n;
cin>>n;
int a,b;
int old_a=0;
int old_b=0;
int flag=0;
int maimum =INT_MIN;
for( int i=0;i<n;i++){
cin>>a>>b;
old_a+=a;
old_b+=b;
if(maimum<abs(old_a-old_b)){
maimum=abs(old_a-old_b);
if(a>b) flag=0;
else if( a<b) flag=1;
}
}
if( flag == 0 ) cout<<"1"<<" "<<maimum<<endl;
else cout<<"2"<<" "<<maimum<<endl;
}
Time complexity - O(n)
Space complexity - O(1)
Ques-10 Degree of Polynomial
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/DPOLY
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int n;
cin>>n;
// int assumed=n-1;
int x;
int maimum=0;
for( int i=0;i<n;i++){
cin>>x;
if ( x == 0) continue;
else maimum=i;
}
cout<<maimum<<endl;
}
}
time complexity - O(t)
space complexity - O(1)
*/