Skip to content

Commit 97adf58

Browse files
authored
Added 4 CodeChef solutions
4 Problems Solutions : DANCEMOVES.cpp MINLCM1.cpp ROOTTREE.cpp RRR.cpp
1 parent 157c2d5 commit 97adf58

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long
4+
#define endl "\n"
5+
const ll INF = 1e9 + 7;
6+
7+
void solve()
8+
{
9+
int x, y;
10+
cin >> x >> y;
11+
12+
if (x == y)
13+
{
14+
cout << "0\n";
15+
}
16+
else if (x < y)
17+
{
18+
if (abs(y - x) % 2 == 0)
19+
cout << abs(y - x) / 2 << endl;
20+
21+
else
22+
{
23+
int c = (abs(y - x) + 2 - 1) / 2;
24+
cout << c + 1 << endl;
25+
}
26+
}
27+
else
28+
cout << abs(x - y) << endl;
29+
}
30+
31+
int main()
32+
{
33+
ios_base ::sync_with_stdio(false);
34+
cin.tie(NULL);
35+
36+
int T;
37+
cin >> T;
38+
while (T--)
39+
solve();
40+
return 0;
41+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long
4+
#define endl "\n"
5+
const ll INF = 1e9 + 7;
6+
7+
void solve()
8+
{
9+
ll x, k;
10+
cin >> x >> k;
11+
12+
cout << 2 * x << ' ' << x * k * (x * k - 1) << '\n';
13+
}
14+
15+
int main()
16+
{
17+
ios_base ::sync_with_stdio(false);
18+
cin.tie(NULL);
19+
20+
int T;
21+
cin >> T;
22+
while (T--)
23+
solve();
24+
return 0;
25+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long
4+
#define endl "\n"
5+
const ll INF = 1e9 + 7;
6+
7+
void solve()
8+
{
9+
int n;
10+
cin >> n;
11+
vector<int> in_degree(n + 1, 0);
12+
13+
for (int i = 0; i < n - 1; i++)
14+
{
15+
int u, v;
16+
cin >> u >> v;
17+
in_degree[v]++;
18+
}
19+
20+
int cnt = 0;
21+
for (int i = 1; i <= n; i++)
22+
if (in_degree[i] == 0)
23+
cnt++;
24+
25+
cout << cnt - 1 << endl;
26+
}
27+
28+
int main()
29+
{
30+
ios_base ::sync_with_stdio(false);
31+
cin.tie(NULL);
32+
33+
int T;
34+
cin >> T;
35+
while (T--)
36+
solve();
37+
return 0;
38+
}

Codechef solutions/(CODECHEF) RRR.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long
4+
#define endl "\n"
5+
const ll INF = 1e9 + 7;
6+
7+
void solve()
8+
{
9+
int n, k;
10+
cin >> n >> k;
11+
12+
int ans = 2 * (n - k) + (2 * ((k - 1) / 2));
13+
cout << ans << '\n';
14+
}
15+
16+
int main()
17+
{
18+
ios_base ::sync_with_stdio(false);
19+
cin.tie(NULL);
20+
21+
int T;
22+
cin >> T;
23+
while (T--)
24+
solve();
25+
return 0;
26+
}

0 commit comments

Comments
 (0)