ICPC Latin American Regional Contests 2019 K. Know your Aliens(顶点式转一般式)

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

思路:

给出了若干方程的解,将其转化为一般式。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e4 + 3;

ll a[N], b[N];///b[i]: (i - 1)次方的系数

int main()
{
    string s;
    while(cin >> s)
    {
        int len = s.size();
        s = "#" + s;
        int tot = 0;
        for(int i = 1;  i < len; ++i)///根
        {
            if(s[i] != s[i + 1])
            {
                a[++tot] = 2 * i + 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 + 1; ++j)
            {
                b[j - 1] -= a[i] * b[j];
            }
        }
        int flag = 1;
        if(s[1] == 'H' && tot % 2)
            flag = -1;
        if(s[1] == 'A' && tot % 2 == 0)
            flag = -1;
        cout<<tot<<'\n';
        for(int i = tot + 1; i >= 1; --i)
        {
            cout<<b[i] * flag;
            if(i > 1)
                cout<<' ';
        }
        cout<<'\n';
    }
    return 0;
}
/*
HHH
AHHA
AHHHAH
*/

 

全部评论

相关推荐

03-17 23:54
黑龙江大学 Java
来个白菜也好啊qaq:可以的,大厂有的缺打手
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
8665次浏览 80人参与
# 你的实习产出是真实的还是包装的? #
1597次浏览 40人参与
# 巨人网络春招 #
11285次浏览 223人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7337次浏览 40人参与
# 重来一次,我还会选择这个专业吗 #
433258次浏览 3926人参与
# 简历第一个项目做什么 #
31475次浏览 324人参与
# MiniMax求职进展汇总 #
23662次浏览 305人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186809次浏览 1118人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152237次浏览 887人参与
# 研究所笔面经互助 #
118840次浏览 577人参与
# 简历中的项目经历要怎么写? #
309904次浏览 4183人参与
# 面试紧张时你会有什么表现? #
30466次浏览 188人参与
# 你今年的平均薪资是多少? #
212956次浏览 1039人参与
# AI时代,哪些岗位最容易被淘汰 #
63247次浏览 793人参与
# 我的求职精神状态 #
447945次浏览 3128人参与
# 你最满意的offer薪资是哪家公司? #
76388次浏览 374人参与
# 高学历就一定能找到好工作吗? #
64275次浏览 620人参与
# 牛客AI文生图 #
21395次浏览 238人参与
# 你怎么看待AI面试 #
179751次浏览 1224人参与
# 正在春招的你,也参与了去年秋招吗? #
363083次浏览 2635人参与
# 腾讯音乐求职进展汇总 #
160539次浏览 1109人参与
# 职能管理面试记录 #
10787次浏览 59人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务