• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
数列 递推
# include <iostream>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <vector>
# include <cmath>
# include <cstdlib>
using namespace std;
typedef long long ll;
typedef double ld;
const double eps = 1e-7;
const int maxn = 1e5 + 5;
typedef vector<ld> vld;
vld ps[maxn];
int fail[maxn];
ld x[maxn], delta[maxn];
int n;
int pn;

int main(void)
{
    while (~scanf("%d", &n) && n) {
        pn = 0;
        for (int i = 1; i <= n; ++i) scanf("%lf", x + i);
        for (int i = 1; i <= n; ++i) {
            ld dt = -x[i];
            for (int j = 0; j < ps[pn].size(); ++j) dt += x[i - j - 1] * ps[pn][j];
            delta[i] = dt;
            if (fabs(dt) <= eps) continue;
            fail[pn] = i;
            if(!pn) { ps[++pn].resize(1); continue; }
            vld&ls = ps[pn - 1];
            ld k = -dt / delta[fail[pn - 1]];
            vld cur;
            cur.resize(i - fail[pn - 1] - 1);
            cur.push_back(-k);
            for (int j = 0; j < ls.size(); ++j) cur.push_back(ls[j] * k);
            if (cur.size() < ps[pn].size()) cur.resize(ps[pn].size());
            for (int j = 0; j < ps[pn].size(); ++j) cur[j] += ps[pn][j];
            ps[++pn] = cur;
        }
        int len = (int)ps[pn].size();
        for (int i = 0; i < len; ++i)
            printf("%g%c", ps[pn][i], " \n"[i == len - 1]);
    }

    return 0;
}

  

posted on 2018-08-28 16:01  dwtfukgv  阅读(110)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3