码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 379D-New Year Letter

时间:2019-04-06 00:02:10      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:个数   ret   hellip   blank   图片   tps   scan   生成   open   

传送门:QAQQAQ

 

题意:给一个字符串生成方式:Sn=Sn-1+Sn-2,然后询问如果要使Sk中的连续“AC”字串数量刚好为x,S1,S2长度刚好为n,m。要求构造出S1,S2。

 

思路:构成AC有两种情况:

    1.AC在中间:斐波那契数列

    2.AC由头尾构成:下面寻找Si的开头结尾规律

3:1开头,2结尾    

4:2开头,2结尾

5:1开头,2结尾

6:2开头,2结尾……两个一循环

下面寻找结合时规律

1,2结合:1结尾接2开头

2,3结合:2结尾接1开头

3,4结合:2结尾接2开头

4,5结合:2结尾接1开头

5,6结合:2结尾接2开头……除了1,2结合接下来两个一循环

    当头为C或尾为A时会影响中间可用字符的个数,所以我们分类讨论4*4中两个字符串头尾A,C的情况,再枚举中间n-2或m-2个位置中AC个数(要充分利用n,m很小这一特点)

技术图片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int dx[]={0,-1,-1,-2};//toua weic,toua weia,touc weic,touc weia
 5 int dy[]={0,-1,-1,-2};
 6 
 7 ll k,x,n,m;
 8 long long f[55];
 9 
10 void print(int ansx,int ansy,int fx,int fy)
11 {
12     string xx,yy;
13     if(fx==2||fx==3) xx+="C";
14     if(fy==2||fy==3) yy+="C";
15     for(int i=1;i<=ansx;i++) xx+="AC";
16     for(int i=ansx*2+1;i<=n+dx[fx];i++) xx+="B";
17     for(int i=1;i<=ansy;i++) yy+="AC";
18     for(int i=ansy*2+1;i<=m+dy[fy];i++) yy+="B";
19     if(fx==1||fx==3) xx+="A";
20     if(fy==1||fy==3) yy+="A";
21     cout<<xx<<endl;
22     cout<<yy<<endl;
23 }
24 
25 int main()
26 {
27     scanf("%lld%lld%lld%lld",&k,&x,&n,&m);
28     for(int xx=0;xx<=3;xx++)
29     {
30         for(int yy=0;yy<=3;yy++)
31         {
32             if(n+dx[xx]<0||m+dy[yy]<0) continue;
33             for(int i=0;i<=(n+dx[xx])/2;i++)
34             {
35                 for(int j=0;j<=(m+dy[yy])/2;j++)
36                 {
37                     ll sum1=i,sum2=j,now;
38                     for(int p=3;p<=k;p++)
39                     {
40                         now=0;
41                         if(p==3) 
42                         {
43                             if((xx==1||xx==3)&&(yy==2||yy==3)) now++;
44                         }
45                         else
46                         {
47                             if(p%2==0)
48                             {
49                                 if((xx==2||xx==3)&&(yy==1||yy==3)) now++;
50                             }
51                             if(p%2==1)
52                             {
53                                 if(yy==3) now++;
54                             }
55                         }
56                         now+=sum1+sum2;
57                         sum1=sum2;
58                         sum2=now;
59                     }
60                     if(now==x) 
61                     {
62                         print(i,j,xx,yy);
63                         return 0;
64                     }
65                 }
66             }
67         }
68     }
69     puts("Happy new year!");
70     return 0;
71 }
View Code

 

codeforces 379D-New Year Letter

标签:个数   ret   hellip   blank   图片   tps   scan   生成   open   

原文地址:https://www.cnblogs.com/Forever-666/p/10660402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!