output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; long long check(long long n, long long m, long long x, long long y) { return x >= 0 && x < n && y >= 0 && y < m; } void pr() { cout << '\n'; } template <class A, class... B> void pr(const A &a, const B &...b) { cout << a << (sizeof...(b) ? " " : ""); pr(b...); } templ...
### Prompt Please formulate a CPP solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, mod = 1e9 + 7; int h, c, t; long double get(int x) { long double cur = ((x / 2) + (x % 2)) * 1ll * h + (x / 2) * 1ll * c; cur /= x; return cur; } int main() { int tc = 1; scanf("%d", &tc); for (int cn = 1; cn <= tc; cn++) { scanf("%d%...
### Prompt Please provide a cpp coded solution to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int h, c, T; cin >> h >> c >> T; if (h == T) { cout << 1 << endl; continue; } else if ((h + c) >= 2 * T) { cout << 2 << endl; } else { long long int x, y; ...
### Prompt Develop a solution in cpp to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; int main() { int T, c, h, t; cin >> T; while (T--) { cin >> h >> c >> t; if (2 * t <= h + c) cout << "2" << endl; else { if (t == h) cout << "1" << endl; else { double n; n = (double)(h - t) / (2 * t - h - c); ...
### Prompt Construct a cpp code solution to the problem outlined: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep ba...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &n) { n = 0; T f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1, c = getchar(); while (isdigit(c)) n = n * 10 + c - '0', c = getchar(); n *= f; } template <typename T> void write(T...
### Prompt Please create a solution in Cpp to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; template <typename T> void write(vector<T> &a) { for (auto it = a.begin(); it != a.end(); it++) cout << *it << " "; cout << "\n"; } void random(long long int nMin, long long int nMax, long long int n) { srand(time(0)); for (long long int i = 0; i < n; i++) { dou...
### Prompt Please create a solution in Cpp to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; void solve() { long long h, c, t; cin >> h >> c >> t; double ans = h - t; long long taken = 1; if (abs((h + c + 0.0) / 2 - t) <= ans) { ans = abs((h + c + 0.0) / 2 - t); taken = 2; } double y = (h - t + 0.0) / (2 * t - (h + c)); ...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; int main() { int T; long long h, c, t, lo, hi, mid, l; scanf("%d", &T); for (int tc = 0; tc < T; tc++) { scanf("%lld%lld%lld", &h, &c, &t); if ((t << 1) <= h + c) printf("2\n"); else { lo = 0; hi = 500005; while ((hi - lo) > 1) { ...
### Prompt Construct a Cpp code solution to the problem outlined: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep ba...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9; const long long mod = 1e9 + 7; vector<bool> prime(MAX, 1); vector<int> spf(MAX, 1), primes; void sieve() { prime[0] = prime[1] = 0; spf[2] = 2; for (long long i = 4; i < MAX; i += 2) { spf[i] = 2; prime[i] = 0; } primes.push_back(2...
### Prompt Construct a cpp code solution to the problem outlined: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep ba...
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") using namespace std::chrono; using namespace std; long long mul(long long a, long long b, long long m = 1000000007) { long long res = 0; a = a % m; while (b > 0) { if (b % 2 == ...
### Prompt Construct a CPP code solution to the problem outlined: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep ba...
#include <bits/stdc++.h> using namespace std; mt19937_64 mt(time(0)); long long gcd(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b % a, a); } pair<long long, long long> get_res(long long a, long long b, long long n, long long c) { long lo...
### Prompt In Cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long c, h; cin >> h >> c; long long y; cin >> y; if (y >= h) { cout << 1 << endl; } else if (2 * y <= (c + h)) { cout << 2 << endl; } else { long long a = (2 * y) ...
### Prompt Generate a CPP solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barrel;...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; const double eps = 2e-6; int h, c, t; double f(ll i) { return abs(t - (h * (i + 1) + c * i) / (2.0 * i + 1)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { cin >...
### Prompt Develop a solution in CPP to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; float h, c, t; float helper(int a) { return (a * h + (a - 1) * c) / (2 * a - 1); } void solve() { cin >> h >> c >> t; if (t == h) { cout << "1\n"; return; } if (t <= (h + c) / 2) { cout << 2 << "\n"; return; } long long int low = 1LL, high = 1e9;...
### Prompt Create a solution in Cpp for the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barre...
#include <bits/stdc++.h> using namespace std; const long double asize = 1005; long double c, h, t, m, two = 2.0, three = 3.0, x; long double hotonbase(long double v) { long double cups = 1 + (2 * v), total = (h + c) * v + h; return total / cups; } long double bs() { long double ans = 0; for (int i = 61; i >= 0;...
### Prompt Your challenge is to write a cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; void solve() { long long h, c, t; cin >> h >> c >> t; if ((h + c) / 2 >= t) { cout << 2 << '\n'; return; } long long k = 2 * ((t - h) / (h + c - 2 * t)) + 1; long long val2 = abs((k + 2) / 2 * c + (k + 3) / 2 * h - t * (k + 2)) * k; long long val1 = ab...
### Prompt Please provide a CPP coded solution to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long h, c, t; long double calc(long long x) { long double th = x * h + x * c; th /= (2 * x); return abs(th - t); } long long ternary_search(long long lo, long long hi) { while (lo < hi - 2) { long long m1 = (lo * 2 + hi) / 3; ...
### Prompt Please provide a cpp coded solution to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; using ll = long long; double h, c, t; double f(ll i) { return (ll((i + 1) / 2) * h + ll(i / 2) * c) / (double)i; } void solve() { cin >> h >> c >> t; if (t >= h) { cout << 1 << endl; return; } if (t <= (h + c) / 2) { cout << 2 << endl; return; } ...
### Prompt In Cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int h, c, t; cin >> h >> c >> t; if (t <= c) { cout << 2 << "\n"; continue; } if (t >= h) { cout << 1 << "\n" << "\n"; continue; } double val1, val2, val3, x; ...
### Prompt Create a solution in CPP for the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barre...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { double h, c, tt; cin >> h >> c >> tt; if (2 * tt <= h + c) { cout << "2" << "\n"; continue; } long long r = (h - tt) / (2 * tt - h - c); long long s = r + 1; double r1...
### Prompt Create a solution in Cpp for the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barre...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long tt; cin >> tt; while (tt--) { float h, c, t, tot, x2; float d1 = 0.0, d2 = 0.0, a = 0.0, min = 100000000, diff = 0; long long i; cin >> h >> c >> t; a ...
### Prompt Your challenge is to write a cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; const long long INF = 1e17 + 7; const long long mod = 1e9 + 7; int main() { long long t; cin >> t; while (t--) { double h, c, t; cin >> h >> c >> t; double k = (h + c) / 2; if (t <= k) { cout << 2 << "\n"; } else ...
### Prompt Construct a CPP code solution to the problem outlined: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep ba...
#include <bits/stdc++.h> using namespace std; double h, c, t; inline double avg(long long m) { return (m * h + (m - 1) * c) / (2 * m - 1); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long tc; cin >> tc; while (tc--) { cin >> h >> c >> t; if (t == h) { cout << "1\n...
### Prompt Please create a solution in cpp to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; bool comp(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } bool comps(const pair<int, int> &a, const pair<int, int> &b) { if (a.second == b.second) return a.first < b.first; return a....
### Prompt Please formulate a cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; void solve() { int h, c, t; cin >> h >> c >> t; if ((h + c) / 2 >= t) { cout << 2 << '\n'; return; } int a = h - t; int b = 2 * t - h - c; int k = 2 * (a / b) + 1; long long val1 = abs(k / 2 * 1ll * c + (k + 1) / 2 * 1ll * h - t * 1ll * k); long lo...
### Prompt Develop a solution in Cpp to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; const long long Mod = 1e9 + 7; const int N = 1000; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int numCases = 1; cin >> numCases; for (int caseNo = 1; caseNo <= numCases; caseNo++) { long long h, c, t; cin >> h >> c >> t; ...
### Prompt Develop a solution in CPP to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; using ll = long long; double h, c, t; double f(ll i) { return (ll((i + 1) / 2) * h + ll(i / 2) * c) / (double)i; } void solve() { cin >> h >> c >> t; if (t >= h) { cout << 1 << endl; return; } if (t <= (h + c) / 2) { cout << 2 << endl; return; } ...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; void solve() { double a, b, c; cin >> a >> b >> c; double x = (a + b) - c - c; double y = -c + b; x = abs(x); y = abs(y); double hihi = abs(c - ((a + b) / 2.0)); double haha = abs(c - (max(ceil(y / x), 1.0) * a + (max(ceil(y / x), 1.0) - 1) * b) / ...
### Prompt Your challenge is to write a CPP solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; const int inf = 0x7FFFFFFF; const long long mod = (0 ? 1000000007 : 998244353); const double eps = 1e-7; const long long llinf = 4223372036854775807; inline void out(long long a) { if (a) cout << "Yes" << endl; else cout << "No" << endl; } void work() { double...
### Prompt Construct a cpp code solution to the problem outlined: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep ba...
#include <bits/stdc++.h> using namespace std; void solve() { float h, c, t; cin >> h >> c >> t; if (t >= h) { cout << "1\n"; return; } else if (2 * t <= (h + c)) { cout << "2\n"; return; } else { int val = (h - t) / (2 * t - h - c); float t1 = ((val + 1) * h + val * c) / (2 * val + 1);...
### Prompt Please provide a Cpp coded solution to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tst, h, c, t; cin >> tst; while (tst--) { cin >> h >> c >> t; if (t <= (h + c) / 2) cout << 2 << '\n'; else { long long t1 = (long long)ceil((h - t) / ((2 *...
### Prompt Create a solution in cpp for the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barre...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int h, c, t; cin >> h >> c >> t; long long res1 = 0, res2 = 0; if (h + c - 2 * t >= 0) cout << 2 << endl; else { int a = h - t; int b = 2 * t - c - h; int k = 2 * (a / b) + 1; ...
### Prompt In cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { double h, c, x; cin >> h >> c >> x; double lw = (h + c) / 2.0; if (x <= lw) { cout << 2 << '\n'; continue; } int l = -1, r = h; int mn = 0; ...
### Prompt Your task is to create a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitel...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int q; cin >> q; while (q--) { double t, h, c; cin >> h >> c >> t; if (h == t) { cout << 1 << '\n'; } else if (h + c == 2 * t) { cout << 2 << '\n'; } else { ...
### Prompt Generate a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barrel;...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long int x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) {...
### Prompt Please create a solution in Cpp to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int n, long long int m) { long long int res = 1; while (n > 0) { if (n & 1) res = (res * x) % m; x = (x * x) % m; n = n >> 1; } return res; } long long int maxSubsetSum(vector<long long int> v) { long long...
### Prompt Please create a solution in CPP to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; int main() { long long tt; cin >> tt; label: while (tt--) { long long h, c, t; cin >> h >> c >> t; if (h == t) { cout << 1 << "\n"; goto label; } long long x; long double answer; long long ans; if (double(h - t) <= abs((h + ...
### Prompt Generate a CPP solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barrel;...
#include <bits/stdc++.h> using namespace std; const long long N = 200005; bool col2(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.second == p2.second) return p1.first > p2.first; return p1.second > p2.second; } struct comp { bool operator()(long long const &x, long long const &y) { return...
### Prompt Please provide a Cpp coded solution to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; const long long int INF = (long long int)1e18; const long long int MOD = (long long int)1e9 + 7; const long long int maxn = (long long int)2e5 + 10, L = 23; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int T; cin >> T; while (T--) { ...
### Prompt Please formulate a CPP solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { double h, c, t; cin >> h >> c >> t; long long ans = 0; long long l = 0; long long r = 1000000; long long diff = 10000000000; double cnt = 100000000.100; while (l <= r) { long long mid = ...
### Prompt Please create a solution in cpp to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> long long int mod = 1e9 + 7; using namespace std; const long long int INF = 1e18; const long long int MAX = 2e5 + 10; long long int power(long long int a, long long int b) { if (b == 0) return 1; long long int num = 1; long long int m = mod + 2; while (b != 1) { if (b % 2 == 0) { ...
### Prompt Generate a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barrel;...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; double h, c, t; while (n--) { long long ans = 0; cin >> h >> c >> t; if (t <= ((h + c) / 2.0)) cout << "2\n"; else { long long k = ((h - t) / ((2.0 * t) - h - c)); double ck1 = abs(((dou...
### Prompt Your task is to create a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitel...
#include <bits/stdc++.h> using namespace std; int T; int h, c, t; int main() { scanf("%d", &T); while (T--) { scanf("%d%d%d", &h, &c, &t); if (t * 2 <= (h + c)) printf("%d\n", 2); else { long long lef = (h - t) / (2 * t - (h + c)); double a1 = (1.0 * h * (lef + 1) + c * lef) / (2 * lef...
### Prompt In cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 1010; int T; int h, c, t; int main() { cin >> T; while (T--) { cin >> h >> c >> t; if ((double)t <= (double)(h + c) / 2.0) puts("2"); else { long long k = (long long)(h - t) / (2LL * t - h - c); long long v1 = abs(...
### Prompt Create a solution in Cpp for the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barre...
#include <bits/stdc++.h> using namespace std; long long T, h, c, t; signed main() { cin >> T; while (T--) { cin >> h >> c >> t; if (t + t <= h + c) { cout << 2 << endl; continue; } if (h <= t) { cout << 1 << endl; continue; } double ans = (h - t) / (t + t - h - c); ...
### Prompt Your task is to create a CPP solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitel...
#include <bits/stdc++.h> using namespace std; int main() { int _; cin >> _; while (_--) { long long h, c, t; cin >> h >> c >> t; if (h + c == 2 * t) { cout << 2 << endl; continue; } else { long long x = 1LL * (c - t) / (h + c - 2 * t); double t1 = 1.0 * (x * h + (x - 1) * c...
### Prompt In cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long inf = 0x3f3f3f3f3f3f3f3f; const int N = 2e5 + 10; int T; long long h, c, t; double cal(long long x) { return abs(1.0 * (h * x + c * (x - 1)) / (2 * x - 1) - 1.0 * t); } int main() { scanf("%d", &T); while (T--) { scanf("...
### Prompt Please formulate a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; long long h, c, t; double check(int cnt) { return ((double)cnt * (double)h + ((double)cnt - (double)1) * (double)c) / (2.0 * cnt - 1.0); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt; cin >> tt; while (tt--) { cin >> h >>...
### Prompt Please create a solution in CPP to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; long long h, c; long double x = 1.0; long double get(long long moves) { long double x = 1.0; return c + ((moves) / (2 * moves - 1.0)) * (h * x - c * x); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, t, m, y, z, temp; cin >> t; wh...
### Prompt In Cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846; long long gcd(long long a, long long b) { long long temp; if (a < b) { temp = b; b = a; a = temp; } if (a % b == 0) { return b; } return gcd(b, a % b); } long long modu(long long a, long long b) { if (a...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; int solve() { double h, c, t; cin >> h >> c >> t; if (t <= (c + h) / 2) return 2; int k = (h - t) / ((2 * t) - h - c); double tk1 = ((k * (h + c)) + h) / ((2 * k) + 1); double tk2 = (((k + 1) * (h + c)) + h) / ((2 * k) + 3); if (abs(t - tk1) <= abs(t - tk2)) r...
### Prompt Construct a Cpp code solution to the problem outlined: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep ba...
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); const long long dx[] = {0, 0, 1, -1}; const long long dy[] = {1, -1, 0, 0}; const long long N = (long long)1e6 + 17; const long long M = (long long)2e3 + 69; const long long inf = (long long)1e14 + 3; const long long mod = (long long)1e9 + 7; l...
### Prompt In Cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; bool f(int n, int h, int c, int t) { return (2 * n + 1ll) * abs(1ll * n * (h + c - 2 * t) + t - c) <= (2 * n - 1ll) * (1ll * n * (h + c - 2 * t) + h - t); } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long t = 1; cin >> t; while (t--)...
### Prompt Develop a solution in cpp to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> long long int mod = 1e9 + 7; using namespace std; const long long int INF = 1e18; const long long int MAX = 2e5 + 10; long long int power(long long int a, long long int b) { if (b == 0) return 1; long long int num = 1; long long int m = mod + 2; while (b != 1) { if (b % 2 == 0) { ...
### Prompt In Cpp, your task is to solve the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barr...
#include <bits/stdc++.h> using namespace std; inline long long ceil(long long a, long long b) { return (a + b - 1) / b; } long double h, c, tb; long double calc(long double x) { long double res = (x + 1) * h + x * c; res /= (2 * x + 1); res = abs(res - tb); return res; } void func() { cin >> h >> c >> tb; i...
### Prompt Your task is to create a cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitel...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; long long int T, t, n, m, h, c, ini, fin; double can, aux, can2; int main() { cin >> T; while (T--) { cin >> h >> c >> t; aux = t; if (t >= h) cout << 1 << "\n"; else { if (t <= ((h + c) / 2)) cou...
### Prompt Create a solution in Cpp for the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barre...
#include <bits/stdc++.h> using namespace std; int main() { long long T = 1; cin >> T; while (T--) { long long h, c, t; cin >> h >> c >> t; if (t == h) { cout << 1 << "\n"; continue; } if (2 * t <= (h + c)) { cout << 2 << "\n"; continue; } long long x = (t - c) /...
### Prompt Please create a solution in CPP to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep...
#include <bits/stdc++.h> using namespace std; class Time { chrono::high_resolution_clock::time_point start; public: Time() { start = chrono::high_resolution_clock::now(); } ~Time() { cout << "\nTime: " << chrono::duration_cast<chrono::duration<double>>( chrono::high_resolution_clock...
### Prompt Please provide a CPP coded solution to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; using ll = long long; double h, c, t; double f(ll i) { return (ll((i + 1) / 2) * h + ll(i / 2) * c) / (double)i; } void solve() { cin >> h >> c >> t; if (t >= h) { cout << 1 << endl; return; } if (t <= (h + c) / 2) { cout << 2 << endl; return; } ...
### Prompt Please provide a cpp coded solution to the problem described below: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; void solve() { long long int i, k, j, h, t, c; cin >> h >> c >> t; if (t == h) { cout << 1 << '\n'; return; } if (t == (h + c) / 2) { cout << 2 << '\n'; return; } if (t < (h + c) / 2) { cout << 2 << '\n'; return; } double n; n = (...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infin...
#include <bits/stdc++.h> using namespace std; int n, m, k; bool works(int n, int k) { if (!(n & 1) || k < 0) return 0; if (k < 2) return k ^ !(n & (n + 1)); if (n == 9 && k == 2) return 0; return 2 * k + 3 <= n; } void sol(int n, int k, int p) { int x = ++m; cout << p << (x > ::n ? '\n' : ' '); for (int i...
### Prompt Your challenge is to write a CPP solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> using namespace std; int n, k, a[100500], cnt = 1; bool A[5][5]; bool can(int i, int j) { if (j < 0 || j > i) return 0; if (i <= 4) return A[i][j]; if (((i + 1) & -(i + 1)) == (i + 1)) return j != 1 && j != i; return j != 0 && j != i; } void work(int st, int n, int k) { if (n == 0) re...
### Prompt Your task is to create a Cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child,...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long LINF = 1e18; const long long MOD = 1e9 + 7; template <typename T> T mul(T a, T b) { return (1LL * a * b) % MOD; } template <typename T> T add(T a, T b) { return (a + b) % MOD; } template <typename T> T sub(T a, T b) { return ((a - ...
### Prompt Your challenge is to write a CPP solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> using namespace std; int n, K, ans[100004]; int lowb(int x) { return x & -x; } int main() { scanf("%d%d", &n, &K); if (n % 2 == 0) return puts("NO"), 0; if (max(0, (n - 3) / 2) < K) return puts("NO"), 0; if (n == 9 && K == 2) return puts("NO"), 0; if (lowb(n + 1) == n + 1 && K == 1) r...
### Prompt Please create a solution in CPP to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> using namespace std; int ans[200010]; int main() { int a, b; cin >> a >> b; if (a % 2 == 0) { printf("NO"); return 0; } if (b == 0) { int k = a + 1; while (k % 2 == 0) k /= 2; if (k == 1) { printf("YES\n"); for (int i = 1; i <= a; i++) printf("%d ", i /...
### Prompt Your task is to create a Cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child,...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int ncnt; int anc[N], lg2[N]; bool Check(int n, int m) { if (n == 1 && m == 0) return true; if (m < 0 || n < 0) return false; if (n == 9 && m == 2) return false; if (((n + 1) & (-(n + 1))) == n + 1 && m == 1) return false; if (m == 0 && ((n...
### Prompt Your task is to create a cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child,...
#include <bits/stdc++.h> using namespace std; int n, k, lim, m, fa[110000]; bool check(int n) { n++; return n == (n & -n); } int main() { scanf("%d%d", &n, &k); lim = max((n - 3) / 2, 0); if (!(n & 1) || (k > lim) || (k == check(n)) || (n == 9 && k == 2)) { puts("NO"); return 0; } puts("YES"); m...
### Prompt In cpp, your task is to solve the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, fa[100005]; int f(int n) { n++; return (n ^ (n & -n)) > 0; } int g(int n) { return (n == 1) ? 0 : (n - 3) / 2; } void cover(int x, int p, int n) { fa[x] = p; if (n == 1) return; for (int k = 1; k <= n; k = k << 1 | 1) if ((k << 1 | 1) > (n -...
### Prompt Construct a CPP code solution to the problem outlined: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except f...
#include <bits/stdc++.h> using namespace std; const int nmax = 1e5 + 42; void wrong() { printf("NO\n"); exit(0); } bool off_one(int n) { return (n & (n + 1)) == 0; } int parent[nmax]; int low(int SZ, int LHS) { int RHS = SZ - 1 - LHS; int ret = 0; if (LHS >= 2 * RHS || RHS >= 2 * LHS) ret++; if (off_one(LHS...
### Prompt Construct a cpp code solution to the problem outlined: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except f...
#include <bits/stdc++.h> using namespace std; int n, k; int fa[100005]; bool is_bal(int n) { int x = __builtin_popcount(n); return (n == ((1 << x) - 1)); } bool check(int n, int k) { if (n % 2 == 0) return false; if (n == 1 && k == 0) return true; if (k > (n - 3) / 2) return false; if (k == 0 && !is_bal(n))...
### Prompt Construct a Cpp code solution to the problem outlined: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except f...
#include <bits/stdc++.h> using namespace std; const int SMALL = 100; vector<vector<int>> dp; bool check(int n, int k) { if (n % 2 == 0 || k < 0) return false; if (n < SMALL) { if (find(dp[n].begin(), dp[n].end(), k) == dp[n].end()) return false; } else if (n & (n + 1)) { if (k == 0 || k >= n / 2) return f...
### Prompt Your task is to create a Cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child,...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long inf = 1LL << 50; const int N = 100000; int cnt = 1; int children[N]; int pwrs[17]; void build(int curr, int k, int n) { if (n == 1) { return; } int lg = log2(n); if (pwrs[lg] * 2 - 1 == n && k == 0) { children[cnt++] = c...
### Prompt Please provide a CPP coded solution to the problem described below: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> using namespace std; int n, k, p[200001]; int low(int x) { return x & -x; } int check() { if (n % 2 == 0) return 0; if (n == 9 && k == 2) return 0; if (k > (n - 3) / 2) return 0; if (low(n + 1) == n + 1 && k == 1) return 0; if (low(n + 1) != n + 1 && k == 0) return 0; return 1; } in...
### Prompt Generate a CPP solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for on...
#include <bits/stdc++.h> using namespace std; vector<int> ans; const int mod = 1e9 + 7; bool hasSoln(int n, int k) { if ((n & 1) == 0) return false; if (k == 0 && (n & (n + 1)) != 0) return false; if (k == 1 && (n & (n + 1)) == 0) return false; if (n == 1 && k != 0) return false; if (n == 1 && k == 0) return ...
### Prompt Please provide a CPP coded solution to the problem described below: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
### Prompt In cpp, your task is to solve the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for...
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 10; int pr[sz], nu = 2; void f(int n, int k, int rt) { if (n > 1) { if (k == 0) { pr[nu] = rt, f(n / 2, k, nu++); pr[nu] = rt, f(n / 2, k, nu++); } else if (k == 1) { for (int x = 1;; x = x * 2 + 1) { int y = n - 1 - ...
### Prompt Develop a solution in Cpp to the problem described below: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> using namespace std; using namespace std; const int maxn = 100000 + 10; const int inf = 2000000000; int n, k; int vis[1 << 19]; inline int gao(int n, int k) { if (k < 0) return 0; if (k == 1) { return !vis[n]; } if (k == 0) { return vis[n]; } if (n == 9 && k == 2) return 0; ...
### Prompt Develop a solution in Cpp to the problem described below: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &num) { T x = 0, f = 1; char ch = getchar(); for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1; for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0'); num = x * f; } in...
### Prompt Please formulate a CPP solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> using namespace std; bool Right(int n, int k) { if (n % 2 == 0) return false; if (n == 1) return k == 0; bool pw2 = ((n + 1) & n) == 0; if (pw2 && k == 1) return false; if (!pw2 && k == 0) return false; if (k > (n - 3) / 2) return false; if (n == 9 && k == 2) return false; retur...
### Prompt Your task is to create a cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child,...
#include <bits/stdc++.h> using namespace std; bool isp2(int n) { while (n % 2 == 0) n /= 2; return n == 1; } int maxk(int n) { return (n - 3) / 2; } bool ok(int n, int k) { if (n < 0 || k < 0 || n % 2 == 0) return false; if (k == 0) { return isp2(n + 1); } if (k == 1) { return !isp2(n + 1); } re...
### Prompt Construct a Cpp code solution to the problem outlined: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except f...
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, k; void end() { puts("NO"); exit(0); } inline bool check(int x) { return x == (x & (-x)); } int fa[N]; int main() { scanf("%d%d", &n, &k); int lim = max(0, (n - 3) / 2); if (n % 2 == 0) end(); if (k > lim) end(); if (check(n + 1) &...
### Prompt Generate a cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for on...
#include <bits/stdc++.h> using namespace std; int n, k, ans[100050]; inline int qr() { char a = 0; int w = 1, np = 0; while (a < '0' || a > '9') { if (a == '-') w = -1; a = getchar(); } while (a <= '9' && a >= '0') { np = (np << 3) + (np << 1) + (a ^ 48); a = getchar(); } return np * w; } ...
### Prompt Construct a Cpp code solution to the problem outlined: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except f...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int mod = 1000000007; int lowbit(int x) { return x & (-x); } int fast_power(int a, int b) { int x; for (x = 1; b; b >>= 1) { if (b & 1) x = 1ll * x * a % mod; a = 1ll * a * a % mod; } return x % mod; } int n, m; int ans[100005]...
### Prompt Please create a solution in CPP to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } int n, k, f[100010]...
### Prompt Generate a CPP solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for on...
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 10; int par[maxN]; int n, k; bool isPower(int n) { int dd = (n + 1); return ((dd & (dd - 1)) == 0); } bool can[105][105]; bool ok(int n, int k) { if (n < 100) { if (!can[n][k]) { return false; } } else { if (k == 0) { i...
### Prompt Your challenge is to write a Cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> #pragma GCC Optimize(2) using namespace std; int n, k, id; inline int lowbit(int x) { return x & (-x); } inline bool isfull(int x) { return (x + 1) == lowbit(x + 1); } inline int lowerX(int x) { while (x != lowbit(x)) x -= lowbit(x); return x - 1; } inline int upperX(int x) { while (!isfu...
### Prompt In cpp, your task is to solve the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for...
#include <bits/stdc++.h> using namespace std; const unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); mt19937 rnd(seed); const int MOD = 998244353; void dp(vector<int> &res, int k, int s, int e, int p) { if (s > e) return; int num = e - s + 1; res[s] = p; if (num == 1) return; i...
### Prompt Please formulate a Cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> const int MAXN = 100005; using namespace std; int pa[MAXN], is_bal[MAXN]; vector<int> bal; int exist(int n, int k) { if (n % 2 == 0) return 0; if (n == 9 && k == 2) return 0; if (n == 1) return k == 0; if (k >= n / 2) return 0; if (is_bal[n]) return k != 1; return k != 0; } void bui...
### Prompt Generate a cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for on...
#include <bits/stdc++.h> using namespace std; int n, k; inline bool check(int n, int k) { if (n % 2 == 0) return false; if (k == 0) return !(n & (n + 1)); if (k == 1) return n & (n + 1); if (n == 9 && k == 2) return false; return k > 0 && k <= max(0, (n - 3) / 2); } int cnt; void dfs(int n, int k, int fa) { ...
### Prompt Please formulate a Cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> using namespace std; bool Right(int n, int k) { if (n % 2 == 0) return false; if (n == 1) return k == 0; bool pw2 = ((n + 1) & n) == 0; if (pw2 && k == 1) return false; if (!pw2 && k == 0) return false; if (k > (n - 3) / 2) return false; if (n == 9 && k == 2) return false; retur...
### Prompt Your task is to create a CPP solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child,...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 100; const long long mod = 1e9 + 7; const long long inf = 1e18; long long t, a[maxn]; bool isp[maxn]; bool ok(long long x, long long y) { if (x == 1 && y == 0) return 1; if (x % 2 == 0) return 0; if (y > (x - 3) / 2) return 0; if (x == 9...
### Prompt Your challenge is to write a cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> using namespace std; bool pt(int n) { return !(n & (n - 1)); } bool check(int n, int k) { if (n <= 0 or n % 2 == 0 or k < 0) return false; if (n <= 3) return k == 0; if (n == 5) return k == 1; if (n == 7) return k == 0 or k == 2; if (n == 9) return k == 1 or k == 3; return k <= (n -...
### Prompt Your challenge is to write a cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> const int MAXN = 1e5; int n, K, fa[MAXN + 5]; int main() { scanf("%d %d", &n, &K); if (!(n & 1)) return puts("NO"), 0; if (!K) { if (n & (n + 1)) return puts("NO"), 0; puts("YES"); for (int i = 1; i <= n; ++i) printf("%d%c", i >> 1, i ^ n ? ' ' : '\n'); return 0; } if ...
### Prompt Generate a CPP solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for on...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, mod = 998244353; template <class o> inline void qr(o &x) { x = 0; char c = getchar(); int f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + (c ^ 48); c = ...
### Prompt Please create a solution in Cpp to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, excep...
#include <bits/stdc++.h> using namespace std; const int chtholly = 0; const int N = 30; bool v[N][N]; int n; using pii = pair<int, int>; void construct(int n, int tar, int par, int val) { int j, k, l; bool pass = false; pii tar_1, tar_2; cout << par << " "; if (n == 1) { return; } else if (n <= N) { ...
### Prompt Create a solution in CPP for the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for ...
#include <bits/stdc++.h> using namespace std; mt19937_64 rng( (unsigned)chrono::system_clock::now().time_since_epoch().count()); const long double PI = acosl(-1); const int nmax = 1e5 + 10; inline bool isTwo(int x) { return x == (x & -x); } int parent[nmax]; int nodecnt = 0; void build(int n, int imbalance, int par...
### Prompt Create a solution in cpp for the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for ...
#include <bits/stdc++.h> using namespace std; int n, k, w; void v(int a) { cout << a << " "; } void t(int a, int b) { for (int i = a + 1; i <= b; i++) v(a + (i - a - 1) / 2); } void solve(int db, int p, int f) { v(f); if (db < 2) t(p, n); else { if (db == 3 && n - p == 10) t(p, p + 6), t(p + 6, p ...
### Prompt Construct a cpp code solution to the problem outlined: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except f...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5, M = 50 + 5; const long long INF = 1e18 + 5; inline long long read() { long long sum = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fh = -1; c = getchar(); } while (c >= '0' && c <= '9') { sum = sum * ...
### Prompt Your task is to create a Cpp solution to the following problem: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child,...
#include <bits/stdc++.h> using namespace std; int n, k; int s[100005], si[100005]; int main() { scanf("%d%d", &n, &k); if (n % 2 == 0) { puts("NO"); return 0; } if (n == 1 && k == 0) { puts("YES"); puts("0"); return 0; } int tmp = (n - 3) / 2; if (tmp < k) { puts("NO"); return ...
### Prompt Please provide a cpp coded solution to the problem described below: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...
#include <bits/stdc++.h> using namespace std; const int N = 100005; bool mark[N]; int full_binary[N]; bool small[10][4]; int ans[N], cnt; bool valid(int n, int k) { if (k < 0) return false; if (n % 2 == 0) return false; if (n == 1 && k == 0) return true; if (k > (n - 3) / 2) { return false; } if (n <= 9...
### Prompt Please provide a Cpp coded solution to the problem described below: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one ch...