【链接】h在这里写链接


【题意】


一开始有n个数字,然后有一个数字X,把每个数字都减去X,又生成N个新的数字.
然后把这2*N个数字混在一起.
告诉你这2*N个数字是什么.让你复原出原来的N个数字,以及数字X.
或告知不可能。

【题解】


考虑一开始的n个数字a[1],a[2]...a[n];
假设a[1] <= a[2] <= ... <= a[n];
然后混起来的2*N个数字。
最小的肯定是a[1]-X.
则,我们枚举a[1]为2..n中的某个数字。
则我们可以暂时算出来X的值。
然后再把它代入2*n个数字当中。
看看是不是a[1]真的可以为这个值.
(把枚举的a[1]和第一个数字a[1]-x删掉后,最小的数字是a[2]-x..再看看a[x]-x+x是不是在2*N个数字里面即可)

【错的次数】


2

【反思】


数组开小+一个变量忘记改变。

【代码】

/*

*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
#include <bitset>
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 emplace_back
#define fi first
#define se second
#define ld long double
#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 rf(x) scnaf("%lf",&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)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
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 = 1e3; int n,a[2*N+10];
vector <int> v;
bool bo[2*N+10]; bool ok(int x){
    int j = 0;
    rep1(i,1,2*n)
        if (!bo[i]){
            bo[i] = true;
            bool ok = false;
            while (1){
                if (j > 2*n) break;
                if (a[j]==a[i]+x){
                    ok = true;
                    bo[j] = true;
                    v.pb(a[j]);
                    j++;
                    break;
                }else j++;
            }
            if (!ok) return false;
        }
    return true;
} int main(){
    //Open();
    //Close();
    ri(n);
    rep1(i,1,2*n)
        ri(a[i]);
    sort(a+1,a+1+2*n);
    rep1(i,2,2*n)
        if (a[i]!=a[1]){
            ms(bo,0);
            bo[1] = bo[i] = true;
            v.clear();
            v.pb(a[i]);
            if (ok(a[i]-a[1])){
                oi(a[i]-a[1]),puts("");
                rep1(i,1,n){
                    oi(v[i-1]);
                    if (i==n)
                        puts("");
                    else
                        oc;
                }
                return 0;
            }
        }
    puts("-1");
    return 0;
}

【CS Round #46 (Div. 1.5) C】Set Subtraction的更多相关文章

  1. 【CS Round #46 (Div. 1.5) E】Ultimate Orbs

    [链接]链接 [题意] n个人从左到右站在一条直线上.每个人都有一个能力值g[i],然后每个人可以将相邻的一个人打败. 然后它的能力值能够增加相应的能力值(就是打败了的那个人的能力值). A能够打败B ...

  2. 【CS Round #46 (Div. 1.5) B】Letters Deque

    [链接]h在这里写链接 [题意] 让你把一个正方形A竖直或水平翻转. 问你翻转一次能不能把A翻转成B [题解] 有说一定要恰好为1次. 并不是说A和B相同就一定不行. [错的次数] 2 [反思] 自己 ...

  3. 【CS Round #46 (Div. 1.5) A】Letters Deque

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] string类模拟 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #incl ...

  4. 【CS Round #36 (Div. 2 only) A】Bicycle Rental

    [题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...

  5. 【CS Round #37 (Div. 2 only) D】Reconstruct Graph

    [Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...

  6. 【CS Round #37 (Div. 2 only) B】Group Split

    [Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...

  7. 【CS Round #37 (Div. 2 only) A】Boring Number

    [Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...

  8. 【CS Round #39 (Div. 2 only) D】Seven-segment Display

    [Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...

  9. 【CS Round #39 (Div. 2 only) C】Reconstruct Sum

    [Link]:https://csacademy.com/contest/round-39/task/reconstruct-sum/ [Description] 给你一个数字S; 让你找有多少对A, ...

随机推荐

  1. 最近遇到的若干Web前端问题:disable和readonly,JqueryEasyUI,KindEditor

    最近项目中用到了Jquery Easyui和KindEditor等框架组件,问题真不少啊~  一些看起来很简单理所当然的事情,竟然花费了不少时间,才解决好~  1.readonly和disable的区 ...

  2. php, hhvm与odp & Unix domain Socket方式

    接上一篇,复习一下 启动php或hhvm: php/sbin/php-fpm start hhvm/bin/hhvm_control start 启动nginx或lighttpd: webserver ...

  3. [Python] Use Python Classes

    Object oriented classes work much like classes in other languages. Learn how to create them and use ...

  4. IIS文件上传大小修改配置说明

    原因:Web 服务器上的请求筛选被配置为拒绝该请求,因为内容长度超过配置的值(IIS 7 默认文件上传大小时30M). 解决:IIS7更改asp.net文件上传大小限制 步骤如下: 1.    修改I ...

  5. solrj简介

    SolrJ基于httpClient: 使用SolrJ操作Solr会比利用httpClient来操作Solr要简单. SolrJ是封装了httpClient方法,来操作solr的API的. SolrJ底 ...

  6. C#导出EXCEL(DataTable导出EXCEL)

    using System; using System.Collections.Generic; using System.Text; using System.Data; using System.I ...

  7. Newtonsoft.json多版本共存

    Newtonsoft.json多版本共存 https://blog.csdn.net/dang13579/article/details/72956684 https://blog.csdn.net/ ...

  8. Spring AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)(转)

    1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下让你不知所措,心想着:管不得很多人都和我说AOP多难多难.当我看进去以后, ...

  9. 数据结构(C实现)------- 单链表

    在单链表中,每个结点包括两部分:存放每个数据元素本身信息的数据域和存放其直接后继存储位置的指针域. 单链表结点的类型描写叙述: typedef int ElemType; typedef struct ...

  10. 用openssl生成含有中文信息的证书

    openssl 支持 ASCII 和 UTF-8 两种编码,应该可以制作中文证书. 在生成证书签发申请时,当输入中文则 openssl 报错,这是因为当前输入的字符是 ANSI 本地编码格式,超出了 ...