题解 「SWTR-04」Meeting in the Forest

· · 题解

1.\;10\;pts

送分的,答案就是 -a_1\times b_1。

2.\;30\;pts

对于一个二次方程,用求根公式 x_{1, 2}=\dfrac{-b\pm\sqrt{b^2-4ac}}{2a},存储一下 \Delta,然后暴算即可。

3.\;60\;pts

这个其实只是用来凑数的,也不知道有什么方法。

4.\;100\;pts

下面来讲正解惹QAQ。

其实这道题是韦达定理的拓展应用,在这里就手推一下韦达定理吧。

首先,根据题目我们可以得到:

其次,有个东东叫做余式定理,它是在说这样一件事: > 对于一个多项式 $f(x)$,它除以 $x-a$ 的余式为 $f(a)$。 > 特别的,当 $f(a)=0$ 时,$x-a$ 是 $f(x)$ 的一个因式。 于是,我们可以令 $f(x)=x^n+a_1x^{n-1}+a_2x^{n-2}+\cdots+a_{n-1}x+a_n=0$,那么 $f(x_1)=f(x_2)=...=f(x_n)=0$。 根据余式定理,我们可以知道: $$x^n+a_1x^{n-1}+a_2x^{n-2}+\cdots+a_{n-1}x+a_n=(x-x_1)(x-x_2)...(x-x_n)$$ 这个表达式是**恒成立**的! 因此,我们把右边的式子拆开,与左边的系数一一匹配,发现了这样一件事情: $$\sum_{1\le j_1 < j_2 <\cdots< j_i \le n}^{n}x_{j_1}x_{j_2}\cdots x_{j_i}=(-1)^i\times a_i$$ 到这里,这道题就基本解决了。我们只需要在输入 $a_i$ 时判断 $i$ 的奇偶性,如果奇数就变为 $-a_i$,然后与 $b_i$ 相乘,最后累加起来就可以啦。 下面放上 $100\;pts$ 代码: ### $Code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> 
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int n, a[200010], b[200010], c[200010], ans;
signed main(){
    //freopen("test20.in", "r", stdin);
    //freopen("test20.out", "w", stdout);
    scanf("%lld", &n);
    for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    for(int i = 1; i <= n; ++i) scanf("%lld", &b[i]);
    for(int i = 1; i <= n; ++i){
        if(i & 1) c[i] = -a[i];//奇数变为相反数
        else c[i] = a[i];//否则还是自己
    }
    for(int i = 1; i <= n; ++i) ans = (ans + b[i] * c[i] % mod) % mod;//答案累加
    printf("%lld", (ans + mod) % mod);//注意负数的判断QAQ
    return 0;//完结撒花
}

End