Skip to content

Commit

Permalink
Merge pull request #77 from Coach-Academy/Rania154-patch-4
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
7oSkaaa authored Dec 25, 2023
2 parents 31e78ba + 0ae529d commit 394a4ca
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Level 2 Class 1/Practice G4/Week 12/C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define endl '\n'


int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
map<int,int> mp;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
mp[x%m]++;
}
int cnt = 0;
for (int i = 0; i < m; ++i) {
int rem = i , com = (m-i)%m;
int mn = min(mp[rem] , mp[com]);
if ( mn > 0)
{
cnt++;
mp[rem] -=mn;
mp[com] -=mn;
}
if ( mp[rem] > 0)
{
cnt += ( mp[rem] - 1);
if ( mn == 0)
cnt++;
mp[rem] =0;
}
else if ( mp[com] > 0)
{
cnt += (mp[com] -1);
if ( mn == 0)
cnt++;
mp[com] = 0;
}
mp[com] = mp[rem] = 0;
}
cout << cnt << endl;
}
return 0;
}
39 changes: 39 additions & 0 deletions Level 2 Class 1/Practice G4/Week 12/D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define endl '\n'


int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
while (true)
{
ll sum =0;
string s = to_string(n);
for (int i = 0; i < s.size(); ++i) {
sum += ( s[i] - '0');
}
if (__gcd(n,sum) > 1)
{
cout << n << endl;
break;
}
n++;
}
}
return 0;
}
39 changes: 39 additions & 0 deletions Level 2 Class 1/Practice G4/Week 12/E.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define endl '\n'


int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
deque<int> v = {1,1};
for (int i = 0; i < n-2; ++i) {
v.push_back(0);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << v[j] << " ";
}
cout << endl;
v.push_back(v.front());
v.pop_front();
}


}
return 0;
}
45 changes: 45 additions & 0 deletions Level 2 Class 1/Practice G4/Week 12/F.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define endl '\n'


int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int idx = -1;
int mx = *max_element(a,a+n);
for (int i = 0; i < n; ++i) {
if ( a[i] == mx)
{
if ( i && a[i-1] < a[i])
idx = i;
if ( i+1 < n && a[i+1] < a[i])
idx = i;
}
}
if ( idx == -1 )
cout << -1 << endl;
else
cout << idx+1 << endl;

}
return 0;
}
50 changes: 50 additions & 0 deletions Level 2 Class 1/Practice G4/Week 12/G.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define endl '\n'


int main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int n,m;
cin >> n >> m;
int a[n][m],b[n][m];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
b[i][j] =0;
}
}
vector<pair<int,int>> v;
for (int i = 0; i < n-1; ++i) {
for (int j = 0; j < m-1; ++j) {
if ( a[i][j] + a[i+1][j] + a[i][j+1]+a[i+1][j+1] == 4)
{
v.push_back({i+1,j+1});
b[i][j] = b[i+1][j] = b[i][j+1]=b[i+1][j+1] = 1;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if ( a[i][j] != b[i][j])
{
cout << -1 << endl;
return 0;
}
}
}
cout << v.size() << endl;
for(auto it : v)
cout << it.first << " " << it.second << endl;
return 0;
}

0 comments on commit 394a4ca

Please sign in to comment.