zoukankan      html  css  js  c++  java
  • 【2017 Multi-University Training Contest

    【链接】http://acm.hdu.edu.cn/showproblem.php?pid=6168


    【题意】


    有一个长度为n的序列a1……an,根据a序列生成了一个b序列,b[i] = a[i]+aj,然后有一个人把a,b序列按随机顺序混合了起来,现在问你初始的a序列是什么 

    【题解】


    c1和c2分别和a1和a2对应;
    则在c中把a1+a2删掉.
    然后得到最小的c,肯定就是a3了.
    再把a3和a1,a2组成的删掉。
    以此类推

    【错的次数】


    0

    【反思】


    在这了写反思

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define ri(x) scanf("%d",&x)
    #define rl(x) scanf("%lld",&x)
    #define rs(x) scanf("%s",x)
    #define oi(x) printf("%d",x)
    #define ol(x) printf("%lld",x)
    #define oc putchar(' ')
    #define os(x) printf(x)
    #define all(x) x.begin(),x.end()
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0)
    
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 125250;
    
    
    int m,n,c[N+10],a[N];
    map <int,int> dic;
    
    
    int main(){
        //Open();
        //Close();
        while (~ri(m)){
            dic.clear();
            n = sqrt(2*m);
            rep1(i,1,m) ri(c[i]);
            sort(c+1,c+1+m);
            a[1] = c[1],a[2] = c[2];
            dic[a[1]+a[2]]--;
            int now = 3;
            rep1(j,3,n){
                while (dic[c[now]]<0){
                    dic[c[now]]++;
                    now++;
                }
                a[j] = c[now];
                now++;
                rep1(k,1,j-1)
                    dic[a[k]+a[j]]--;
            }
            oi(n);puts("");
            rep1(i,1,n){
                oi(a[i]);
                if (i==n)
                    puts("");
                else
                    oc;
            }
        }
        return 0;
    }
    


  • 相关阅读:
    小程序返回顶部top滚动
    创建对象的几种模式
    前端基础常识
    三行代码让页面中的所有元素增添不同颜色的外边框
    纯css制作小三角
    设计表单
    纯css制作三级菜单
    三栏-中栏流动布局
    三栏固定布局(为栏设定内边距和边框)
    ie8以下不兼容h5新标签的解决方法
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626102.html
Copyright © 2011-2022 走看看