zoukankan      html  css  js  c++  java
  • International Collegiate Programming Contest 2019 Latin American Regional Contests Problem K

    题目链接:https://codeforces.ml/gym/102428/attachments/download/9820/statements-en.pdf

    题意:构造一个多项式使得外星人编号的函数值小于零,人类的编号函数值大于零。

    思路:零点存在问题,我们只要找出字符串中有多少A-H或者H-A的变化就是零点个数,然后利用求多项式板子的代码即可。

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<vector>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<bits/stdc++.h>
     7 using namespace std;
     8 #define mem(s,n) memset(s,n,sizeof s);
     9 #define PI acos(-1.0)
    10 typedef long long ll;
    11 const int maxn=1e5+5;
    12 const ll Inf=0x7f7f7f7f;
    13 ll a[maxn],b[maxn];
    14 char s[maxn];
    15 int main()
    16 {
    17     scanf("%s",s);
    18     int tot=0;
    19     //cout<<strlen(s)<<endl;
    20     for(int i=0;i<strlen(s)-1;i++)
    21     {
    22         if(s[i]==s[i+1]) continue;
    23         else 
    24         {
    25             a[++tot]=2*i+3;
    26             //cout<<tot<<endl;
    27         }
    28     }
    29     b[1]=1;
    30     for(int i=1;i<=tot;i++)
    31     {
    32         for(int j=i+1;j>=1;j--) b[j]=b[j-1];
    33         for(int j=1;j<=i+1;j++) b[j-1]-=a[i]*b[j];
    34     }
    35     ll k=1;
    36     if(s[0]=='H'&&tot%2) k=-1;
    37     if(s[0]=='A'&&tot%2==0) k=-1;
    38     cout<<tot<<endl;
    39     for(int i=1+tot;i>=1;i--)
    40     {    
    41          if(i==1) 
    42            printf("%lld
    ",b[i]*k);
    43          else 
    44            printf("%lld ",b[i]*k);
    45           
    46     }
    47     return 0;
    48 }

    (训练的时候真是菜,一个很小的问题错了w了五次真白给)

  • 相关阅读:
    web动静分离
    vm采用NAT方式连接时,设置静态ip
    nginx实现tcp负载均衡
    读取文件
    线程池源码分析
    mongodb操作
    bind
    Xss攻击
    json和java对象相互转换
    静态资源默认加载路径
  • 原文地址:https://www.cnblogs.com/zpj61/p/13762476.html
Copyright © 2011-2022 走看看