QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630040 | #8795. Mysterious Sequence | qianchen06# | RE | 0ms | 0kb | C++14 | 1.3kb | 2024-10-11 16:08:07 | 2024-10-11 16:08:09 |
answer
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
void solve()
{
double a, b;
int n;
vector<double> x(n + 1);
cin >> a >> b >> n >> x[1] >> x[n];
if (n == 2)
{
cout << fixed << setprecision(10);
cout << x[1] << '\n';
cout << x[n] << '\n';
return;
}
auto check = [&](double y)
{
x[2] = y;
for (int i = 3; i < n; i++)
{
x[i] = x[i - 1] * a + x[i - 2] * b;
}
double res = x[n - 1] * a + x[n - 2] * b;
return res >= x[n];
};
double l = -1e9,
r = 1e9;
cout << fixed << setprecision(10);
while (l <= r)
{
if (r - l < eps)
{
break;
}
double mid = (l + r) / 2.0;
if (check(mid))
{
r = mid;
}
else
l = mid;
}
x[2] = l;
for (int i = 3; i < n; i++)
{
x[i] = x[i - 1] * a + x[i - 2] * b;
}
for (int i = 1; i <= n; i++)
{
cout << x[i] << '\n';
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
1.0 1.0 10 1 10