• HDU 全国多校第四场 题解


    题解


    A AND Minimum Spanning Tree

     参考代码:

    #include<bits/stdc++.h>
    #define maxl 200010
    using namespace std;
    
    int n,ans1;
    int mi[31];
    int ans[maxl];
    
    inline void prework()
    {
        scanf("%d",&n);
    }
    
    inline int find(int x)
    {
        for(int j=0;j<=30;j++)
        if((x&mi[j])==0)
            return mi[j];
    }
    
    inline void mainwork()
    {
        ans1=0;int x;
        for(int i=2;i<=n;i++)
        {
            if(i&1)
            {
                x=find(i);
                if(x<=n)
                    ans[i]=x;
                else
                    ans1++,ans[i]=1;    
            }
            else
                ans[i]=1;
        }
    }
    
    inline void print()
    {
        printf("%d
    ",ans1);
        for(int i=2;i<=n;i++)
            printf("%d%c",ans[i],(i==n)?'
    ':' ');
    }
    
    int main()
    {
        mi[0]=1;
        for(int i=1;i<=30;i++)
            mi[i]=mi[i-1]*2;
        int t;
        scanf("%d",&t);
        for(int i=1;i<=t;i++)
        {
            prework();
            mainwork();
            print();
        }
        return 0;
    }
    View Code

    B Colored Tree

     unsolved.

    C Divide the Stones

     题解:https://blog.csdn.net/liufengwei1/article/details/97970041

      1 #include<bits/stdc++.h>
      2 #define maxl 100010
      3 using namespace std;
      4  
      5 long long k,n,sum,t;
      6 long long dy[maxl];
      7 long long last[maxl],to[maxl];
      8 long long tmp[maxl];
      9 bool flag;
     10 vector <long long> ans[maxl];
     11  
     12 inline void prework()
     13 {
     14     scanf("%lld%lld",&n,&k);
     15     sum=1ll*n*(n+1)/2;
     16     for(long long i=1;i<=k;i++)
     17         ans[i].clear();
     18 }
     19  
     20 inline void mainwork()
     21 {
     22     flag=false;
     23     if(sum%k!=0)
     24         return;
     25     sum=sum/k;
     26     long long id;
     27     t=n/k;
     28     if(t%2==0)
     29     {
     30         long long id=1;
     31         for(long long i=1;i<=k;i++)
     32         {
     33             for(long long j=1;j<=t/2;j++)
     34             {
     35                 ans[i].push_back(id);
     36                 ans[i].push_back(n-id+1);
     37                 id++;
     38             }
     39         }
     40         flag=true;
     41     }
     42     else
     43     {
     44         if(n/k==1)
     45         {
     46             if(n==1)
     47             {
     48                 ans[1].push_back(1);
     49                 flag=true;
     50             }
     51             return;
     52         }
     53         for(long long i=1;i<=k/2+1;i++)
     54         {
     55             dy[i]=k/2+i;
     56             to[i]=(i-1)*2+1;
     57         }
     58         for(long long i=k/2+2;i<=k;i++)
     59         {
     60             dy[i]=i-(k/2)-1;
     61             to[i]=(i-(k/2)-1)*2;
     62         }
     63         for(long long i=1;i<=k;i++)
     64             ans[i].push_back(i),last[i]=i,tmp[i]=i;
     65         long long num;
     66         for(long long i=2;i<n/k;i++)
     67         {
     68             for(long long j=1;j<=k;j++)
     69             {
     70                 num=dy[last[j]]+(i-1)*k; 
     71                 ans[j].push_back(num);
     72                 last[j]=to[last[j]];
     73                 tmp[j]+=num;
     74             }    
     75         }
     76         for(long long i=1;i<=k;i++)
     77             ans[i].push_back(sum-tmp[i]);
     78         flag=true;
     79     }
     80 }
     81  
     82 inline void print()
     83 {
     84     if(flag)
     85     {
     86         puts("yes");
     87         long long l;
     88         for(long long i=1;i<=k;i++)
     89         {
     90             for(long long j=0;j<n/k;j++)
     91                 printf("%lld%c",ans[i][j],(j==(n/k-1))?'
    ':' ');
     92         }
     93     }
     94     else
     95         puts("no");
     96 }
     97  
     98 int main()
     99 {
    100     long long t;
    101     scanf("%lld",&t);
    102     for(long long i=1;i<=t;i++)
    103     {
    104         prework();
    105         mainwork();
    106         print();
    107     }
    108     return 0;
    109 }
    View Code

    D Enveloping Convex

     unsolved.

    E Good Numbers

     unsolved.

    F Horse

     unsolved.

    G Just an Old Puzzle

    题解:百度“15难题”

      参考代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int ans;
    int a[17];
    int x[17];
    
    inline void prework()
    {
        for(int i=1;i<=16;i++)
        { 
            scanf("%d",&a[i]);
            if(a[i]==0)
            { 
                a[i]=16;
                ans=x[i]; 
            } 
        } 
    }
    
    inline void mainwork()
    {
        for(int i=1;i<=16;i++)
        {
            for(int j=i+1;j<=16;j++)
            if(a[j]<a[i])
                ans++;
        }
        
    }
    
    inline void print()
    {
        if(ans&1)
            puts("No");
        else
            puts("Yes");
    }
    
    int main()
    {
        x[2]=1;x[4]=1;x[5]=1;x[7]=1;
        x[10]=1;x[12]=1;x[13]=1;x[15]=1;
        int t;
        scanf("%d",&t);
        for(int cas=1;cas<=t;cas++)
        {
            prework();
            mainwork();
            print();
        }
        return 0;
    }
    View Code

    H K-th Closest Distance

    题解:主席树+二分 https://blog.csdn.net/liufengwei1/article/details/97948584

      参考代码

    #include<bits/stdc++.h>
    #define maxl 100010
    using namespace std;
    
    const int nn=1e6;
    
    int n,m,tot,ans;
    int rt[maxl],a[maxl];
    struct node
    {
        int ls,rs,sum;
    }tree[maxl*10*35];
    
    inline void insert(int num,int &x,int l,int r)
    {
        tree[++tot]=tree[x];x=tot;
        ++tree[x].sum;
        if(l==r) return;
        int mid=(l+r)>>1;
        if(num<=mid)
            insert(num,tree[x].ls,l,mid);
        else
            insert(num,tree[x].rs,mid+1,r);
    }
    
    inline void prework()
    {
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        tree[0].ls=tree[0].rs=tree[0].sum=0;
        rt[0]=0;
        tot=0;
        for(int i=1;i<=n;i++)
        {
            rt[i]=rt[i-1];
            insert(a[i],rt[i],1,nn);
        }
    }
    
    inline int query(int i,int j,int l,int r,int i1,int j1)
    {
        if(i1==l && j1==r)
            return tree[j].sum-tree[i].sum;
        int mid=(i1+j1)>>1,ret;
        if(r<=mid)
            ret=query(tree[i].ls,tree[j].ls,l,r,i1,mid);
        else if(l>mid)
            ret=query(tree[i].rs,tree[j].rs,l,r,mid+1,j1);
        else
        {
            ret=query(tree[i].ls,tree[j].ls,l,mid,i1,mid);
            ret+=query(tree[i].rs,tree[j].rs,mid+1,r,mid+1,j1);
        }
        return ret;
    }
    
    inline bool jug(int l,int r,int mid,int p,int k)
    {
        int up=min(p+mid,nn),lo=max(1,p-mid);
        int sum=query(rt[l-1],rt[r],lo,up,1,nn);
        if(sum<k)
            return false;
        else
            return true;
    }
    
    inline void mainwork()
    {
        ans=0;int up,lo,p,k,l,r,mid;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d%d%d",&lo,&up,&p,&k);
            lo^=ans;up^=ans;p^=ans;k^=ans;
            l=0;r=nn;
            while(l+1<r)
            {
                mid=(l+r)>>1;
                if(!jug(lo,up,mid,p,k))// <k
                    l=mid;
                else
                    r=mid;
            }
            if(jug(lo,up,l,p,k))
                ans=l;
            else
                ans=l+1;
            printf("%d
    ",ans);
        }
    }
    
    inline void print(){}
    
    int main()
    {
        int t;
        scanf("%d",&t);
        for(int i=1;i<=t;i++)
        {
            prework();
            mainwork();
            print();
        }
        return 0;
    }
    View Code

    I Linear Functions

     unsolved.

    J Minimal Power of Prime

     参考代码

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int size=1e6+5;
    double eps=1e-8;
    int p[size];bool prime[size];
    int mpri[size];
    int tot=0;
    void init()
    {
        for(int i=1;i<size;i++) prime[i]=true;
        for(int i=2;i<size;i++)
        {
            if(prime[i])
            {
                p[++tot]=i;
                mpri[i]=i;
            }
            for(int j=1;j<=tot&&p[j]*i<size;j++)
            {
                prime[i*p[j]]=false;mpri[i*p[j]]=p[j];
                if(i%p[j]==0) break;
            }
        }
    }
    int main()
    {
        init();
        int t;
        long long x;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lld",&x);
            int cnt=0;
            int ans=64;
            if(x<size){
                int ps=mpri[x];
                while(x!=1)
                {
                    do x/=ps,cnt++;
                    while(mpri[x]==ps);
                    ps=mpri[x];
                    ans=min(ans,cnt);
                }
                printf("%d
    ",ans);
                continue;
            }
            bool flag=false;
            for(int i=1;i<=tot;i++)
            {
                cnt=0;
                if(x%p[i]==0)
                {
                    do x/=p[i],cnt++;
                    while(x%p[i]==0);
                }
                if(cnt==1)
                {
                    puts("1");
                    flag=true;
                    break;
                }
            }
            if(flag) continue;
            LL sq=sqrt(x)+eps;
            if(sq*sq==x)
            {
                printf("2
    ");
            }
            else 
            {
                puts("1");
            }
        }
    }    
    View Code

  • 相关阅读:
    Task10 文本预处理
    Task09 批量归一化
    Task06 Basic of CNN
    Task05 梯度消失和梯度爆炸
    Task 04 过拟合,欠拟合及其解决方案
    机器学习 Task 03 多层感知机
    机器学习 task2 softmax与分类模型
    异步与闭包与fetch
    baidu API
    my own JSON
  • 原文地址:https://www.cnblogs.com/csushl/p/11280673.html
Copyright © 2020-2023  润新知