首页 > 其他 > 详细

International Collegiate Programming Contest 2019 Latin American Regional Contests Problem K

时间:2020-10-02 23:00:17      阅读:38      评论:0      收藏:0      [点我收藏+]

题目链接: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\n",b[i]*k);
43          else 
44            printf("%lld ",b[i]*k);
45           
46     }
47     return 0;
48 }

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

International Collegiate Programming Contest 2019 Latin American Regional Contests Problem K

原文:https://www.cnblogs.com/zpj61/p/13762476.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!