参考的原文链接

题目

Our world has been invaded by shape shifting 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.
Input

The input consists of a single line that contains a string S of length N (1 ≤ N ≤ 10^4),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.
Output

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 2^63.

样例输入1

HHH

样例输出1

0
1

样例输入2

AHHA

样例输出2

2
-1 10 -21

样例输入3

AHHHAH

样例输出3

3
1 -23 159 -297

题意

给一个由“H”和“A”组成的字符串,H代表人类,A代表外星人,构造一个一元 n 多次方程,使得每个字母 H 对应的下标的2倍对应的因变量 > 0,A对应的因变量 < 0

解法

A<0,而H>0,即中间的奇数为方程的解,
即给出

(x-a[n])(x-a[n-1])……(x-a[1])=0

将以上的式子化为一般式
设a0 a1…an为方程一般式的系数,ai为指数为i的项的系数
根据韦达定理,

an−1=∑1≤i≤nxia_{n-1}=\sum_{\mathclap{1\le i\le n}} x_{i} an−1​=1≤i≤n​∑​xi​

an−2=∑1≤i<j≤nxixja_{n-2}=\sum_{\mathclap{1\le i< j\le n}} x_{i}x_{j} an−2​=1≤i<j≤n​∑​xi​xj​
an−3=∑1≤i<j<k≤nxixjxka_{n-3}=\sum_{\mathclap{1\le i< j<k\le n}} x_{i}x_{j}x_{k} an−3​=1≤i<j<k≤n​∑​xi​xj​xk​
………… ……
a0=∏1≤i≤nxia_0=\prod_{\mathclap{1\le i\le n}} x_{i} a0​=1≤i≤n​∏​xi​

当解有1个时
a0=x1,a1=1a_0=x_1, a1=1 a0​=x1​,a1=1
当解有2个时
a0=x1∗x2,a1=x1+x2,a2=1a_0=x_1*x_2, a1=x_1+x_2, a2=1 a0​=x1​∗x2​,a1=x1​+x2​,a2=1
当解有3个时
a0=x1∗x2∗x3a1=x1∗x2+x1∗x3+x2∗x3a2=x1+x2+x3a3=1a_0=x_1*x_2*x_3\\ a1=x_1*x_2+x_1*x_3+x_2*x_3\\ a2=x_1+x_2+x_3\\ a_3=1 a0​=x1​∗x2​∗x3​a1=x1​∗x2​+x1​∗x3​+x2​∗x3​a2=x1​+x2​+x3​a3​=1

由上可得
设b[i][j]为拥有i个解的幂次为j的系数,不计算an

b[i][j]=b[i−1][j]∗a[i]+b[i−1][j−1]b[i][j]=b[i-1][j]*a[i]+b[i-1][j-1] b[i][j]=b[i−1][j]∗a[i]+b[i−1][j−1]

通过代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char c[10100];
ll a[10100],b[10100];
int main()
{cin>>c+1;int len=strlen(c+1);int tot=0; for(int i=1;i<len;i++){if(c[i]!=c[i+1])a[++tot]=i*2+1;}b[1] = 1;for(int i=1;i<=tot;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]*a[i];}} int flag=1;if(c[1]=='H'&&tot%2==1)flag=-1;if(c[1]=='A'&&tot%2==0)flag=-1;cout<<tot<<endl;for(int i=tot+1;i>=1;i--){cout<<flag*b[i];if(i>1)cout<<' '; flag=-flag;}cout<<'\n';return 0;}

ICPC Latin American Regional Contests 2019 K.Know your Aliens菜鸡版相关推荐

  1. ICPC Latin American Regional – 2017 B题(模拟+思维)

    ICPC Latin American Regional – 2017 Alan Curing is a famous sports programmer. He is the creator of ...

  2. ICPC Central Europe Regional Contest 2019 K. K==S(AC自动机+矩阵快速幂)

    Progressive hard octave rock tunes (so-called "phorts") are written using a specifific mus ...

  3. 2021-2022 ACM-ICPC Latin American Regional Programming Contest

    2021-2022 ACM-ICPC Latin American Regional Programming Contest J. Joining Pairs 思路: 本题显然答案为NNN的情况为两条 ...

  4. 【2019.09.21】ICPC Latin American Regional-2017

    提交地址:https://codeforces.com/gym/101889 解题数:6/13 题目: A: B: C: D: E: F: G: H: I: J: K: L: M: 感觉整场下来自己的 ...

  5. 2021-2022 ACM-ICPC Latin American Regional Programming Contest 题解

    B 先两边贪心,然后中间部分卷积 #pragma GCC optimize("O3")#include<iostream> #include<string.h&g ...

  6. 2019 ICPC Asia Yinchuan Regional(9 / 13)

    2019 ICPC Asia Yinchuan Regional A - Girls Band Party(分组背包) 每个物品有两个标签,名字,颜色,当名字是设置为奖赏时会对整体加上0.1 的贡献, ...

  7. The 2019 ICPC Asia Shanghai Regional Contest

    The 2019 ICPC Asia Shanghai Regional Contest 题号 题目 知识点 A Mr. Panda and Dominoes B Prefix Code C Maze ...

  8. 2019 ICPC Asia Nanchang Regional

    2019 ICPC Asia Nanchang Regional C. And and Pair E. Bob's Problem 链接:https://www.jisuanke.com/contes ...

  9. 2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)

    2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018) 题号 题目 知识点 难度 A Access ...

最新文章

  1. Java设计模式——装饰者模式
  2. CodeForces - 1364C Ehab and Prefix MEX(贪心+构造)
  3. 九个著名科技公司的十位CEO的办公桌照片
  4. 入门基础-VC网络编程入门
  5. Linux基础知识之用户和用户组以及 Linux 权限管理
  6. 机器学习实战10-Artificial Neural Networks人工神经网络简介(mnist数据集)
  7. WSS3.0安装后,系统资源消耗这么大
  8. sublime text mac版实施输入处理程序的技巧
  9. (四)洞悉linux下的Netfilteriptables:包过滤子系统iptable_filter
  10. c语言课后作业,C语言练习题
  11. 虚拟机修改默认SSH端口号为10022
  12. android平板改成电视盒子,自己动手把闲置的手机或者平板自制成电视的盒子
  13. 生意参谋和数据银行盘点:品牌+市场+产品
  14. 认识自我,还需吾日三省吾身
  15. [资源分享][Unity][人物模型][动作]一些人物模型以及动作的分享
  16. Javase杂谈(四)
  17. 端游与页游之战:微端网游突出重围
  18. Echars的下载和使用
  19. Django实训:图书信息管理系统
  20. G1怎样设置WAP上网

热门文章

  1. 企业表格技术与风险指标补录系统
  2. 百度秋招补录测开一面
  3. 西西弗斯--生命的意义--人为什么活着
  4. 博途v14电脑要求_TIA博途V14安装的系统要求
  5. 幻读(phantom read)详解
  6. “门头沟”迎赔偿草案,砸盘阴影重现
  7. Poco c ++ 库安装
  8. 总奖金 200 万的 AI Challenger 开赛,可申请免费 GPU 资源
  9. 【开发教程1】开源蓝牙心率防水运动手环-套件检测教程
  10. 搭建自己的 Git 服务器