Mahesh and his lost array

 
Problem code: ANUMLA
 
 

All submissions for this problem are available.

Read problems statements in Mandarin Chinese and Russian as well.

Mahesh got a beautiful array named A as a birthday gift from his beautiful girlfriend Namratha. There are N positive integers in that array. Mahesh loved the array so much that he started to spend a lot of time on it everyday. One day, he wrote down all possible subsets of the array. Then for each subset, he calculated the sum of elements in that subset and wrote it down on a paper. Unfortunately, Mahesh lost the beautiful array :(. He still has the paper on which he wrote all subset sums. Your task is to rebuild beautiful array A and help the couple stay happy :)

Input

The first line of the input contains an integer T denoting the number of test cases.
First line of each test case contains one integer N, the number of elements in A.
Second line of each test case contains 2^N integers, the values written on paper

Output

For each test case, output one line with N space separated integers in non-decreasing order.

Constraints

  • 1T50
  • 1N15
  • 0Values on paper10^9
  • All input values are valid. A solution always exists

Example

Input
2
1
0 10
2
0 1 1 2 Output
10
1 1

Explanation

Test case #2
For the array [1,1], possible subsets are {}, {1}, {1}, {1,1}, respective sums are 0, 1, 1, 2.

给出序列的所有子集和,还原序列的元素

从小到大枚举删数,然后遇到一个最小的即是序列中的数

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = ;
int n , m , tot , x[N] ;
bool vis[N] , tag ;
vector<int>ans; void Output() {
for( int i = ; i < ans.size(); ++i ){
cout << ans[i] << ( i == n-?'\n':' ');
}
} int find( int num ) {
int l = , r = tot- , pos = - ;
if( num > x[r] ) return - ;
while( l <= r ) {
int mid = (l+r)>>;
if( x[mid] == num ) {
if( vis[mid] ) l = mid + ;
else pos = mid , r = mid - ;
}
else if( x[mid] < num )
l = mid + ;
else
r = mid - ;
}
return pos ;
} void Run() {
cin >> n ;
tot = (<<n); ans.clear();
memset( vis , false , sizeof vis );
for( int i = ; i < tot ; ++i ) cin >> x[i] ;
sort( x , x + tot );
for( int i = ; i < tot ; ++i ) if( !vis[i] ) {
vis[i] = true; ans.push_back( x[i] );
if( ans.size() == n ) break ;
for( int j = ; j < tot ; ++j ) if( vis[j] ) {
int pos = find( x[i] + x[j] );
if( pos == - || i == j ) continue ;
vis[pos] = true ;
}
}
Output();
}
int main()
{
// freopen("in.txt","r",stdin);
int _ ,cas = ; cin >> _ ;
while(_--) Run() ;
}

CodeChef Mahesh and his lost array的更多相关文章

  1. scau 2015寒假训练

    并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...

  2. codechef AUG17 T1 Chef and Rainbow Array

    Chef and Rainbow Array Problem Code: RAINBOWA Chef likes all arrays equally. But he likes some array ...

  3. codechef AUG17 T5 Chef And Fibonacci Array

    Chef has an array A = (A1, A2, ..., AN), which has N integers in it initially. Chef found that for i ...

  4. CodeChef - ELHIDARR Find an element in hidden array(二分交互)

    Find an element in hidden array There is an array of length N consisting of non-negative integers. T ...

  5. CodeChef - ELHIDARR Find an element in hidden array(互动题)题解

    题意:有一串不递减的串,串中的任意元素都有k个,除了一个元素,他只有1 <= n < k-1个,你现在能向oj做出以下操作: 输出:1 pos,oj会返回pos位置的元素值 输出:2 va ...

  6. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

  7. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

    https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...

  8. CODECHEF Chef and Churus 解题报告

    [CODECHEF]Chef and Churus Description 有一个长度为\(n\)的数组\(A\),有\(n\)个函数,第\(i\)个函数的值为\(\sum_{j=l_i}^{r_i} ...

  9. Codechef Course Selection

    Home » Practice(Hard) » Course Selection Course Selection Problem Code: RINSubmit https://www.codech ...

随机推荐

  1. centos7卸载YUM后重装过程 -bash: yum: command not found / -bash: yum: 未找到命令

    [root@localhost ~]# rpm -qa |grep yum yum-3.4.3-158.el7.centos.noarch yum-plugin-fastestmirror-1.1.3 ...

  2. vue+element ui 滚动加载

    <div id="app"> <div class="infinite-list-wrapper" style="overflow: ...

  3. file 显示文件的类型

    1. 命令功能 file命令是确定文件类型,也可以辨识一些文件的编码格式.通过文件的头部信息来获取文件类型.windows是通过扩展名来确定文件类型. 2. 语法格式 file  [option]  ...

  4. (转)nginx+redis实现接入层高性能缓存技术

    转自:https://blog.csdn.net/phil_code/article/details/79154271 1. OpenRestyOpenResty是一个基于 Nginx与 Lua的高性 ...

  5. Robomongo可视化命令

    ## 更新命令示例 db.getCollection('collection_name').update(    {'_id':ObjectId('id string')},     {$set:{' ...

  6. Flsak中的socket是基于werkzeug实现的。

    from werkzeug.serving import run_simple from werkzeug.wrappers import Request,Respinse @Request.appl ...

  7. pandas学习(一)

    pandas.DataFrame.sort_index 用法 sort_index(axis=0, level=None, ascending=True, inplace=False, kind='q ...

  8. BZOJ 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛 树形DP

    Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) ...

  9. vue组件传值之父传子

    1.父组件给子组件传值  home父组件  header子组件  关键字props home代码 <template> <div> <v-header :title=&q ...

  10. IBatis.Net 下使用SqlBulkCopy 大批量导入数据 问题解决

    SQLBulkCopy是继承SQLClient空间下的一个特殊类,它可以帮助我们以映射的方式把DataTable和DataReader数据大批量导入到数据库对应表中 public void Inert ...