数学题-零点式转换为一般式Know your Aliens

简介: 题目描述Our world has been invaded by shapeshifting aliens that kidnap people and steal their identities.You are an inspector from a task force dedicated to detect and capture them. As such, you were given special tools to detect aliens and differentiate them from real humans.

CF网址 Know your Aliens


题目描述


Our world has been invaded by shapeshifting aliens that kidnap people and steal their identities.You are an inspector from a task force dedicated to detect and capture them. As such, you were given special tools to detect aliens and differentiate them from real humans. Your current mission is to visit a city that is suspected of have been invaded, secretly inspect every person there so as to know whose are aliens and whose aren’t, and report it all to Headquarters. Then they can send forces to the city by surprise and capture all the aliens at once. The aliens are aware of the work of inspectors like you, and are monitoring all radio channels to detect the transmission of such reports, in order to anticipate any retaliation. Therefore, there have been several efforts to encrypt the reports, and the most recent method uses polynomials.

The city you must visit has N citizens, each identified by a distinct even integer from 2 to 2N. You want to find a polynomial P such that, for every citizen i, P(i) > 0 if citizen i is

a human, and P(i) < 0 otherwise. This polynomial will be transmitted to the Headquarters.With the aim of minimizing bandwidth, the polynomial has some additional requirements:each root and coefficient must be an integer, the coefficient of its highest degree term must be either 1 or −1, and its degree must be the lowest possible.

For each citizen, you know whether they’re a human or not. Given this information, you must find a polynomial that satisfies the described constraints.


输入


The input consists of a single line that contains a string S of length N (1 ≤ N ≤ 104),where N is the population of the city. For i = 1, 2, . . . , N, the i-th character of S is either the uppercase letter “H” or the uppercase letter “A”, indicating respectively that citizen 2i is a human or an alien.


输出


The first line must contain an integer D indicating the degree of a polynomial that satisfies the described constraints. The second line must contain D + 1 integers representing the coefficients of the polynomial, in decreasing order of the corresponding terms. It’s guaranteed that there exists at least one solution such that the absolute value of each coefficient is less than 263.


样例输入


【样例1】
HHH
【样例2】
AHHA
【样例3】
AHHHAH


样例输出


【样例1】
0
1
【样例2】
2
-1 10 -21
【样例3】
3
1 -23 159 -297


题目大意


给出一个字符串(下标从1开始),要构造一个一元n次多项式f(x),使得在字符串中位置为’A’的对应下标的二倍 2×i 处的函数值f(2i) < 0, 而在字符对应为’H’对应的下标的二倍 2 × i处的函数值 f(2i) > 0

而且要使得零点以及系数全部为整数(each root and coefficient must be an integer),并且要最高项的系数是 1 or -1

(the coefficient of its highest degree term must be either 1 or −1,)并且还要使得最高项的系数尽可能的小(its degree must be the lowest possible)我tmd当时怎么就没看见第一个条件呢

这样一来,如果相邻的两个字符不相同,那么必然就有一个零点,并且零点为整数,那么来讲,相邻的两个下标2i 2(i+1)之间必然有一个零点,所以这个零点就必然是 2 * i + 1

这个题主要用到了韦达定理:

微信图片_20220607145913.jpg


关于符号问题,如果极端的考虑一下,就是下图:


微信图片_20220607145923.jpg

因为an不是1就是-1所以导致后面的an-1以及an-2等非常好求

不开long long直接卡掉,CFwa1

string s;
ll x[maxn];
ll b[maxn];
int cnt;
void _Get_x(){
    int len = s.size();
    for(int i=1;i < len-1;i++){
        if(s[i] != s[i+1]) x[++cnt] = 2*i+1;
    }
    cout<<cnt<<endl;
}
void _Get_xi(){
    for(int i=1;i<= cnt;i++){
        for(int j=i+1;j>=1;j--){
            b[j] = b[j - 1];
        }
        for(int j=1;j<=i;j++){
            b[j] += b[j+1] * x[i];
        }
    }
}
int main()
{
    b[1] = 1;
    cin >> s;
    s = 'a' + s;
    _Get_x();
    _Get_xi();
    int oper = 1;
    if(s[1] == 'H' && cnt % 2) oper *= -1;
    if(s[1] == 'A' && cnt % 2 == 0) oper *= -1;
    for(int i=cnt + 1;i >= 1;i --){
        printf("%lld",b[i]*oper);
        oper *= -1;
        if(i != 1) printf(" ");
    }
    return 0;
}


目录
相关文章
|
7月前
|
机器学习/深度学习 人工智能 算法
【代数学作业1完整版-python实现GNFS一般数域筛】构造特定的整系数不可约多项式:涉及素数、模运算和优化问题
【代数学作业1完整版-python实现GNFS一般数域筛】构造特定的整系数不可约多项式:涉及素数、模运算和优化问题
144 0
|
7月前
|
机器学习/深度学习 人工智能 算法
【代数学作业1-python实现GNFS一般数域筛】构造特定的整系数不可约多项式:涉及素数、模运算和优化问题
【代数学作业1-python实现GNFS一般数域筛】构造特定的整系数不可约多项式:涉及素数、模运算和优化问题
132 0
|
4月前
|
人工智能 算法
第一周算法设计与分析:C : 200和整数对之间的情缘
这篇文章介绍了解决算法问题"200和整数对之间的情缘"的方法,通过统计数组中每个数模200的余数,并计算每个同余类中数的组合数来找出所有满足条件的整数对(i, j),使得\( A_i - A_j \)是200的整数倍。
|
6月前
本周练习题目(高精度,大数值)
本周练习题目(高精度,大数值)
|
7月前
|
vr&ar
分位数自回归QAR分析痛苦指数:失业率与通货膨胀率时间序列|数据分享
分位数自回归QAR分析痛苦指数:失业率与通货膨胀率时间序列|数据分享
|
7月前
R语言小数定律的保险业应用:泊松分布模拟索赔次数
R语言小数定律的保险业应用:泊松分布模拟索赔次数
|
算法
基础算法练习200题03、电视剧每集时间(四舍五入)
基础算法练习200题03、电视剧每集时间(四舍五入)
90 0
基础算法练习200题03、电视剧每集时间(四舍五入)
|
C++
MOOC (C++) 3-5美分找钱 将n美分转换成25、10、5和1美分的硬币总共有多少种转换方法?
MOOC (C++) 3-5美分找钱 将n美分转换成25、10、5和1美分的硬币总共有多少种转换方法?
101 0
|
存储 机器学习/深度学习 算法
《三分钟-算法修行》两数相加之解与应用
《三分钟-算法修行》两数相加之解与应用
137 0
《三分钟-算法修行》两数相加之解与应用