Untitled
unknown
plain_text
a year ago
2.8 kB
9
Indexable
#include<bits/stdc++.h> using namespace std; #define int long long typedef long long ll; #define double long double typedef vector<int> vi; typedef vector<vector<int>> vvi; // ------------------------MeMe-----------------------// int compare(double a, double b) { double eps = 1e-12; if (abs(a - b) < eps) return 0; if (a > b) return 1; else return -1; } void code() { int t1, t2, x1, x2; double t0; cin >> t1 >> t2 >> x1 >> x2 >> t0; vector<int> ans = {-1, -1}; double mn = 1e13; for (int a = 0 ; a <= x1 ; a++) { int l = 0 , r = x2; double curr = 1e13; int who = -1; int who_cost; while(l <= r) { int m = (l + r) / 2; int b = m; double cost = (a * t1 + b * t2) / (double) (a + b); if (compare(cost, t0) >= 0) { curr = min(curr, cost - t0); if (compare(curr, mn) == -1) { mn = curr; ans = {a, b}; } if (compare(curr, mn) == 0) { if (a + b >= ans[0] + ans[1]) ans = {a, b}; } who = b; who_cost = cost; r = m - 1; } else l = m + 1; } { if (who == -1) continue; int l = who , r = x2; while(l <= r) { int m = (l + r) / 2; int b = m; double cost = (a * t1 + b * t2) / (double) (a + b); if (cost == who_cost) { curr = min(curr, cost - t0); if (compare(curr, mn) == -1) { mn = curr; ans = {a, b}; } if (compare(curr, mn) == 0) { if (a + b >= ans[0] + ans[1]) ans = {a, b}; } l = m + 1; } else { r = m - 1; } } } } cout << ans[0] <<" " << ans[1] << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("err.txt", "w", stderr); #endif int tt = 1; // cin >> tt; for (int tn = 1 ; tn <= tt ; tn++) { #ifndef ONLINE_JUDGE cout << "_________Test_" << tn << "_________" << endl; cerr << "_________Test_" << tn << "_________" << endl; #endif code(); } #ifndef ONLINE_JUDGE cout << "________________________" ; cerr << "________________________" ; #endif return 0; }
Editor is loading...
Leave a Comment