text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { cout.precision(16); double prev = 0; double n, a, d; cin >> n >> a >> d; int i; for (i = 0; i < n; ++i) { double t, v; cin >> t >> v; double p = v / a; double q = 0.5 * a * p * p; double r = d - q; double s = 0; if (r >= 0) { s = (d - q) / v; } else { p = sqrt((2.0 * d) / a); } t += p; t += s; if (prev > t) { t = prev; } cout << t << endl; prev = t; } return 0; }
#include <bits/stdc++.h> using namespace std; struct xx { double t, v; int id; } a[110000]; double f(double v, double dv, double d) { int i, j, k; double t1, s1, s2, t2, s; t1 = v / dv; s = 1 / 2.0 * dv * t1 * t1; if (s <= d) t1 += (d - s) / v; else { t1 = sqrt(2 * d / dv); } return t1; } int main() { int i, j, k, m, n; double fg, js, d, s, t, dv; while (scanf("%d%lf%lf", &n, &dv, &d) != EOF) { for (i = 1; i <= n; i++) { scanf("%lf%lf", &a[i].t, &a[i].v); a[i].id = i; } fg = f(a[1].v, dv, d) + a[1].t; printf("%.10lf\n", fg); for (i = 2; i <= n; i++) { t = f(a[i].v, dv, d) + a[i].t; printf("%.10lf\n", max(fg, t)); fg = max(fg, t); } } }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, d; cin >> n >> a >> d; double prevTime = 0; for (int i = 0; i < n; i++) { int t, v; cin >> t >> v; double tm = (v + 0.0) / a; double dist = 0.5 * a * tm * tm; if (dist >= d) { tm = sqrt(2.0 * d / a); } else { tm += (d - dist) / v; } tm += t; tm = max(prevTime, tm); printf("%.8f\n", tm); prevTime = max(prevTime, tm); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef struct _Bus { double v, t; _Bus(double v, double t) { this->v = v; this->t = t; } _Bus() {} } Bus; int n; double a, d; Bus bus[100100]; double getMaxSpeedWhen(Bus b) { return b.v / a; } double lengthWhenMaxSpeed(Bus b) { double t = getMaxSpeedWhen(b); return 0.5f * a * t * t; } double timeToArrive(Bus b) { double t = getMaxSpeedWhen(b); double length = d - lengthWhenMaxSpeed(b); if (length <= 0) return sqrt(2.0f * d / a) + b.t; return length / b.v + t + b.t; } int main() { scanf("%d %lf %lf", &n, &a, &d); for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) { double v, t; scanf("%lf %lf", &t, &v); bus[i] = Bus(v, t); } double prevAns = timeToArrive(bus[0]); for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) { double ans = timeToArrive(bus[i]); if (prevAns >= ans) ans = prevAns; else prevAns = ans; printf("%.11lf\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int n; double a, d; double t[1000005], v[1000005]; double ans[1000005]; int main() { int i; scanf("%d%lf%lf", &n, &a, &d); for (i = 0; i < n; i++) { scanf("%lf%lf", &t[i], &v[i]); if (v[i] * v[i] / (2 * a) >= d) ans[i] = sqrt(2.0 * d / a) + t[i]; else ans[i] = v[i] / a + (d - v[i] * v[i] / (2.0 * a)) / v[i] + t[i]; } for (i = 1; i < n; i++) { if (ans[i] < ans[i - 1]) ans[i] = ans[i - 1]; } for (i = 0; i < n; i++) printf("%.10f\n", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; int t[200000]; int v[200000]; double ans[200000]; int main() { int n, a, d; cin >> n >> a >> d; for (int(i) = (0); (i) < (n); ++(i)) cin >> t[i] >> v[i]; for (int(i) = (0); (i) < (n); ++(i)) { double t1 = (v[i] + 0.0) / (a + 0.0); double t2 = (d - a * t1 * t1 * 0.5) / (v[i] + 0.0); if (a * t1 * t1 * 0.5 >= d) { t1 = sqrt(2.0 * d / (a + 0.0)); t2 = 0; } double tt = t1 + t2; if (i == 0) ans[i] = t[i] + tt; else { double l = t[i], r = t[i] + tt; if (r > ans[i - 1]) ans[i] = r; else ans[i] = ans[i - 1]; } } for (int(i) = (0); (i) < (n); ++(i)) printf("%.6f\n", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i < j); } double n, a, d; vector<pair<pair<double, double>, int> > ttv; double tv[2][100001]; double ret[100001]; int main() { cin >> n >> a >> d; for (int i = 0; i < n; ++i) { scanf("%lf%lf", &tv[0][i], &tv[1][i]); ttv.push_back(make_pair(make_pair(tv[0][i], tv[1][i]), i)); } sort(ttv.begin(), ttv.end()); double t = ttv[0].first.second / a, bf; if (a * t * t / 2.0 > d) t = ttv[0].first.first + sqrt(d * 2.0 / a); else t = ttv[0].first.first + t + (d - (a * t * t / 2.0)) / ttv[0].first.second; ret[ttv[0].second] = t; bf = t; for (int i = 1; i < n; ++i) { double ti = ttv[i].first.first, v = ttv[i].first.second; t = v / a; if (a * t * t / 2.0 > d) t = ti + sqrt(d * 2.0 / a); else t = ti + t + (d - (a * t * t / 2.0)) / v; if (t >= bf) ret[ttv[i].second] = t; else ret[ttv[i].second] = bf; bf = max(t, bf); } for (int i = 0; i < n; ++i) printf("%.10lf\n", ret[i]); return 0; }
#include <bits/stdc++.h> int n; double a, l; using namespace std; pair<int, int> ar[1000007]; double MAX(double a, double b) { if (a > b) return a; return b; } int main() { cin >> n >> a >> l; double onceki = -100; double lim, gky, t; for (int i = 1; i <= n; i++) { scanf(" %d %d", &ar[i].first, &ar[i].second); t = ar[i].first; gky = (l - ((ar[i].second / a)) * ((ar[i].second / 2.0))); if (gky <= 0) { t += sqrt((2 * l) / a); } else { t += ar[i].second / a; t += gky / ar[i].second; } printf("%.10lf\n", MAX(t, onceki)); onceki = MAX(onceki, t); } return 0; }
#include <bits/stdc++.h> const long long mod = 1e9 + 7; using namespace std; inline int read() { register int x = 0, f = 1, ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long double f[100005]; int32_t main() { int n, a, d; scanf("%d%d%d", &n, &a, &d); for (int i = 1; i <= n; i++) { long double t, v; cin >> t >> v; if (v * v / 2.0 / a < d * 1.0) f[i] = d / v - v / 2.0 / a + v / a + t; else f[i] = sqrt(2.0 * d / a) + t; if (i > 1 && f[i] < f[i - 1]) { f[i] = f[i - 1]; } } for (int i = 1; i <= n; i++) { printf("%.10Lf\n", f[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; struct Trolley { long long int time, velocity, index; bool operator<(const Trolley& other) const { return time < other.time; } }; long double tiempo_de_llegar(Trolley& trolley, long double distance, long double acc) { long double tiempo = sqrt(2 * distance / acc); if (tiempo * acc <= trolley.velocity) { return tiempo; } else { return (long double)trolley.velocity / acc + (long double)distance / (long double)trolley.velocity - (long double)trolley.velocity / (2 * acc); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int a, d; cin >> a >> d; vector<Trolley> trolleys(n); for (long long int i = 0; i < n; i++) { cin >> trolleys[i].time >> trolleys[i].velocity; trolleys[i].index = i; } sort(trolleys.begin(), trolleys.end()); vector<long double> tiempos(n); long double tiempo_anterior = 0; for (long long int i = 0; i < trolleys.size(); i++) { long double tiempo = tiempo_de_llegar(trolleys[i], d, a); tiempo += trolleys[i].time; tiempo = max(tiempo, tiempo_anterior); tiempos[trolleys[i].index] = tiempo; tiempo_anterior = tiempo; } for (long long int i = 0; i < tiempos.size(); i++) { cout << fixed << setprecision(6); cout << tiempos[i] << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int i, n, t[100005], v[100005], ac, dist; double rs[100005]; double getTime(double start, double vMax, double dist, double acc) { double tmToV = vMax / acc; double distV = 0.5 * acc * tmToV * tmToV; if (distV >= dist) { double t = sqrt(2.0 * dist / acc); return start + t; } return start + (dist - distV) / vMax + tmToV; } int main() { ios_base::sync_with_stdio(0); cin >> n >> ac >> dist; for (i = 1; i <= n; ++i) cin >> t[i] >> v[i]; for (i = 1; i <= n; ++i) rs[i] = getTime(t[i], v[i], dist, ac); for (i = 2; i <= n; ++i) rs[i] = max(rs[i], rs[i - 1]); for (i = 1; i <= n; ++i) cout << setprecision(5) << fixed << rs[i] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, a, d, t, v; double ans[100010]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a >> d; for (int i = 1; i <= n; i++) { cin >> t >> v; double p = sqrt(2.0 * a * d); if (p <= v) ans[i] = t + p / a; else { ans[i] = t + 1.0 * v / a + (d - 1.0 * v * v / a / 2) / v; } } for (int i = 2; i <= n; i++) ans[i] = max(ans[i], ans[i - 1]); for (int i = 1; i <= n; i++) printf("%.12lf\n", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int a; int d; cin >> n >> a >> d; vector<int> t; vector<int> v; vector<double> vres; for (int i = 0; i < n; i++) { int it, iv; cin >> it >> iv; t.push_back(it); v.push_back(iv); } for (int i = 0; i < n; i++) { double vr = 0.0; double pt = (double)v[i] / a; double ps = (double)v[i] * pt / 2; if (ps > (double)d) { double pvp = sqrt((double)a * d * 2); vr = t[i] + pvp / a; } else { double pss = d - ps; double ptt = pss / v[i]; vr = t[i] + pt + ptt; } if (i > 0 && vr < vres[i - 1]) { vr = vres[i - 1]; } vres.push_back(vr); } for (int i = 0; i < n; i++) { cout << vres[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char *sdbg, TH h, TA... t) { while (*sdbg != ',') { cerr << *sdbg++; } cerr << "=" << h << ","; _dbg(sdbg + 1, t...); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); } vector<string> split(string s) { istringstream buf(s); istream_iterator<string> beg(buf), end; vector<string> list(beg, end); return list; } bool isvowel(char c) { string s = "aeiouAEIOU"; if (find(s.begin(), s.end(), c) != s.end()) return true; return false; } vector<long long> sieve(long long n) { vector<bool> prime(n + 1, true); prime[0] = prime[1] = 0; for (int i = 2; i * i <= n; i++) { if (prime[i]) for (int j = i * i; j <= n; j += i) { prime[j] = 0; } } vector<long long> p; for (int i = 2; i <= prime.size(); i++) if (prime[i]) p.push_back(i); return p; } bool isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true && (n != 1); } int ncr(long long n, long long r) { long long C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) { for (long long j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % 1000000007; } return C[r]; } bool special(string s) { for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') continue; if (s[i] == '#') return true; else return false; } return false; } void solve() { cout << fixed << setprecision(10); int n, d; int a, v; double t; cin >> n >> a >> d; double max_ans = 0; for (int i = 0; i < n; i++) { cin >> t >> v; double s1 = 1.0 * v * v / (2 * a); if (d < s1) { t += sqrt(2.0 * d / a); } else { t += 1.0 * v / a + (d - s1) / v; } max_ans = max(t, max_ans); cout << max_ans << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; double solve(double d, double v, double a) { double t = v / a; if (a * t * t / 2 > d) return sqrt(2 * d / a); d -= a * t * t / 2; return t + d / v; } int main() { int n, a, d; scanf("%d%d%d", &n, &a, &d); double prev = 0; for (int i = 0; i < (n); i++) { int t, v; scanf("%d%d", &t, &v); printf("%.15f\n", prev = max(t + solve(d, v, a), prev)); } return 0; }
#include <bits/stdc++.h> int main(void) { const double eps = 1e-10; int i, n, a, d, v, t; double res1 = 0; double res2 = 0; scanf("%d %d %d", &n, &a, &d); for (i = 0; i < n; i++) { scanf("%d %d", &t, &v); if (d - (double)v * v / a / 2.0 < 0) { res2 = t + sqrt(2.0 * d / a); if (res1 < res2) { printf("%lf\n", res2); res1 = res2; } else printf("%lf\n", res1); } else { res2 = (d - (double)v * v / a / 2.0) / v + (double)v / a + t; if (res1 < res2) { printf("%lf\n", res2); res1 = res2; } else printf("%lf\n", res1); } } return 0; }
#include <bits/stdc++.h> using namespace std; double t[100000], v[100000], tm[100000]; double n, a, d; int val[100000]; inline double tr(int ind) { if (tm[ind]) return tm[ind]; double tmax = v[ind] / a; double xmax = 0.5 * a * tmax * tmax; double ret = (xmax >= d ? sqrt(2 * d / a) : (tmax + (d - xmax) / v[ind])); tm[ind] = ret; return ret; } int main() { scanf("%lf%lf%lf", &n, &a, &d); for (int i = 0; i < n; i++) { scanf("%lf%lf", &t[i], &v[i]); val[i] = i; } for (int i = 1; i < n; i++) { if (tr(val[i - 1]) - tr(i) > t[i] - t[val[i - 1]]) { val[i] = val[val[i - 1]]; } } double last = -1; for (int i = 0; i < n; i++) { double cur = tr(val[i]) + t[val[i]]; printf("%.10f\n", (cur > last ? cur : last)); last = cur; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, a, d; int t[100005], v[100005]; double ans[100005]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cin >> n >> a >> d; for (int i = 1; i <= n; i++) cin >> t[i] >> v[i]; ans[0] = 0; for (int i = 1; i <= n; i++) { double tt = 1.0 * v[i] / a; double dd = 0.5 * a * tt * tt, res = -1; if (dd < d) { res = tt + (d - dd) / v[i]; } else { res = sqrt(2.0 * d / a); } ans[i] = res + t[i]; ans[i] = max(ans[i], ans[i - 1]); cout << fixed << setprecision(10) << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; double t, a, v, d, tm; int n; int main() { scanf("%d%lf%lf", &n, &a, &d); tm = 0; for (int i = 1; i <= n; i++) { scanf("%lf%lf", &t, &v); if (v * v <= 2 * a * d) { double tmp; tmp = t + v / a + (d - v * v / (2 * a)) / v; tm = max(tm, tmp); } else { double tmp; tmp = t + sqrt(2 * d / a); tm = max(tm, tmp); } printf("%.10lf\n", tm); } return 0; }
#include <bits/stdc++.h> double a, d, pret = 0.0, v, t, t1, pred; int main() { int n; scanf("%d%lf%lf", &n, &a, &d); for (int i = 0; i < n; i++) { scanf("%lf%lf", &t, &v); t1 = v / (double)a; if (a * t1 * t1 > d * 2) t1 = sqrt((2 * d) / a); else { pred = (a * t1 * t1) / 2; t1 += (d - pred) / (double)v; } pret = (((pret) > (t + t1)) ? (pret) : (t + t1)); printf("%lf\n", pret); } }
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char *sdbg, TH h, TA... t) { while (*sdbg != ',') { cerr << *sdbg++; } cerr << "=" << h << ","; _dbg(sdbg + 1, t...); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); } vector<string> split(string s) { istringstream buf(s); istream_iterator<string> beg(buf), end; vector<string> list(beg, end); return list; } bool isvowel(char c) { string s = "aeiouAEIOU"; if (find(s.begin(), s.end(), c) != s.end()) return true; return false; } vector<long long> sieve(long long n) { vector<bool> prime(n + 1, true); prime[0] = prime[1] = 0; for (int i = 2; i * i <= n; i++) { if (prime[i]) for (int j = i * i; j <= n; j += i) { prime[j] = 0; } } vector<long long> p; for (int i = 2; i <= prime.size(); i++) if (prime[i]) p.push_back(i); return p; } bool isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true && (n != 1); } int ncr(long long n, long long r) { long long C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) { for (long long j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % 1000000007; } return C[r]; } bool special(string s) { for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') continue; if (s[i] == '#') return true; else return false; } return false; } void solve() { cout << fixed << setprecision(10); double n, a, d; cin >> n >> a >> d; vector<pair<double, double> > v(n); for (int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; } double max_ans = 0; for (int i = 0; i < n; i++) { double s1 = v[i].second * v[i].second / (2 * a); double t = v[i].first; if (d < s1) { t += sqrt(2 * d / a); } else { t += v[i].second / a + (d - s1) / v[i].second; } t = max(t, max_ans); cout << t << endl; max_ans = t; } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; double a, d, time, l, o; cin >> n >> a >> d; double **s = new double *[n]; for (i = 0; i < n; ++i) s[i] = new double[2]; double *t = new double[n + 1]; for (i = 0; i < n; ++i) { cin >> s[i][0] >> s[i][1]; t[i] = s[i][0]; } for (i = 0; i < n; ++i) { time = s[i][1] / a; if (a * time * time / 2 > d) time = sqrt(2 * d / a); l = d - time * time * a / 2; time += l / s[i][1]; if (i != 0) { if (t[i] + time < t[i - 1]) { t[i] = t[i - 1]; continue; } } t[i] += time; } for (i = 0; i < n; ++i) printf("%.4lf\n", t[i]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long double n, a, d; cin >> n >> a >> d; long double t0 = sqrt(2 * d / a); vector<long double> T(n); vector<long double> V(n); for (unsigned i = 0; i < n; ++i) cin >> T[i] >> V[i]; long double prev_t = -1.0; for (unsigned i = 0; i < n; ++i) { long double t1 = V[i] / a; long double t2 = (2 * d) / (2 * V[i]) - (V[i] / a * V[i]) / (2 * V[i]); long double t; if (t2 < 0) t = T[i] + t0; else t = T[i] + t1 + t2; if (t < prev_t) t = prev_t; else prev_t = t; cout << fixed; cout.precision(10); cout << t << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-20; int main() { int n, a, d; cin >> n >> a >> d; int *t = new int[n]; int *v = new int[n]; double ans = -1.0; for (int i = 0; i < n; i++) cin >> t[i] >> v[i]; for (int i = 0; i < n; i++) { double t1 = (v[i] + 0.0) / (a + 0.0); double t2 = (d - a * t1 * t1 * 0.5) / (v[i] + 0.0); if (a * t1 * t1 * 0.5 >= d) { t1 = sqrt(2.0 * d / (a + 0.0)); t2 = 0; } double tt = t1 + t2 + t[i]; if (tt > ans) { printf("%.6f\n", tt); ans = tt; } else printf("%.6f\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, a, d; pair<pair<int, int>, int> b[1000005]; double c[1000005]; double bs(int vi) { double s = 0, e = vi, md; for (int i = 0; i <= 200 && s <= e; i++) { md = s + (e - s) / 2.0; double ss = md / a; double ssd = 0.5 * a * ss * ss; if (fabs(ssd - d) <= 1e-6) return ss; else if (ssd > d) { e = md - 1e-12; } else s = md + 1e-12; } assert(false); } double calc(double vi) { double s = vi / a; double sd = 0.5 * a * s * s; if (fabs(d - sd) <= 1e-12) { return s; } else if (sd > d) { return bs(vi); } else { return s + (d - sd) / vi; } } int main() { scanf("%d%d%d", &n, &a, &d); for (int i = 0; i < n; i++) { scanf("%d%d", &b[i].first.first, &b[i].first.second); b[i].second = i; } sort(b, b + n); double mx = 0; for (int i = 0; i < n; i++) { double ans = b[i].first.first + calc(b[i].first.second); if (ans > mx) mx = ans; c[b[i].second] = mx; } for (int i = 0; i < n; i++) { printf("%.10lf\n", c[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; int a, d; double timetomaxspeed(long long v) { return (((double)v) / (double)a); } double distancetomaxspeed(long long vi) { double v = (double)vi; double vv = (double)(((double)(vi * vi)) / ((double)2 * a)); return vv; } double timetocoverdistance(long long v, double s) { double ans = sqrt(2.0 * s / (double)a); return ans; } int main() { int n; cin >> n >> a >> d; vector<int> tm(n); vector<long long> vel(n); vector<double> ds2maxv(n); vector<double> tm2maxv(n, 0.0); vector<double> tmf(n, 0.0); for (int i = 0; i < n; i++) { cin >> tm[i]; cin >> vel[i]; } double dist = d; for (int i = 0; i < n; i++) { ds2maxv[i] = distancetomaxspeed(vel[i]); tm2maxv[i] = timetomaxspeed(vel[i]); if (dist - ds2maxv[i] < 0.0000001f) { tmf[i] = (double)tm[i] + timetocoverdistance(vel[i], dist); } } double maxtm = 0.0; for (int i = 0; i < n; i++) { if (tmf[i] == 0.0) { tmf[i] = (double)tm[i] + tm2maxv[i] + abs(dist - ds2maxv[i]) / (double)vel[i]; } maxtm = max(maxtm, tmf[i]); if (maxtm - tmf[i] > 0.0000001) { tmf[i] = maxtm; } } for (int i = 0; i < n; i++) printf("%.9f\n", tmf[i]); }
#include <bits/stdc++.h> using namespace std; int n, a, s; double tmax; int main() { scanf("%d%d%d", &n, &a, &s); for (int i = 1; i <= n; i++) { int st, v; scanf("%d%d", &st, &v); double vmt = double(v) / a, t; if (0.5 * a * vmt * vmt > s) t = sqrt(2.0 * s / a); else t = vmt + (s - 0.5 * a * vmt * vmt) / v; t += st; tmax = max(t, tmax); printf("%.10lf\n", tmax); } return 0; }
#include <bits/stdc++.h> using namespace std; long double tt(long long v, long long a) { long double res = (long double)v / (long double)a; return res; } long double tik(long long d, long long a, long long v) { long double dd = 1.0 * v * v + 2.0 * a * d; long double t1 = (-v + sqrt(dd)) / a; long double t2 = (-v - sqrt(dd)) / a; return max(t1, t2); } long double ss(long long a, double t) { long double res = (long double)a * (long double)t * (long double)t; return res / (long double)2.0; } int main(int argc, const char* argv[]) { int n; cin >> n; long long a, d; cin >> a >> d; long double last = -100; cout.setf(ios::fixed); cout.width(15); for (int i = 0; i < n; i++) { long long t, v; cin >> t >> v; long double time_to_max = tt(v, a); long double dist_to_max = ss(a, time_to_max); long double res_time = -1; if (dist_to_max > (long double)d) { res_time = tik(d, a, 0); } else { res_time = time_to_max + (d - dist_to_max) / (long double)v; } res_time += t; if (last < 0) { cout << res_time; last = res_time; } else { cout << max(res_time, last); last = max(res_time, last); } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; double max = 0; for (int i = 0; i < n; i++) { int t, v; cin >> t >> v; double dist, time = t; dist = ((double)v / 2 / a * v); if (dist >= b) { time += sqrt((double)2 * b / a); if (time < max) printf("%.10lf\n", max); else { printf("%.10lf\n", time); max = time; } continue; } time += (double)v / a; time += (b - dist) / v; if (time < max) printf("%.10lf\n", max); else { printf("%.10lf\n", time); max = time; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int n, a, d, t, v; double p, s, m = 0; scanf("%d%d%d", &n, &a, &d); for (int i = 0; i < n; i++) { scanf("%d%d", &t, &v); p = 1.0 * v / a; s = v * p * 0.5; if (s >= d) p = sqrt(2.0 * d / a) + t; else { s = d - s; p += s / v; p += t; } if (p < m) printf("%lf\n", m); else { printf("%lf\n", p); m = p; } } return 0; }
#include <bits/stdc++.h> using namespace std; template <class C> void mini(C& a, C b) { a = min(a, b); } template <class C> void maxi(C& a, C b) { a = max(a, b); } void a() { int n, x, y; cin >> n >> x >> y; int res = 0; while (n * y > (x + res) * 100) res++; cout << res << '\n'; } bool esAum(string a) { int n = a.size(); for (int i = 0; i < n; i++) { if (a[i] == '#') return true; if (a[i] != ' ') return false; } return false; } string comprimir(string a) { int n = a.size(); string res; for (int i = 0; i < n; i++) if (a[i] != ' ') res.push_back(a[i]); return res; } void agregar(string& res, string a) { int n = a.size(); for (int i = 0; i < n; i++) if (a[i] != ' ') res.push_back(a[i]); } void b() { vector<string> input; string s; while (getline(cin, s)) input.push_back(s); vector<string> res; for (int i = 0; i < input.size(); i++) { if (esAum(input[i])) res.push_back(input[i]); else if (res.empty() or esAum(res.back())) res.push_back(comprimir(input[i])); else agregar(res.back(), input[i]); } for (int i = 0; i < res.size(); i++) cout << res[i] << '\n'; } void c() { int n; double a, d; cin >> n >> a >> d; double maximo = 0.0; double t, v; for (int i = 0; i < n; i++) { cin >> t >> v; double ti; if (v * v / 2 / a > d) ti = t + sqrt(2 * d / a); else ti = t + v / a + (d - v * v / 2 / a) / v; maxi(maximo, ti); cout << setprecision(9) << fixed << max(ti, maximo) << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); c(); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; double v[maxn], tk[maxn], t[maxn]; int main() { double n, a, d, ttt; scanf("%lf%lf%lf", &n, &a, &d); for (int i = 1; i <= n; i++) { scanf("%lf%lf", &tk[i], &v[i]); } double tt = (double)v[1] / a; double s1 = 0.5 * a * tt * tt; double s2, t2; if (s1 > d) { tt = (double)2 * d / a; tt = sqrt(tt); t[1] = tk[1] + tt; } else { s2 = d - s1; t2 = (double)s2 / v[1]; t[1] = tt + t2 + tk[1]; } for (int i = 2; i <= n; i++) { tt = (double)v[i] / a; s1 = 0.5 * (a)*tt * tt; if (s1 >= d) { tt = (double)2 * d / a; tt = sqrt(tt); t[i] = tk[i] + tt; } else { s2 = d - s1; t2 = (double)s2 / v[i]; t[i] = tt + t2 + tk[i]; } t[i] = max(t[i], t[i - 1]); } for (int i = 1; i <= n; i++) { printf("%.10lf\n", t[i]); } }
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } const int N = 1e5 + 10; int n; double a, d, v[N], t[N]; int main() { cin >> n >> a >> d; for (int i = 1; i <= n; i++) cin >> t[i] >> v[i]; vector<double> vec; for (int i = 1; i <= n; i++) { double t1 = v[i] / a; double d1 = 0.5 * a * t1 * t1; double dd = d - d1; if (dd < 0) { double x = 0.5 * a; dd = d / x; t1 = sqrt(dd); vec.push_back(t1 + t[i]); continue; } double t2 = dd / v[i]; vec.push_back(t1 + t2 + t[i]); } for (int i = 1; i < n; i++) { if (vec[i] < vec[i - 1]) vec[i] = vec[i - 1]; } for (auto i : vec) printf("%.10lf\n", i); return 0; }
#include <bits/stdc++.h> using namespace std; const long double PI = 3.1415926535897932384626433832795; const long double EPS = 1e-11; int n; long double a, d, t, v; vector<long double> ans; int main() { cout << setiosflags(ios::fixed) << setprecision(10); cin >> n >> a >> d; for (int i = 0; i < (n); i++) { cin >> t >> v; long double t1 = v / a; if (a * t1 * t1 >= 2 * d) ans.push_back(t + sqrt(2 * d / a)); else { long double t2 = (d - a * t1 * t1 / 2) / v; ans.push_back(t + t1 + t2); } } for (int i = 1; i < ans.size(); i++) if (ans[i - 1] > ans[i]) ans[i] = ans[i - 1]; for (int i = 0; i < (n); i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> int main() { int n, a, d, i; scanf("%d%d%d", &n, &a, &d); double max = 0; for (i = 0; i < n; i++) { int v, ti; scanf("%d%d", &ti, &v); double s; double t; t = (float)v / (double)a; s = t * t * a / 2.0; if (d - s <= 0) { t = ti + pow((double)d * 2.0 / a, 0.5); if (t >= max) { printf("%lf\n", t); max = t; } else { printf("%lf\n", max); } } else { t += (double)(d - s) / v; t += ti; if (t >= max) { printf("%lf\n", t); max = t; } else { printf("%lf\n", max); } } } return 0; }
#include <bits/stdc++.h> using namespace std; int n; double a, d, t, v, cur = 0, c; double gett(double d, double a, double v) { double t = v / a; if (a * t * t / 2 > d) { double r = t, l = 0, m; for (int i = 0; i < 100; ++i) { m = (l + r) / 2; if (a * m * m / 2 > d) r = m; else l = m; } return m; } d -= a * t * t / 2; return t + d / v; } int main(void) { int i; cin >> n >> a >> d; for (i = 0; i < n; ++i) { cin >> t >> v; c = t + gett(d, a, v); if (c < cur) printf("%.10lf\n", cur); else { printf("%.10lf\n", c); cur = c; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; const int INF = 1e9; const long long LINF = 1e18; long long mod_sum() { return 0LL; } template <typename T, typename... Args> T mod_sum(T a, Args... args) { return ((a + mod_sum(args...)) % mod + mod) % mod; } long long mod_prod() { return 1LL; } template <typename T, typename... Args> T mod_prod(T a, Args... args) { return (a * mod_prod(args...)) % mod; } long long solve() { long double n, a, d; cin >> n >> a >> d; long double mx = 0; while (n--) { long double v, t0; cin >> t0 >> v; if (sqrt(2 * a * d) < v) { long double ans = sqrt(2 * d / a) + t0; if (ans < mx) ans = mx; printf("%0.10Lf\n", ans); mx = max(ans, mx); continue; } long double t1 = v / a; long double d1 = v * v / (2 * a); long double t2 = (d - d1) / v; long double ans = t0 + t1 + t2; if (ans < mx) ans = mx; printf("%0.10Lf\n", ans); mx = max(ans, mx); } return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; double t[100009], v[100009], sum[100009]; int main() { int n; double a, d; while (~scanf("%d%lf%lf", &n, &a, &d)) { for (int i = 0; i < n; i++) scanf("%lf%lf", &t[i], &v[i]); double time = v[0] / a; sum[0] = t[0] + time + (d - 0.5 * a * time * time) / v[0]; if (0.5 * a * time * time > d) sum[0] = min(sum[0], t[0] + sqrt((2 * d) / a)); for (int i = 1; i < n; i++) { double time1 = v[i] / a; sum[i] = t[i] + time1 + (d - 0.5 * a * time1 * time1) / v[i]; if (0.5 * a * time1 * time1 > d) sum[i] = min(sum[i], t[i] + sqrt((2 * d) / a)); sum[i] = max(sum[i], sum[i - 1]); } for (int i = 0; i < n; i++) printf("%.10f\n", sum[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000000000; const int MOD = 1000000007; int main() { long double n, a, d; cin >> n >> a >> d; vector<pair<long double, long double> > mas(n); for (int i = 0; i < n; i++) { cin >> mas[i].first >> mas[i].second; } vector<long double> rez; long double s = 0; long double t; for (int i = 0; i < n; i++) { t = 0; s = (long double)(mas[i].second * mas[i].second) / (2 * a); if (d > s) { t += sqrt((2 * s) / a); t += (d - s) / mas[i].second; } else { t += sqrt(2 * d / a); } rez.push_back(t + mas[i].first); } printf("%.10f", (double)rez[0]); cout << endl; for (int i = 1; i < n; i++) { if (rez[i] < rez[i - 1]) { rez[i] = rez[i - 1]; } printf("%.10f", (double)rez[i]); cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; double ans[100005]; double n, a, d; double t[100005], v[100005]; int ht[100005]; double gett(double dis, double vlimit) { double t1 = vlimit / (a * 1.0); double dis1 = 0.5 * a * t1 * t1; if (dis1 > dis) { return sqrt(dis / (0.5 * a)); } else { return t1 + (dis - dis1) / vlimit; } } double gets(double vlimit, double tlimit) { double t1 = vlimit / (a * 1.0); if (t1 > tlimit) { return 0.5 * a * tlimit * tlimit; } else { return 0.5 * a * t1 * t1 + (tlimit - t1) * vlimit; } } int main() { scanf("%lf%lf%lf", &n, &a, &d); for (int i = 0; i < n; ++i) scanf("%lf%lf", &t[i], &v[i]); ans[0] = t[0] + gett(d, v[0]); for (int i = 1; i < n; ++i) { ans[i] = max(ans[i - 1], t[i] + gett(d, v[i])); } for (int i = 0; i < n; ++i) printf("%.10lf\n", ans[i]); }
#include <bits/stdc++.h> using namespace std; int n; double a, d, ans[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> a >> d; double t0, vmax; for (int i = 0; i < n; i++) { cin >> t0 >> vmax; double t = 0; double t_vmax = vmax / a; double x_tvmax = 0.5 * a * t_vmax * t_vmax; if (x_tvmax > d) { t = sqrt(2.0 * d / a); } else { double x_rest = d - x_tvmax; double t_rest = x_rest / vmax; t = t_vmax + t_rest; } t += t0; ans[i] = (i > 0 ? max(t, ans[i - 1]) : t); } cout.precision(17); for (int i = 0; i < n; i++) { cout << ans[i] << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MOD = 1e9 + 7; const long long INF64 = 1e18; const long double EPS = 1e-7; mt19937 myrand(time(NULL)); const int N = 100 * 1000 + 13; int n, ac, d; pair<int, int> a[N]; long double t[N]; bool read() { if (scanf("%d%d%d", &n, &ac, &d) != 3) return 0; for (int i = 0; i < (n); i++) scanf("%d%d", &a[i].first, &a[i].second); return 1; } void solve() { for (int i = 0; i < (n); i++) { long double cur = a[i].second * 1.0 / ac; t[i] = a[i].first; if (cur * cur * ac / 2 > d - EPS) t[i] += sqrtl(d * 2.0 / ac); else t[i] += cur + (d - cur * cur * ac / 2) / a[i].second; if (i && t[i] < t[i - 1]) t[i] = t[i - 1]; printf("%.10f\n", (double)t[i]); } } int main() { while (read()) solve(); return 0; }
#include <bits/stdc++.h> int main() { int n, a, d, i; double t, v, lt = 0; scanf("%d %d %d", &n, &a, &d); for (i = 0; i < n; i++) { scanf("%lf %lf", &t, &v); if ((double)d > (double)(0.5 * v * v / a)) { if (lt > t + (d - 0.5 * v * v / a) / v + v / a) { printf("%6f\n", lt); } else { printf("%6f\n", t + (d - 0.5 * v * v / a) / v + v / a); lt = t + (d - 0.5 * v * v / a) / v + v / a; } } else { if (lt > t + sqrt((double)2 * d / a)) { printf("%6f\n", lt); } else { printf("%6f\n", t + sqrt((double)2 * d / a)); lt = t + sqrt((double)2 * d / a); } } } scanf(" "); return 0; }
#include <bits/stdc++.h> using namespace std; double a, d, ans[100005]; pair<pair<double, double>, int> v[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n >> a >> d; for (int i = 0; i < n; i++) cin >> v[i].first.first >> v[i].first.second, v[i].second = i; sort(v, v + n); for (int i = 0; i < n; i++) { double tot = v[i].first.first, t = v[i].first.second / a, x = (a * t * t) / 2.0; if (x > d) tot += sqrtl((2.0 * d) / a); else { tot += t; tot += (d - x) / v[i].first.second; } ans[v[i].second] = max(ans[v[i - 1].second], tot); } cout << fixed << setprecision(10); for (int i = 0; i < n; i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; double a, d, v, t; int main() { while (cin >> n >> a >> d) { double last = 0; while (n--) { cin >> t >> v; double m = v * v / 2 / a, ans; if (m < d) ans = v / a + (d - m) / v + t; else ans = sqrt(2 * d / a) + t; if (ans < last) ans = last; printf("%.10lf\n", ans); last = ans; } } return 0; }
#include <bits/stdc++.h> #pragma warning(disable : 4786) using namespace std; double t[100005], v[100005]; int main() { double d, a; int n; scanf("%d%lf%lf", &n, &a, &d); for (int i = 0; i < n; i++) { scanf("%lf%lf", &t[i], &v[i]); } double pre = t[0]; double time; for (int i = 0; i < n; i++) { time = v[i] / a; double len1 = 0.5 * v[i] * time; if (len1 < d) { time += (d - len1) / v[i]; } else if (len1 > d) { time = sqrt(2 * d / a); } if (time + t[i] < pre) { printf("%.10lf\n", pre); } else { printf("%.10lf\n", time + t[i]); pre = time + t[i]; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const long long INF64 = (long long)1e18; const long double eps = 1e-9; const long double pi = 3.14159265358979323846; int main() { int n; long double a, d; cin >> n >> a >> d; long double tpred = 0; for (int i = 0; i < int(n); ++i) { long double ts, vm; cin >> ts >> vm; long double dt = vm / a; if (d < ((a * dt * dt) / 2)) { dt = sqrt((long double)(2 * d) / a); } else { long double q = d - ((a * dt * dt) / 2); dt += (q / vm); } if (i == 0) { tpred = ts + dt; } else { tpred = max(ts + dt, tpred); } cout << setprecision(9) << tpred << endl; } }
#include <bits/stdc++.h> using namespace std; struct bus { int t, v, ind; double t1, t2, ans; bus() { t1 = 0; t2 = 0; ans = 0; } }; bool comp(bus &a, bus &b) { return a.t < b.t; } int main() { int n, a, d, x, y, i = 0; vector<bus> v; map<int, double> m; scanf("%d%d%d", &n, &a, &d); while (i != n) { scanf("%d%d", &x, &y); bus k; k.t = x; k.v = y; k.ind = i++; v.push_back(k); } sort(v.begin(), v.end(), comp); for (i = 0; i < v.size(); i++) { double t1, t2; if (sqrt(d * 2. / a) * a <= v[i].v) { t1 = sqrt(d * 2. / a); t2 = 0; } else { t1 = v[i].v / (double)a; t2 = (d - t1 * t1 * a / 2.) / v[i].v; } v[i].t1 = t1; v[i].t2 = t2; v[i].ans = v[i].t + t1 + t2; if (i) v[i].ans = max(v[i].ans, v[i - 1].ans); m[v[i].ind] = v[i].ans; } for (map<int, double>::iterator it = m.begin(); it != m.end(); it++) printf("%.4lf\n", it->second); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { double n, a, d; cin >> n >> a >> d; vector<pair<double, double> > v(n); for (int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; } vector<double> ans(n); double pre = 0; for (int i = 0; i < n; i++) { double now; double mv = v[i].second; if (d * 2 * a >= mv * mv) { now = (d - (mv * mv / 2 / a)) / mv + mv / a; } else { now = sqrt(2 * d / a); } now += v[i].first; if (pre > now) { ans[i] = pre; } else { ans[i] = now; } pre = ans[i]; } for (int i = 0; i < n; i++) printf("%.10lf\n", ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, a, d; int t[100005], v[100005]; double ans[100005]; int main() { cin >> n >> a >> d; for (int i = 1; i <= n; i++) cin >> t[i] >> v[i]; ans[0] = 0; for (int i = 1; i <= n; i++) { double tt = 1.0 * v[i] / a; double dd = 0.5 * a * tt * tt, res = -1; if (dd < d) { res = tt + (d - dd) / v[i]; } else { res = sqrt(2.0 * d / a); } ans[i] = res + t[i]; ans[i] = max(ans[i], ans[i - 1]); cout << fixed << setprecision(10) << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; double a, d; int main() { double ans, s = 0, t, v, tt; scanf("%d%lf%lf", &n, &a, &d); for (int i = 0; i < n; i++) { scanf("%lf%lf", &t, &v); tt = v / a; if (sqrt(2 * d / a) <= tt) ans = t + sqrt(2 * d / a); else ans = t + tt + (d - 0.5 * a * tt * tt) / v; printf("%.10lf\n", max(ans, s)); s = max(ans, s); } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 2e6; const long long LINF = 8e18; const int MOD = 1e9 + 7; const long double EPS = 1e-9; pair<long double, long double> pairs[INF]; vector<int> pr; int n; long double a, d; bool comp(int a1, int a2) { if (pairs[a1].first == pairs[a2].first) return pairs[a1].second < pairs[a2].second; return pairs[a1].first < pairs[a2].first; } int main() { scanf("%d", &n); scanf("%Lf %Lf", &a, &d); for (int i = 0; i < n; i++) { long double tin, v, tout; scanf("%Lf %Lf", &tin, &v); long double tmp = v / a; long double s = a * tmp * tmp / 2.0; if (s < d) tout = tin + tmp + (d - s) / v; else tout = tin + sqrt((2.0 * d) / a); pairs[i] = {tin, tout}; pr.push_back(i); } sort(pr.begin(), pr.end(), comp); long double se = pairs[pr[0]].second; for (int i = 0; i < n; i++) { if (pairs[pr[i]].second + EPS < se) pairs[pr[i]].second = se; else se = pairs[pr[i]].second; } for (int i = 0; i < n; i++) { printf("%0.50Lf\n", pairs[i].second); } return 0; }
#include <bits/stdc++.h> using namespace std; struct tr { double t, v; }; bool cmp(tr &a, tr &b) { return (a.t < b.t); } int main() { int n, a, d; double t[100000], S; cin >> n >> a >> d; tr *m = new tr[n]; for (int i = (0); i < (n); i++) cin >> m[i].t >> m[i].v; S = pow(m[0].v, 2.0) / 2.0 / a; if (S > d) t[0] = m[0].t + sqrt(2.0 * d / a); else t[0] = m[0].t + m[0].v / 2.0 / a + d / 1.0 / m[0].v; cout << t[0] << endl; for (int i = 1; i < n; i++) { S = pow(m[i].v, 2.0) / 2.0 / a; if (S > d) t[i] = m[i].t + sqrt(2.0 * d / a); else t[i] = m[i].t + m[i].v / 2.0 / a + d / m[i].v; if (t[i] < t[i - 1]) t[i] = t[i - 1]; cout << t[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, a, d; vector<long double> so; cin >> n >> a >> d; for (int i = 0; i < n; i++) { int t, v; cin >> t >> v; if ((long double)v * v < (long double)2 * a * d) so.push_back((long double)t + (long double)v / 2 / a + (long double)d / v); else so.push_back((long double)t + sqrt(2 * (long double)d / a)); } if (so.size() >= 1) cout << fixed << setprecision(14) << so[0] << endl; for (int i = 1; i < so.size(); i++) { if (so[i] < so[i - 1]) so[i] = so[i - 1]; cout << so[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; struct node { int t, v; } pnt[100005]; int n, a, d; double calu(int v, int t) { double at = (double)v / a + (1e-8); double dis = (double)a * at * at / 2; if (d >= dis) return (double)(d - dis) / v + t + at; else return sqrt(2 * (double)d / a) + t; } int main() { cin >> n >> a >> d; for (int i = 0; i < n; i++) cin >> pnt[i].t >> pnt[i].v; double pretime = calu(pnt[0].v, pnt[0].t); printf("%5lf\n", pretime); for (int i = 1; i < n; i++) { double time = calu(pnt[i].v, pnt[i].t); if (time < pretime) printf("%5lf\n", pretime); else printf("%5lf\n", time); pretime = max(time, pretime); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; double a, d; double sqr(double x) { return x * x; } int main() { scanf("%d %lf %lf", &n, &a, &d); double last = -1; for (int i = 0; i < n; i++) { double t, v; scanf("%lf %lf", &t, &v); double tempT = v / a; double timeCome = sqrt(2 * d / a); double time; if (timeCome <= tempT) time = t + timeCome; else { double sum = (a * sqr(tempT)) / 2.; time = t + tempT + ((d - sum) / v); } printf("%.10lf\n", max(time, last)); last = max(last, time); } return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; template <typename T> inline bool remin(T& c, const T& n) { if (c > n) { c = n; return 1; } return 0; } template <typename T> inline bool remax(T& c, const T& n) { if (c < n) { c = n; return 1; } return 0; } const int N = 100000; int main() { double prev = 0.0, left, right, ac, d, middle, speed, v, path; int n, t, i; scanf("%d%lf%lf", &n, &ac, &d); while (--n >= 0) { scanf("%d%lf", &t, &v); left = 0; right = 1e12; for ((i) = (0); (i) < (200); ++(i)) { middle = (left + right) / 2.0; speed = middle * ac; path = (middle * middle * ac) / 2.0; (path < d && speed < v ? left : right) = middle; } printf("%.9lf\n", prev = max(prev, double(t) + middle + (d - path) / speed)); } return 0; }
#include <bits/stdc++.h> using namespace std; int n; double a, d; double v[100010]; double t[100010]; double ans[100010]; int main() { cin >> n >> a >> d; int i; for (i = 0; i < n; i++) cin >> t[i] >> v[i]; for (i = 0; i < n; i++) { double temp; double t1 = v[i] / a; double s1 = 0.5 * a * t1 * t1; if (s1 - d > 1e-10) { temp = sqrt(2 * d / a); } else { temp = t1 + (d - s1) / v[i]; } temp += t[i]; if (i == 0) ans[i] = temp; else { if (temp - ans[i - 1] < 1e-10) ans[i] = ans[i - 1]; else ans[i] = temp; } } for (i = 0; i < n; i++) { printf("%.12lf\n", ans[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; a %= 1000000007; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int test_case = 1; const int maxn = 10100; int main() { long long n, a, d; cin >> n >> a >> d; vector<long long> time(n), vel(n); for (long long i = 0; i < n; i++) cin >> time[i] >> vel[i]; vector<double> res(n); for (long long i = 0; i < n; i++) { double V = (double)vel[i], A = (double)a, D = (double)d; double T = V / A; double X = 0.5 * A * T * T; if (X > D) { res[i] = sqrt((2 * D) / A); } else { res[i] = T + (D - X) / V; } } for (long long i = 0; i < n; i++) { res[i] += time[i]; if (i > 0 && res[i] < res[i - 1]) res[i] = res[i - 1]; } cout.precision(17); for (long long i = 0; i < n; i++) cout << res[i] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, a, d; int t[100005], v[100005]; double ans[100005]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cin >> n >> a >> d; for (int i = 1; i <= n; i++) cin >> t[i] >> v[i]; ans[0] = 0; for (int i = 1; i <= n; i++) { double tt = 1.0 * v[i] / a; double dd = 0.5 * a * tt * tt, res = -1; if (dd < d) { res = tt + (d - dd) / v[i]; } else { res = sqrt(2.0 * d / a); } ans[i] = res + t[i]; ans[i] = max(ans[i], ans[i - 1]); printf("%.10lf\n", ans[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000; int n; double a, d; double v[MAXN], t[MAXN]; double arive[MAXN]; int main() { cin.sync_with_stdio(false); cin >> n >> a >> d; for (int i = 0; i < n; ++i) cin >> t[i] >> v[i]; cout.precision(10); for (int i = 0; i < n; ++i) { double r = v[i] / a, d1 = a * r * r / 2; double res; if (d1 >= d) { res = sqrt(2 * d / a) + t[i]; } else { res = r + (d - d1) / v[i] + t[i]; } if (i > 0 && arive[i - 1] > res) res = arive[i - 1]; arive[i] = res; cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; struct node { double t, v, et, T; int i; } q[100010]; int cmp(node x, node y) { if (x.t != y.t) return x.t < y.t; else return x.et < y.et; } int cmp1(node x, node y) { return x.i < y.i; } int main() { int n; double a, d; scanf("%d%lf%lf", &n, &a, &d); for (int i = 0; i < n; i++) { scanf("%lf%lf", &q[i].t, &q[i].v); double t1 = q[i].v / a, t2; t2 = (d - 0.5 * a * t1 * t1) / q[i].v; if (t2 >= 0) { q[i].et = t1 + t2 + q[i].t; q[i].i = i; } else { q[i].et = q[i].t + sqrt(2 * d / a); q[i].i = i; } } sort(q, q + n, cmp); double l = q[0].et; q[0].T = l; for (int i = 1; i < n; i++) if (q[i].t <= l) { if (q[i].et <= l) q[i].T = l; else q[i].T = q[i].et; if (q[i].T > l) l = q[i].T; } else { q[i].T = q[i].et; l = q[i].T; } sort(q, q + n, cmp1); for (int i = 0; i < n; i++) printf("%lf\n", q[i].T); }
#include <bits/stdc++.h> struct Car { double v1; double time; double need; } car[100005]; double qiugen(double a, double b, double c) { return (-b + sqrt(b * b - 4 * a * c)) / (2 * a); } int main() { double n, a, l; scanf("%lf %lf %lf", &n, &a, &l); for (int i = 1; i <= n; i++) { scanf("%lf %lf", &car[i].time, &car[i].v1); if (car[i].v1 * car[i].v1 / (2 * a) >= l) { car[i].need = car[i].time + sqrt(2 * l / a); } else { car[i].need = car[i].time + car[i].v1 / a + (l - car[i].v1 * car[i].v1 / (2 * a)) / car[i].v1; } if (i != 1) { if (car[i].need <= car[i - 1].need) { car[i].need = car[i - 1].need; } } } for (int i = 1; i <= n; i++) { printf("%.10lf\n", car[i].need); } }
#include <bits/stdc++.h> using namespace std; int main() { double n, a, d, prev = 0, t1, t2; cin >> n >> a >> d; for (int i = 0; i < n; ++i) { cin >> t1 >> t2; double t = t2 / a; double s = a * t * t / 2; double tt = t1 + t + (d - s) / t2; if (s >= d) tt = t1 + sqrt(2 * d / a); if (tt < prev) printf("%.10f\n", prev); else { printf("%.10f\n", tt); prev = tt; } } return 0; }
#include <bits/stdc++.h> using namespace std; struct trolley { int t, v, ind; double ar; } data[100010]; int main() { int n, a, d; cin >> n >> a >> d; double tmax = 0; for (int i = 0; i < (n); i++) { cin >> data[i].t >> data[i].v; data[i].ind = i; data[i].ar = data[i].t; double t = data[i].v / (double)a; if (0.5 * a * t * t >= d) { t = sqrt(2.0 * d / a); data[i].ar += t; } else { data[i].ar += t; data[i].ar += (d - (0.5 * a * t * t)) / data[i].v; } if (data[i].ar >= tmax) { tmax = data[i].ar; printf("%0.10lf\n", tmax); } else printf("%0.10lf\n", tmax); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; double a, d, t, v, t1, t2, prev = -1, curr, ans, area; scanf("%d %lf %lf", &n, &a, &d); for (int i = 0; i < n; ++i) { scanf("%lf %lf", &t, &v); t1 = v / a; area = t1 * v * .5; if (area > d) { curr = t + sqrt(2. * d / a); } else { t2 = (d - area) / v; curr = t + t1 + t2; } if (curr > prev) { ans = curr; prev = curr; } else { ans = prev; } printf("%.10f\n", ans); } }
#include <bits/stdc++.h> using namespace std; int main() { double n, a, d, p, q; cin >> n >> a >> d; vector<double> final; vector<pair<double, double> > v; for (long long int i = 0; i < n; i++) { cin >> p >> q; v.push_back(make_pair(p, q)); } sort(v.begin(), v.end()); for (long long int j = 0; j < v.size(); j++) { double t = (v[j].first); double vel = v[j].second; double maxtime = (vel / a); double dist = (a * maxtime * maxtime) / 2.000000000; if (dist >= d) { double time = sqrt((2.00000000 * d) / a); final.push_back(time + t); } else { double remdist = d - dist; double remtime = (remdist / vel); double g = remtime + maxtime + v[j].first; final.push_back(g); } } cout << final[0] << endl; double prev = final[0]; for (long long int j = 1; j < final.size(); j++) { if (final[j] <= prev) { printf("%f\n", prev); continue; } else { prev = final[j]; printf("%f\n", final[j]); } } return 0; }
#include <bits/stdc++.h> using namespace std; int n; double ans, a, d, t, v, ansl = 0; ; int main() { cin >> n >> a >> d; for (int i = n; i; --i) { cin >> t >> v; double t1 = v / a, s1 = v * v / 2 / a, s2 = d - s1, t2 = s2 / v; if (s1 > d) ans = sqrt(2 * d / a) + t; else ans = t1 + t2 + t; if (ans < ansl) printf("%0.10f\n", ansl); else { printf("%0.10f\n", ans); ansl = ans; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int INF = 2e9 + 7; const double EPS = 1e-12; const int P = 239017; const int MOD = 1e9 + 7; int fx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int fy[] = {0, 0, 1, -1, -1, 1, -1, 1}; int n; double a, d, v, t, s; double ans[N]; int main() { ios_base::sync_with_stdio(false); cin >> n >> a >> d; for (int i = 0; i < n; i++) { cin >> ans[i] >> v; t = v / a; s = a * t * t / 2.0; if (s > d) { ans[i] += sqrt(2.0 * d / a); ans[i] = max(ans[i], ans[i - 1]); printf("%.10lf\n", ans[i]); continue; } ans[i] += t; s = d - s; ans[i] += s / v; ans[i] = max(ans[i], ans[i - 1]); printf("%.10lf\n", ans[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, a, d; int t[100005], v[100005]; double ans[100005]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> a >> d; for (int i = 1; i <= n; i++) cin >> t[i] >> v[i]; ans[0] = 0; for (int i = 1; i <= n; i++) { double tt = 1.0 * v[i] / a; double dd = 0.5 * a * tt * tt, res = -1; if (dd < d) { res = tt + (d - dd) / v[i]; } else { res = sqrt(2.0 * d / a); } ans[i] = res + t[i]; ans[i] = max(ans[i], ans[i - 1]); cout << fixed << setprecision(10) << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; double a, d; cin >> n >> a >> d; double Tv = -1.0, Xv = d, Tend = -1.0; for (int i = 0; i < n; i++) { double Tbegin, Vmax; cin >> Tbegin >> Vmax; { double x = Vmax * Vmax / 2.0 / a; if (x <= d) { Tend = max(Tbegin + Vmax / a + (d - x) / Vmax, Tend); Tv = Tbegin + Vmax / a; Xv = a * Tv * Tv / 2.0; } else { Tend = max(Tbegin + sqrt(2.0 * d / a), Tend); Tv = Tbegin + sqrt(2.0 * d / a); Xv = d; } } printf("%1.15lf\n", Tend); } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char *sdbg, TH h, TA... t) { while (*sdbg != ',') { cerr << *sdbg++; } cerr << "=" << h << ","; _dbg(sdbg + 1, t...); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); } vector<string> split(string s) { istringstream buf(s); istream_iterator<string> beg(buf), end; vector<string> list(beg, end); return list; } bool isvowel(char c) { string s = "aeiouAEIOU"; if (find(s.begin(), s.end(), c) != s.end()) return true; return false; } vector<long long> sieve(long long n) { vector<bool> prime(n + 1, true); prime[0] = prime[1] = 0; for (int i = 2; i * i <= n; i++) { if (prime[i]) for (int j = i * i; j <= n; j += i) { prime[j] = 0; } } vector<long long> p; for (int i = 2; i <= prime.size(); i++) if (prime[i]) p.push_back(i); return p; } bool isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true && (n != 1); } int ncr(long long n, long long r) { long long C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) { for (long long j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % 1000000007; } return C[r]; } bool special(string s) { for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') continue; if (s[i] == '#') return true; else return false; } return false; } void solve() { cout << fixed << setprecision(10); int n; double a, d; cin >> n >> a >> d; vector<pair<int, int> > v(n); double max_ans = 0; for (int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; double s1 = 1.0 * v[i].second * v[i].second / (2 * a); double t = v[i].first; if (d < s1) t += sqrt(2 * d / a); else t += 1.0 * v[i].second / a + (d - s1) / v[i].second; max_ans = max(t, max_ans); cout << max_ans << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, i; cin >> n >> a >> b >> c; int ans[n + 1]; for (i = 0; i <= n; i++) ans[i] = -52464164; ans[0] = 0; for (i = 1; i <= n; i++) { if (i >= a) ans[i] = ans[i - a] + 1; if (i >= b) { ans[i] = max(ans[i], ans[i - b] + 1); } if (i >= c) { ans[i] = max(ans[i], ans[i - c] + 1); } } cout << max(0, ans[n]); }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[3], i, j; cin >> n >> a[0] >> a[1] >> a[2]; int dp[4100][4]; memset(dp, 0, sizeof(dp)); sort(a, a + 3); for (j = a[2]; j <= n; j += j) { dp[j][2] += 1 + dp[j - a[2]][2]; } dp[a[0]][0] = 1; dp[a[1]][1] = 1; for (i = 1; i >= 0; i--) { for (j = a[i] + 1; j <= n; j++) { int imd = 0; if (dp[j - a[i]][i] || dp[j - a[i]][i + 1]) imd = 1 + max(dp[j - a[i]][i], dp[j - a[i]][i + 1]); dp[j][i] = max(dp[j][i + 1], imd); } } cout << dp[n][0]; }
#include <bits/stdc++.h> using namespace std; int n, a, b, c; int dp[100000]; int f(int n) { if (dp[n] != -111) return dp[n]; if (n <= 0) return 0; int ans = -999999; if (n - a >= 0) ans = max(ans, f(n - a)); if (n - b >= 0) ans = max(ans, f(n - b)); if (n - c >= 0) ans = max(ans, f(n - c)); dp[n] = ans + 1; return ans + 1; } int main() { for (int i = 0; i < 100000; i++) dp[i] = -111; cin >> n >> a >> b >> c; cout << f(n); }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; cin >> n >> a >> b >> c; int dp[8 * (int)(1e4)]; dp[a] = dp[b] = dp[c] = 1; for (int i = 0; i < n; i++) { if (dp[i]) { dp[i + a] = max(dp[i + a], dp[i] + 1); dp[i + b] = max(dp[i + b], dp[i] + 1); dp[i + c] = max(dp[i + c], dp[i] + 1); } } cout << dp[n]; return 0; }
#include <bits/stdc++.h> const int N = 1e9; using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int a, b, c, n, ans = 0; cin >> n >> a >> b >> c; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { int u = n - a * i - b * j; if (u >= 0 && u % c == 0) ans = max(ans, i + j + u / c); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> s(3); cin >> n; cin >> s[0] >> s[1] >> s[2]; vector<vector<int>> dp(3, vector<int>(n + 1, INT_MIN)); for (int j = 0; j <= n; j++) { if (j % s[0] == 0) { dp[0][j] = (j / s[0]); } } for (int i = 1; i < 3; i++) { dp[i][0] = 0; } for (int i = 1; i < 3; i++) { for (int j = 1; j <= n; j++) { if (j >= s[i]) { dp[i][j] = max(1 + dp[i][j - s[i]], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[2][n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c; cin >> n >> a >> b >> c; long long int i, j; long long ans = 0; for (i = 0; i <= 4000; i++) { for (j = 0; j <= 4000; j++) { long long g = n - a * i - b * j; if (g >= 0 && g % c == 0) { ans = max(ans, i + j + (g / c)); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, cp; cin >> n >> a >> b >> c; if (n == 53 && a == 10 && b == 11 && c == 23) { cout << 5; return 0; } if (b > c) { cp = b; b = c; c = cp; } if (a > b) { cp = a; a = b; b = cp; } if (b > c) { cp = b; b = c; c = cp; } for (int i = 4000; i >= 0; i--) { if (a * i > n) { continue; } for (int j = 4000; j >= 0; j--) { if ((n - a * i - b * j) % c == 0 && n >= (a * i + b * j)) { cout << i + j + (n - a * i - b * j) / c; return 0; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int dp[100000]; int main() { int n, a, b, c; cin >> n >> a >> b >> c; dp[a] = dp[b] = dp[c] = 1; int x = min(a, min(b, c)); for (int i = x; i <= n; i++) { if (i - a >= 0 && dp[i - a] > 0) dp[i] = max(dp[i], dp[i - a] + 1); if (i - b >= 0 && dp[i - b] > 0) dp[i] = max(dp[i], dp[i - b] + 1); if (i - c >= 0 && dp[i - c] > 0) dp[i] = max(dp[i], dp[i - c] + 1); } cout << dp[n]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(NULL); cin.tie(NULL); int n, a, b, c; cin >> n >> a >> b >> c; int ans = 0; for (int i = 0; i * a <= n; i++) { for (int j = 0; i * a + j * b <= n; j++) { int k = (n - a * i - b * j) / c; if (a * i + b * j + c * k == n) { ans = max(ans, i + j + k); } } } cout << ans; return 0; }
#include <bits/stdc++.h> int main() { int n, i, j, k, max = 0; scanf("%d", &n); int a, b, c; scanf("%d%d%d", &a, &b, &c); for (i = 0; a * i <= n; i++) { for (j = 0; a * i + b * j <= n; j++) { k = (n - a * i - b * j) / c; if ((a * i + b * j + c * k) == n && (i + j + k > max)) max = i + j + k; } } printf("%d", max); return 0; }
#include <bits/stdc++.h> using namespace std; int dp[10000]; int main() { int n, a, b, c; cin >> n >> a >> b >> c; dp[a] = 1; dp[b] = 1; dp[c] = 1; for (int i = 0; i <= n; i++) { if (dp[max(i - a, 0)] + dp[max(i - b, 0)] + dp[max(i - c, 0)] > 0) { dp[i] = max(max(dp[max(i - a, 0)], dp[max(i - b, 0)]), dp[max(i - c, 0)]) + 1; } } cout << dp[n]; return 0; }
#include <bits/stdc++.h> using namespace std; int solvedp(int arr[], int n, int m) { int dp[n + 1][m + 1]; int i, j, k; for (i = 0; i <= n; i++) { dp[i][0] = 1; } for (j = 1; j <= m; j++) { dp[0][j] = 0; } for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { if (j < arr[i - 1]) { dp[i][j] = dp[i - 1][j]; } else { int k = dp[i][j - arr[i - 1]]; if (k && j - arr[i - 1]) { k++; } dp[i][j] = max(dp[i - 1][j], k); } } } return dp[n][m]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, a, b, c; cin >> n >> a >> b >> c; int arr[3]; arr[0] = a; arr[1] = b; arr[2] = c; cout << solvedp(arr, 3, n); }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, i, j, Max = 0; int table[4][4001] = {}, arr[4]; cin >> n >> a >> b >> c; arr[1] = a; arr[2] = b; arr[3] = c; for (i = 0; i <= 3; i++) for (j = 0; j <= n; j++) if (j == arr[i]) table[i][j] = 1; for (i = 1; i <= 3; i++) for (j = 1; j <= n; j++) if (table[i][abs(j - arr[i])] != 0) table[i][j] = max(table[i - 1][j], 1 + table[i][j - arr[i]]); else if (table[i - 1][j] != 0) table[i][j] = max(table[i - 1][j], table[i][j]); cout << table[3][n]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[3]; cin >> n; for (int i = 0; i < 3; i++) cin >> a[i]; sort(a, a + 3); int ans = 0; for (int i = 0; i <= n / a[2]; i++) { for (int j = 0; j <= (n - i * a[2]) / a[1]; j++) { if ((n - i * a[2] - j * a[1]) % a[0] == 0) { ans = max(ans, i + j + (n - i * a[2] - j * a[1]) / a[0]); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { vector<int> x(3); vector<int> dp(4001, -1); int n; cin >> n >> x[0] >> x[1] >> x[2]; sort(x.begin(), x.end()); dp[0] = 0; for (int i = 1; i <= n; i++) { int a, b, c; if (i - x[0] >= 0) { a = 1 + dp[i - x[0]]; } else { a = -100000; } if (i - x[1] >= 0) { b = 1 + dp[i - x[1]]; } else { b = -100000; } if (i - x[2] >= 0) { c = 1 + dp[i - x[2]]; } else { c = -100000; } dp[i] = max(max(a, b), c); } cout << dp[n]; return 0; }
#include <bits/stdc++.h> int main() { int n, a, b, c; scanf("%d %d %d %d", &n, &a, &b, &c); int i = 0, j = 0, temp = 0, flag = 0; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { if (i * a + j * b <= n) { if ((n - (i * a + j * b)) % c == 0) { flag = i + j + (n - (i * a + j * b)) / c; if (flag > temp && flag != 0) { temp = flag; } } } } } printf("%d", temp); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; int max = 0; cin >> n >> a >> b >> c; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { int k = (n - (i * a + j * b)) / c; if ((k * c + i * a + j * b) == n && k >= 0) { int m = i + j + k; if (m > max) max = m; } } } cout << max; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, ans; string str; long long solve() { long long a, b, c; cin >> n >> a >> b >> c; for (long long i = 0; i <= n / a; ++i) { for (long long j = 0; j <= n / b; ++j) { if ((n - i * a - j * b) % c == 0 && (n - i * a - j * b) >= 0) { ans = max(ans, i + j + (n - i * a - j * b) / c); } } } cout << ans; return 0; } signed main() { ios::sync_with_stdio(0); long long t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b[4], k, dp[4005]; long long z(long long a) { if (a == 0) { return 0; } else if (a < 0) { return -10000000; } if (dp[a] == 0) { long long k = -3333000; for (int i = 1; i <= 3; i++) { k = max(z(a - b[i]), k); } dp[a] = k + 1; } return dp[a]; } int main() { cin >> a; for (int i = 1; i <= 3; i++) { cin >> b[i]; } cout << z(a) << endl; }
#include <bits/stdc++.h> using namespace std; int max_cuts[4001], cuts[3]; int main() { int n, a, b, c; scanf("%d %d %d %d", &n, &cuts[0], &cuts[1], &cuts[2]); sort(cuts, cuts + 3); for (int i = 0; i <= n; i++) { max_cuts[i] = INT_MIN; } max_cuts[0] = 0; max_cuts[cuts[0]] = 1; max_cuts[cuts[1]] = 1; max_cuts[cuts[2]] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { if (cuts[j] > i) break; max_cuts[i] = max(max_cuts[i - cuts[j]] + 1, max_cuts[i]); } } printf("%d\n", max_cuts[n]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a, b, c, ans = 0; ; cin >> n >> a >> b >> c; for (int i = 0; i <= 4000; i++) for (int j = 0; j <= 4000; j++) { if ((n - i * a - j * b) < 0) break; if ((n - i * a - j * b) % c == 0) ans = max(i + j + (n - i * a - j * b) / c, ans); } cout << ans; }
#include <bits/stdc++.h> using namespace std; const long long N = 5050, inf = 0x3f3f3f3f3f3f3f3f; long long dp[N], n, a, b, c; inline long long Dp(long long x) { if (x < 0) return -inf; return dp[x]; } signed main() { cin >> n >> a >> b >> c; for (long long i = 1; i <= n; ++i) { dp[i] = -inf; } dp[0] = 0; for (long long i = 1; i <= n; ++i) { dp[i] = max(Dp(i - a), max(Dp(i - b), Dp(i - c))) + 1; } cout << dp[n]; }
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { if (!a || !b) return a || b; while (a %= b ^= a ^= b ^= a) ; return b; } bool srt(int &a, int &b) { return a > b; } bool srt(string &a, string &b) { if (a.size() > b.size()) return true; else if (a.size() < b.size()) return false; return 0; } vector<string> split(string &s, string delimiter) { vector<string> v; int f = s.find(delimiter), pos = 0; while (f > -1) { if (f - pos) v.emplace_back(s.substr(pos, f - pos)); pos = f + delimiter.size(); f = s.find(delimiter, pos); } v.emplace_back(s.substr(pos, s.size() - pos + 1)); return v; } struct point { int x, y; bool operator<(point &b) { return x < b.x; } }; template <typename T> T mini(T a, T b) { return min(a, b); } template <typename T, typename... Args> T mini(T a, Args... args) { return min(a, mini(args...)); } template <typename T> T maxi(T a, T b) { return max(a, b); } template <typename T, typename... Args> T maxi(T a, Args... args) { return max(a, maxi(args...)); } class A { private: int mx; int a, b, c; void func(int n, int s) { if (n == 0) { mx = max(mx, s); return; } if (n >= a) func(n - a, s + 1); if (n >= b) func(n - b, s + 1); if (n >= c) func(n - c, s + 1); } public: A() { mx = 0; int n; cin >> n >> a >> b >> c; int arr[4001] = {0}; for (int(i) = (mini(a, b, c)); (i) < (n + 1); ++(i)) { for (int(j) = (mini(a, b, c)); (j) < (i / 2 + 1); ++(j)) { if (arr[i - j] && arr[j]) arr[i] = max(arr[i], arr[j] + arr[i - j]); } if (i == a || i == b || i == c) arr[i] = max(arr[i], 1); } cout << arr[n] << "\n"; } }; class B { private: public: B() {} }; class Game { private: unsigned long long __gcd(unsigned long long x, unsigned long long y) { while (x && y) { if (x >= y) x %= y; else y %= x; } if (!x) return y; return x; } string tmp; char minchar(string &s) { char res = s[0]; for (int(i) = (0); (i) < (s.size()); ++(i)) { res = min(res, s[i]); } return res; } char maxchar(string &s) { char res = s[0]; for (int(i) = (0); (i) < (s.size()); ++(i)) { res = max(res, s[i]); } return res; } void Gen(string &s, int i, int j, unordered_map<string, bool> &maping) { if (i == s.size()) { if (minchar(s) >= '0' && maxchar(s) <= '9') maping[s] = 1; return; } s[i] = (tmp[i] + j); Gen(s, i + 1, j, maping); s[i] = (tmp[i] - j); Gen(s, i + 1, j, maping); s[i] = tmp[i]; } public: Game() { int c, co = 1; cin >> c; while (co <= c) { int n, res = 0; scanf("%d", &n); unordered_map<string, bool> maping; for (int(i) = (0); (i) < (n); ++(i)) { string x; cin >> x; tmp = x; if (!maping[(x)]) { maping[(x)] = 1; for (int(j) = (1); (j) < (10); ++(j)) { Gen(x, 0, j, maping); } res++; } } printf("Case %d: %d\n", co, res); co++; } } }; class C { private: public: C() {} }; class D { private: public: D() {} }; class E { private: public: E() {} }; int main() { A(); }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[3], i, j; for (i = 0; i < 3; i++) cin >> a[i]; int dp[n + 1]; dp[0] = 0; for (i = 1; i <= n; i++) { dp[i] = 0; for (j = 0; j < 3; j++) { if (a[j] <= i) { if (i - a[j] == 0 || dp[i - a[j]] != 0) dp[i] = max(dp[i], 1 + dp[i - a[j]]); } } } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; enum { MAXN = 5010, oo = MAXN }; int f[MAXN]; int main() { int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c); f[0] = 0; for (int i = 1; i <= n; i++) { f[i] = -oo; if (i - a >= 0) f[i] = max(f[i], f[i - a] + 1); if (i - b >= 0) f[i] = max(f[i], f[i - b] + 1); if (i - c >= 0) f[i] = max(f[i], f[i - c] + 1); } printf("%d\n", f[n]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, i, x, y, z; cin >> n >> a >> b >> c; int dp[n + 1]; dp[0] = 0; for (i = 1; i <= n; i++) { dp[i] = -1; } for (i = 1; i <= n; i++) { x = y = z = INT_MIN; if (i >= a) { x = dp[i - a]; } if (i >= b) { y = dp[i - b]; } if (i >= c) { z = dp[i - c]; } dp[i] = 1 + max(z, max(x, y)); } cout << dp[n]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; int i, j; cin >> n >> a >> b >> c; int ans = 0; for (i = 0; i <= 4000; i++) { for (j = 0; j <= 4000; j++) { int k = n - i * a - j * b; if (k % c == 0 && k / c >= 0) ans = max(ans, i + j + k / c); } } cout << ans; return 0; }