• BZOJ 5251: [2018多省省队联测]劈配


    题目大意:

    https://www.lydsy.com/JudgeOnline/problem.php?id=5251

    题解:

    要求最优的录取方案,网络流。

    问每个人的排名至少上升多少才能满足期望,这个有二分性。二分+网络流判定,没有加优化所以在某些网站上会T。

    代码:

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #define pi acos(-1)
    using namespace std;
    struct node{
        double x,i;
        node(){}
        node(double x,double i):x(x),i(i){}
        node operator+(node a) {return node(x+a.x,i+a.i);}
        node operator-(node a) {return node(x-a.x,i-a.i);}
        node operator*(node a) {return node(x*a.x-i*a.i,x*a.i+i*a.x);}
    }a[300005],b[300005];
    int rev[300005];
    void fft(node *a,int n,int t)
    {
        for (int i=0; i<n; i++)
            if (i<rev[i]) swap(a[i],a[rev[i]]);
        for (int j=1; j<n; j<<=1)
        {
            node wn(cos(2*pi/(j<<1)),t*sin(2*pi/(j<<1)));
            for (int i=0; i<n; i+=(j<<1))
            {
                node w(1,0),t0,t1;
                for (int k=0; k<j; k++,w=w*wn)
                {
                    t0=a[i+k];
                    t1=w*a[i+j+k];
                    a[i+k]=t0+t1;
                    a[i+j+k]=t0-t1;
                }
            }
        }
    }
    int main()
    {
       	int n;
    	scanf("%d",&n);
    	n--;
        for (int i=0; i<=n; i++) scanf("%lf%lf",&a[i].x,&b[n-i].x);
        int nn=1,len=0;
        while (nn<=2*n){
            nn<<=1;
            len++;
        }
        rev[0]=0;
        for (int i=1; i<nn; i++)
            rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
        fft(a,nn,1);
        fft(b,nn,1);
        for (int i=0; i<=nn; i++)
            a[i]=a[i]*b[i];
        fft(a,nn,-1);
        for (int i=n; i<=2*n; i++)
            printf("%d
    ",(int)(a[i].x/nn+0.5));
        return 0;
    }
    

      

  • 相关阅读:
    字符串类题
    计算器(栈、字符串)
    排序与检索,UVa 10474,(大理石在哪里)
    2019第十届蓝桥杯Java题
    暴力求解法
    图的遍历
    栈 队列与优先队列
    刷题小知识总结点
    字符串题单
    string
  • 原文地址:https://www.cnblogs.com/silenty/p/8796030.html
Copyright © 2020-2023  润新知