BZOJ 3033 太鼓达人

题目描述

七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行。这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是刚刚被精英队伍成员XLk、Poet_shy和lydrainbowcat拯救出来的的applepi。看到两人对太鼓达人产生了兴趣,applepi果断闪人,于是cl拿起鼓棒准备挑战。然而即使是在普通难度下,cl的路人本性也充分地暴露了出来。一曲终了,不但没有过关,就连鼓都不灵了。Vani十分过意不去,决定帮助工作人员修鼓。

鼓的主要元件是M个围成一圈的传感器。每个传感器都有开和关两种工作状态,分别用1和0表示。显然,从不同的位置出发沿顺时针方向连续检查K个传感器可以得到M个长度为K的01串。Vani知道这M个01串应该是互不相同的。而且鼓的设计很精密,M会取到可能的最大值。现在Vani已经了解到了K的值,他希望你求出M的值,并给出字典序最小的传感器排布方案。

输入格式

一个整数K。

输出格式

一个整数M和一个二进制串,由一个空格分隔。表示可能的最大的M,以及字典序最小的排布方案,字符0表示关,1表示开。你输出的串的第一个字和最后一个字是相邻的。

样例

样例输入

3

样例输出

8 00010111

数据范围与提示

得到的8个01串分别是000、001、010、101、011、111、110和100。注意前后是相邻的。长度为3的二进制串总共只有8种,所以M = 8一定是可能的最大值。

对于全部测试点,2≤K≤11。

  这题是个比较经典的回路题,所谓最长的串包含不同的子串,我们可以从子串进行考虑,例如样例,是如何得到的呢?

  

  没错我在长度为3的所有2进制串中找到在后面加一位能得到的串,建图,可以发现一个串从自己回到自己就是在这张图上跑欧拉回路,字典序最小就是从0开始。

  附上AC代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int k;
cin>>k;
if(k==2) puts("4 0011");
if(k==3) puts("8 00010111");
if(k==4) puts("16 0000100110101111");
if(k==5) puts("32 00000100011001010011101011011111");
if(k==6) puts("64 0000001000011000101000111001001011001101001111010101110110111111");
if(k==7) puts("128 00000001000001100001010000111000100100010110001101000111100100110010101001011100110110011101001111101010110101111011011101111111");
if(k==8) puts("256 0000000010000001100000101000001110000100100001011000011010000111100010001001100010101000101110001100100011011000111010001111100100101001001110010101100101101001011110011001101010011011100111011001111010011111101010101110101101101011111011011110111011111111");
if(k==9) puts("512 00000000010000000110000001010000001110000010010000010110000011010000011110000100010000100110000101010000101110000110010000110110000111010000111110001000110001001010001001110001010010001010110001011010001011110001100110001101010001101110001110010001110110001111010001111110010010010110010011010010011110010100110010101010010101110010110110010111010010111110011001110011010110011011010011011110011101010011101110011110110011111010011111110101010110101011110101101110101110110101111110110110111110111011110111111111");
if(k==10) puts("1024 0000000000100000000110000000101000000011100000010010000001011000000110100000011110000010001000001001100000101010000010111000001100100000110110000011101000001111100001000010001100001001010000100111000010100100001010110000101101000010111100001100010000110011000011010100001101110000111001000011101100001111010000111111000100010100010001110001001001000100101100010011010001001111000101001100010101010001010111000101100100010110110001011101000101111100011000110010100011001110001101001000110101100011011010001101111000111001100011101010001110111000111100100011110110001111101000111111100100100110010010101001001011100100110110010011101001001111100101001010011100101010110010101101001010111100101100110010110101001011011100101110110010111101001011111100110011010011001111001101010100110101110011011011001101110100110111110011100111010110011101101001110111100111101010011110111001111101100111111010011111111010101010111010101101101010111110101101011011110101110111010111101101011111110110110111011011111101110111110111101111111111");
if(k==11) puts("2048 00000000000100000000011000000001010000000011100000001001000000010110000000110100000001111000000100010000001001100000010101000000101110000001100100000011011000000111010000001111100000100001000001000110000010010100000100111000001010010000010101100000101101000001011110000011000100000110011000001101010000011011100000111001000001110110000011110100000111111000010000110000100010100001000111000010010010000100101100001001101000010011110000101000100001010011000010101010000101011100001011001000010110110000101110100001011111000011000110000110010100001100111000011010010000110101100001101101000011011110000111000100001110011000011101010000111011100001111001000011110110000111110100001111111000100010010001000101100010001101000100011110001001001100010010101000100101110001001100100010011011000100111010001001111100010100011000101001010001010011100010101001000101010110001010110100010101111000101100110001011010100010110111000101110010001011101100010111101000101111110001100011100011001001000110010110001100110100011001111000110100110001101010100011010111000110110010001101101100011011101000110111110001110010100011100111000111010010001110101100011101101000111011110001111001100011110101000111101110001111100100011111011000111111010001111111100100100101001001001110010010101100100101101001001011110010011001100100110101001001101110010011101100100111101001001111110010100101100101001101001010011110010101001100101010101001010101110010101101100101011101001010111110010110011100101101011001011011010010110111100101110011001011101010010111011100101111011001011111010010111111100110011011001100111010011001111100110100111001101010110011010110100110101111001101101010011011011100110111011001101111010011011111100111001111001110101010011101011100111011011001110111010011101111100111101011001111011010011110111100111110101001111101110011111101100111111101001111111110101010101101010101111010101101110101011101101010111111010110101110101101101101011011111010111011110101111011101011111011010111111110110110111101101110111011011111110111011111101111011111011111111111");
}/*
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int k,b[2050],ch[2050][2050],mas,cnt;
bool v[2050],t[2050];
int rd()
{
    char cc=getchar();
    int s=0,w=1;
    while(cc<'0'||cc>'9') {if(cc=='-') w=-1;cc=getchar();}
    while(cc>='0'&&cc<='9') s=(s<<3)+(s<<1)+cc-'0',cc=getchar();
    return s*w;
}
void dfs(int x)
{
    for(int i=0;i<=mas;i++)
    {
        if(ch[x][i]&&!v[i])
        {
            ch[x][i]=0;
            v[i]=1;
            dfs(i);
        }
    }
    b[++cnt]=x;
}
int main()
{
    freopen("2.cpp","w",stdout);
    printf("#include<iostream>\n#include<cstdio>\n#include<cstring>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nint main(){\n");
    printf("int k;\ncin>>k;\n");
    for(k=2;k<=11;k++)
    {
        memset(t,0,sizeof(t));
        memset(v,0,sizeof(v));
        memset(ch,0,sizeof(ch));
        memset(b,0,sizeof(b));cnt=0;
        printf("if(k==%d) puts(\"",k);
        mas=(1<<k)-1;
        //memset(ch,-1,sizeof(ch));
        for(int i=0;i<=mas;i++)
        {
            int nt=(i<<1)&mas;
            t[nt|1]=1;t[nt]=0;
        //    cout<<i<<" "<<(nt|1)<<" "<<nt<<endl;
            if((nt|1)!=i) ch[i][nt|1]=1;
            if(nt!=i) ch[i][nt]=1;
        }
        dfs(0);
        printf("%d ",cnt-1);
        for(int i=1;i<=k;i++) printf("0");
        for(int i=cnt-1;i>k;i--) printf("%d",t[b[i]]);
        puts("\");");
    }
    printf("}\n");
}
*/
View Code

  咳咳

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int k,b[2050],ch[2050][2050],mas,cnt;
bool v[2050],t[2050];
int rd()
{
    char cc=getchar();
    int s=0,w=1;
    while(cc<'0'||cc>'9') {if(cc=='-') w=-1;cc=getchar();}
    while(cc>='0'&&cc<='9') s=(s<<3)+(s<<1)+cc-'0',cc=getchar();
    return s*w;
}
void dfs(int x)
{
    for(int i=0;i<=mas;i++)
    {
        if(ch[x][i]&&!v[i])
        {
            ch[x][i]=0;
            v[i]=1;
            dfs(i);
        }
    }
    b[++cnt]=x;
}
int main()
{
    k=rd();
    mas=(1<<k)-1;
    //memset(ch,-1,sizeof(ch));
    for(int i=0;i<=mas;i++)
    {
        int nt=(i<<1)&mas;
        t[nt|1]=1;t[nt]=0;
    //    cout<<i<<" "<<(nt|1)<<" "<<nt<<endl;
        if((nt|1)!=i) ch[i][nt|1]=1;
        if(nt!=i) ch[i][nt]=1;
    }
    dfs(0);
    printf("%d ",cnt-1);
    for(int i=1;i<=k;i++) printf("0");
    for(int i=cnt-1;i>k;i--) printf("%d",t[b[i]]);
    puts("");
}
/*
g++ 1.cpp -o 1
./1
4
*/
View Code

 

 

 

 

posted @ 2019-07-13 07:13  starsing  阅读(218)  评论(0编辑  收藏  举报