[CQOI2018]九连环

传送门

Solution

\[ans=\left \lfloor \frac{2^{n+1}}{3} \right \rfloor \]

我为什么要写FFT啊~


#include
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
#define MN 16384
const double Pi=std::acos(-1.);
struct complex
{
    double x,y;
    complex(double x=0,double y=0):x(x),y(y){}
    inline complex operator+(const complex& o)const{return complex(x+o.x,y+o.y);}
    inline complex operator-(const complex& o)const{return complex(x-o.x,y-o.y);}
    inline complex operator*(const complex& o)const{return complex(x*o.x-y*o.y,x*o.y+y*o.x);}
    inline void swap(complex& o){register complex t=o;o=(*this);*this=t;}
}a[MN],b[MN];
int N=16384,di=14,pos[MN];
inline void FFT(complex *a,int type)
{
    register int i,j,p,k;
    for(i=0;i0) fl=1,printf("%03d",(int)a[i].x);
    puts("");
}
inline void sqr(complex *a)
{
    FFT(a,1);
    register int i;
    for(i=0;i>=1,sqr(b)) if(m&1) pro(a,b);
}
int main()
{
    register int i,m=read();
    for(i=0;i>1]>>1)|((i&1)<<(di-1));
    while(m--)
    {
        fpow(read()+1);
        bool fl=0;dig(a);
        for(i=N-1;~i;--i)
        {
            int o=(int)(a[i].x/3.);
            if(!fl&&o>0) fl=1,printf("%d",o);
            else if(fl) printf("%03d",o);
            if(i) a[i-1].x+=(double)(a[i].x-3.*o)*1000.;
        }
        puts("");
    }
    return 0;
}



Blog来自PaperCloud,未经允许,请勿转载,TKS!

转载于:https://www.cnblogs.com/PaperCloud/p/10080159.html

你可能感兴趣的:([CQOI2018]九连环)