-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from Coach-Academy/Rania154-patch-4
Add files via upload
- Loading branch information
Showing
5 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |