• 对拍练习


    去年的对拍noip上用不了...

    不知道是不是机子的问题...换了一种对拍。

    以洛谷11月月赛T2为例。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long
    using namespace std;
    
    int n;
    
    int h[320],vis[320];
    
    LL ans;
    
    void dfs(int now,int a,LL scor)
    {
        if(a==n)
        {
            ans=max(ans,scor);
            return ;
        }
        for(int i=1;i<=n;i++)
        {
            if(vis[i]) continue;
            vis[i]=true;
            dfs(i,a+1,scor+(h[now]-h[i])*(h[now]-h[i]));
            vis[i]=false;
        }
    }
    
    int main()
    {
        freopen("rand.txt","r",stdin);
        freopen("baoli.txt","w",stdout);
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&h[i]);
        dfs(0,0,0);
        cout<<ans<<endl;
        return 0;
    }
    暴力程序
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long
    using namespace std;
    
    int n;
    
    int L,R;
    
    int h[320];
    
    LL ans;
    
    int main()
    {
        freopen("rand.txt","r",stdin);
        freopen("my.txt","w",stdout);
        scanf("%d",&n);L=0;R=n;
        for(int i=1;i<=n;i++) scanf("%d",&h[i]);
        sort(h,h+n+1);
        while(L<R)
        {
            ans=ans+(h[R]-h[L])*(h[R]-h[L]);
            L++;
            ans=ans+(h[R]-h[L])*(h[R]-h[L]);
            R--;
        }
        cout<<ans<<endl;
        return 0;    
    } 
    正解
    #include<iostream>
    #include<cstring>
    #include<ctime>
    #include<cstdio>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    int main()
    {
        freopen("rand.txt","w",stdout);
        srand(time(0));
        int n;n=rand()%5+1;
        cout<<n<<endl;
        for(int i=1;i<=n;i++)
        {
            int x;x=rand()%100+2;
            cout<<x<<" ";
        }
        return 0;
    } 
    生成的数据
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    int main()
    {
        while(1)
        {
            system("rand.exe");
            system("baoli.exe");
            system("my.exe");
            if(system("fc baoli.txt my.txt "))
            while(1);
        }
        return 0;
    }
    对拍

     要写cstdlib

    这四个程序

  • 相关阅读:
    【BZOJ4444】国旗计划
    NOIp模拟赛三十一
    [arc086e]snuke line
    NOIp模拟赛三十
    [agc004f]namori
    [agc004d]salvage robot
    [agc016b]colorful hats
    NOIp模拟赛二十九
    [arc082f]sandglass
    Oracle性能报告--ASH
  • 原文地址:https://www.cnblogs.com/zzyh/p/9904040.html
Copyright © 2020-2023  润新知