【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;
}


原文地址:https://www.cnblogs.com/AWCXV/p/7626102.html