zoukankan      html  css  js  c++  java
  • 对拍练习

    去年的对拍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

    这四个程序

  • 相关阅读:
    从入门到不放弃系列之Koa2
    进击Node.js基础(二)
    进击Node.js基础(一)
    探知浏览器并发请求个数
    Elasticsearch 聚合操作
    Elasticsearch 数据查询
    Elasticsearch 数据操作
    Elasticsearch 映射操作
    Elasticsearch 索引操作
    IDEA类和方法注释模板设置
  • 原文地址:https://www.cnblogs.com/zzyh/p/9904040.html
Copyright © 2011-2022 走看看