Add solutions for Codeforces problems 1986A, 1986B, and 1986C
This commit is contained in:
parent
a31f744f07
commit
c40b1c8007
30
Codes/1986 A - X Axis/1986A.cpp
Normal file
30
Codes/1986 A - X Axis/1986A.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
|
||||
|
||||
void solve()
|
||||
{
|
||||
int a,b,c;
|
||||
cin>>a>>b>>c;
|
||||
int mn = INT_MAX;
|
||||
for(int i=1; i<=10; ++i)
|
||||
{
|
||||
int diff = abs(a-i)+abs(b-i)+abs(c-i);
|
||||
mn = min(diff, mn);
|
||||
}
|
||||
cout<<mn<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false), cin.tie(nullptr);
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
48
Codes/1986 B - Matrix Stabilization/1986B.cpp
Normal file
48
Codes/1986 B - Matrix Stabilization/1986B.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
|
||||
|
||||
|
||||
void solve()
|
||||
{
|
||||
ll n,m;
|
||||
cin>>n>>m;
|
||||
vector<vector<ll>> v(n, vector<ll>(m));
|
||||
for(ll i=0; i<n; ++i)
|
||||
{
|
||||
for(ll j=0; j<m; ++j)
|
||||
cin>>v[i][j];
|
||||
}
|
||||
for(int i=0; i<n; ++i)
|
||||
{
|
||||
for(int j=0; j<m; ++j)
|
||||
{
|
||||
ll mx=0;
|
||||
if(i+1<n)
|
||||
mx=max(mx, v[i+1][j]);
|
||||
if(i-1>=0)
|
||||
mx=max(mx, v[i-1][j]);
|
||||
if(j+1<m)
|
||||
mx=max(mx, v[i][j+1]);
|
||||
if(j-1>=0)
|
||||
mx=max(mx, v[i][j-1]);
|
||||
if(v[i][j]>mx) v[i][j] = mx;
|
||||
cout<<v[i][j] << " ";
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false), cin.tie(nullptr);
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
41
Codes/1986 C - Update Queries/1986C.cpp
Normal file
41
Codes/1986 C - Update Queries/1986C.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n,m;
|
||||
cin>>n>>m;
|
||||
string s,c;
|
||||
cin>>s;
|
||||
set<int>st;
|
||||
for(int i=0; i<m; ++i)
|
||||
{
|
||||
int x;
|
||||
cin>>x;
|
||||
st.insert(x);
|
||||
}
|
||||
cin>>c;
|
||||
sort(c.begin(),c.end());
|
||||
vector<int>v;
|
||||
for(auto x:st) v.push_back(x);
|
||||
for(int i=0; i<st.size(); ++i)
|
||||
{
|
||||
s[v[i]-1] = c[i];
|
||||
}
|
||||
cout<<s<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false), cin.tie(nullptr);
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
@ -349,6 +349,9 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
|
||||
| 337 | 1985 E | Secret Box | [Question](https://codeforces.com/problemset/problem/1985/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20E%20-%20Secret%20Box)
|
||||
| 338 | 1985 F | Final Boss | [Question](https://codeforces.com/problemset/problem/1985/F) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20F%20-%20Final%20Boss)
|
||||
| 339 | 1985 G | D-Function | [Question](https://codeforces.com/problemset/problem/1985/G) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20G%20-%20D-Function)
|
||||
| 340 | 1986 A | X Axis | [Question](https://codeforces.com/problemset/problem/1986/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20A%20-%20X%20Axis)
|
||||
| 341 | 1986 B | Matrix Stabilization | [Question](https://codeforces.com/problemset/problem/1986/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20B%20-%20Matrix%20Stabilization)
|
||||
| 342 | 1986 C | Update Queries | [Question](https://codeforces.com/problemset/problem/1986/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20C%20-%20Update%20Queries)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user