Add solutions for Codeforces problems 1971A, 1971B, 1971C, 1971D, 1971E, and 1971F

This commit is contained in:
ShazidMahsrafi 2024-05-11 15:30:27 +06:00
parent a7ff9b4015
commit 0ce34aa47e
7 changed files with 216 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#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 x,y;
cin>>x>>y;
cout<<min(x,y)<<" "<<max(x,y)<<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();
}
}

View File

@ -0,0 +1,35 @@
#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()
{
string s;
cin>>s;
bool ok=0;
for(int i=1; i<s.size(); ++i)
{
if(s[i]!=s[0])
{
swap(s[i],s[0]);
ok=1;
break;
}
}
if(ok) cout<<"YES\n"<<s<<endl;
else cout<<"NO\n";
}
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();
}
}

View 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()
{
ll a,b,c,d;
cin>>a>>b>>c>>d;
int ct=0;
for(int i=min(a,b); i<=max(a,b); ++i)
{
if(i==c || i==d) ct++;
}
if(ct & 1) cout<<"YES\n";
else cout<<"NO\n";
}
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();
}
}

View 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()
{
string s;
cin>>s;
ll ans=1, f=0;
for(int i=1; i<s.size(); ++i)
{
ans += (s[i] != s[i-1]);
f |= (s[i]=='1' && s[i-1]=='0');
}
cout<<ans-f<<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();
}
}

View File

@ -0,0 +1,42 @@
#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,k,q;
cin>>n>>k>>q;
vector<ll>a(k+1),b(k+1);
a[0]=b[0]=0;
for(int i=1; i<=k; ++i) cin>>a[i];
for(int i=1; i<=k; ++i) cin>>b[i];
while(q--)
{
ll d;
cin>>d;
ll ind=lower_bound(a.begin(),a.end(),d) - a.begin();
if(a[ind]==d) cout<<b[ind]<<" ";
else
{
ll dist=a[ind]-a[ind-1];
ll time=b[ind]-b[ind-1];
ll x=d-a[ind-1];
cout<<((x*time)/dist)+b[ind-1]<<" ";
}
}
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();
}
}

View File

@ -0,0 +1,49 @@
#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;}
ll points(ll r)
{
ll p = 0;
for(ll x = 0; x <= r; ++x)
{
ll y,d = (r + 1) * (r + 1) - x * x;
ll l = 0, h = r;
while(l <= h)
{
ll mid = l + (h - l) / 2;
if(mid * mid < d)
{
y = mid;
l = mid + 1;
}
else h = mid - 1;
}
if(x == 0) p += (y * 2 + 1);
else p += ((y * 2 + 1) * 2);
}
return p;
}
void solve()
{
ll r;
cin >> r;
ll p1 = points(r);
ll p2 = points(r - 1);
cout << p1 - p2 << 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();
}
}

View File

@ -319,6 +319,12 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
| 307 | 1968 G1 | Division + LCP (easy version) | [Question](https://codeforces.com/problemset/problem/1968/G1) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20G1%20-%20Division%20+%20LCP%20(easy%20version)) | 307 | 1968 G1 | Division + LCP (easy version) | [Question](https://codeforces.com/problemset/problem/1968/G1) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20G1%20-%20Division%20+%20LCP%20(easy%20version))
| 308 | 1969 A | Two Friends | [Question](https://codeforces.com/problemset/problem/1969/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20A%20-%20Two%20Friends) | 308 | 1969 A | Two Friends | [Question](https://codeforces.com/problemset/problem/1969/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20A%20-%20Two%20Friends)
| 309 | 1969 B | Shifts and Sorting | [Question](https://codeforces.com/problemset/problem/1969/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20B%20-%20Shifts%20and%20Sorting) | 309 | 1969 B | Shifts and Sorting | [Question](https://codeforces.com/problemset/problem/1969/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20B%20-%20Shifts%20and%20Sorting)
| 310 | 1971 A | My First Sorting Problem | [Question](https://codeforces.com/problemset/problem/1971/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20A%20-%20My%20First%20Sorting%20Problem)
| 311 | 1971 B | Different String | [Question](https://codeforces.com/problemset/problem/1971/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20B%20-%20Different%20String)
| 312 | 1971 C | Clock and Strings | [Question](https://codeforces.com/problemset/problem/1971/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20C%20-%20Clock%20and%20Strings)
| 313 | 1971 D | Binary Cut | [Question](https://codeforces.com/problemset/problem/1971/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20D%20-%20Binary%20Cut)
| 314 | 1971 E | Find the Car | [Question](https://codeforces.com/problemset/problem/1971/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20E%20-%20Find%20the%20Car)
| 315 | 1971 F | Circle Perimeter | [Question](https://codeforces.com/problemset/problem/1971/F) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20F%20-%20Circle%20Perimeter)