zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    github设置添加SSH
    pythonanywhere笔记
    Python3x 爬取妹子图
    python3.4 百度API接口
    简易博客开发(8)----django1.9 博客部署到pythonanywhere上
    Python3.4+Django1.9+Bootstrap3
    docker搭建私有仓库之harbor
    docker新手常见问题和知识点
    node之sinopia搭建本地npm仓库
    rancher-HA快速搭建
  • 原文地址:https://www.cnblogs.com/silenty/p/8796030.html
Copyright © 2011-2022 走看看