CodeChef Mahesh and his lost array
Mahesh and his lost arrayProblem 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
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 15
- 0 ≤ Values on paper ≤ 10^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的更多相关文章
- scau 2015寒假训练
并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...
- codechef AUG17 T1 Chef and Rainbow Array
Chef and Rainbow Array Problem Code: RAINBOWA Chef likes all arrays equally. But he likes some array ...
- 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 ...
- 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 ...
- CodeChef - ELHIDARR Find an element in hidden array(互动题)题解
题意:有一串不递减的串,串中的任意元素都有k个,除了一个元素,他只有1 <= n < k-1个,你现在能向oj做出以下操作: 输出:1 pos,oj会返回pos位置的元素值 输出:2 va ...
- 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] 表示第 ...
- 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 ...
- CODECHEF Chef and Churus 解题报告
[CODECHEF]Chef and Churus Description 有一个长度为\(n\)的数组\(A\),有\(n\)个函数,第\(i\)个函数的值为\(\sum_{j=l_i}^{r_i} ...
- Codechef Course Selection
Home » Practice(Hard) » Course Selection Course Selection Problem Code: RINSubmit https://www.codech ...
随机推荐
- 2018-8-10-WPF-控件继承树
title author date CreateTime categories WPF 控件继承树 lindexi 2018-08-10 19:16:53 +0800 2018-2-13 17:23: ...
- 03.LinuxCentOS系统root目录LVM磁盘扩容
根目录LVM扩容操作步骤: [root@centos7 ~]# df -lh文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 50G 7.7G 43G 6% / ...
- java类实现序列化的方法?collection框架中实现什么样的接口
- ivew 限制输入 0 到 1 的数字 包括小数, 0 ,1
input <FormItem label="> <Input v-model="formItem.shapeDifferen.breastScaleOutSpa ...
- 三条路线告诉你如何掌握Spring IoC容器的核心原理
原文链接:https://blog.csdn.net/bntx2jsqfehy7/article/details/78977178
- tensorflow2.0 squeeze出错
用tf.keras写了自定义层,但在调用自定义层的时候总是报错,找了好久才发现问题所在,所以记下此问题. 问题代码 u=tf.squeeze(tf.expand_dims(tf.expand_dims ...
- 约瑟夫环 c++ 循环输入
#include<iostream> #include<string.h> #include<cstdio> #include <sstream> us ...
- 【CF1244D】Paint the Tree(树形DP,树)
题意: n<=1e5,1<=a[i][j]<=1e9 思路: 不是很懂INF为什么要开到1e15,我觉得只要1e14就好 #include<bits/stdc++.h> ...
- 透明的LISTVIEW
.NET就是封装的太密了,有时很多时候让我们反而更麻烦,特别是COPY不到的时候,又不懂自已想的话,说土一点就是死路一条, 记得以前经常用一句话,C++支持,可C#他不支持啊!就这样安慰自已 其实做多 ...
- ctrl+鼠标左键监听
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...