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 ...
随机推荐
- popen, pclose - process I/O
SYNOPSIS #include <stdio.h> FILE *popen(const char *command, const char *type); int pclose(FIL ...
- rabbitmq tags
#用户角色####################### RabbitMQ的用户角色分类:none.management.policymaker.monitoring.administrator Ra ...
- spring boot generator
pom.xml 插件引用依赖 <build> <plugins> <plugin> <groupId>org.springframework.boot& ...
- sqlmap POST注入
带表单的页面: 1.sqlmap.py -u "http://mysqli/Less-11/" --forms 2.python sqlmap.py -r d:\test.txt ...
- 在一个div上增加遮罩
有一个需求是给一个视频增加遮罩 我研究了下 抽象出来就是给一个div增加遮罩 原理是:最外层的div使用relative定位 然后里面放两个子div 一个是不被遮的 另一个是遮罩(用abs ...
- python-数据驱动
1.parameterized.parameterized import unittest from parameterized import parameterized,param class Te ...
- [CF1081H]Palindromic Magic
题意:给两个字符串\(a,b\),求出有多少种不同的字符串能通过从第一个串中取出一个回文串,从第二个串中取出一个回文串,按顺序拼接得到. 题解:证明?看官方题解吧 一些定义: 回文串拆分:\(s=ab ...
- 数据导入导出mysql版本不同导致的问题
5.6.16-log导出.5.5.47-log导入 `addtime` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '记录生产时间', 需要修改为: `add ...
- 使用 localstorage 写入浏览器并获取
写入:以字符串的形式写入 localStorage.setItem('data', JSON.stringify(arr)); 获取: 注意:一定要使JSON.parse转为对象才能取出来,不然是空的 ...
- leetcode 238. 除自身以外数组的乘积 (python)
给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积. 示例: 输入: [1 ...