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 ...
随机推荐
- pg_ctl - 启动,停止和重启 PostgreSQL 服务器
SYNOPSIS pg_ctl start [ -w ] [ -s ] [ -D datadir] [ -l filename] [ -o options] [ -p path] pg_ctl sto ...
- Linux性能优化从入门到实战:16 文件系统篇:总结磁盘I/O指标/工具、问题定位和调优
(1)磁盘 I/O 性能指标 文件系统和磁盘 I/O 指标对应的工具 文件系统和磁盘 I/O 工具对应的指标 (2)磁盘 I/O 问题定位分析思路 (3)I/O 性能优化思路 Step 1:首先采用 ...
- php 弱类型比较
1.按数字值比较 1.1数字(整数.浮点数.科学计数法.各种进制数)或纯十进制数字字符串. <?php $a = 100; //整数 $b = "100"; //十进制数字符 ...
- spring boot 集成 websocket 实现消息主动推送
spring boot 集成 websocket 实现消息主动 前言 http协议是无状态协议,每次请求都不知道前面发生了什么,而且只可以由浏览器端请求服务器端,而不能由服务器去主动通知浏览器端,是单 ...
- java 构造方法中super()的作用?
手贱百度了一下 :java里面自定义类的有参构造方法为什么不用super() 举个例子: class Father { Father(){print ('father');}; } class Son ...
- python网络编程之验证客户端链接的合法性
六.socket的更多方法介绍 服务端套接字函数s.bind() 绑定(主机,端口号)到套接字s.listen() 开始TCP监听s.accept() b被动接收TCP客户的连接,(阻塞式)等待连接的 ...
- CKEditor粘贴图片上传功能
很多时候我们用一些管理系统的时候,发布新闻.公告等文字类信息时,希望能很快的将word里面的内容直接粘贴到富文本编辑器里面,然后发布出来.减少排版复杂的工作量. 下面是借用百度doc 来快速实现这个w ...
- Word文档粘贴到DEDECMS
Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧?Chrome高版本提供了可以将单张图片转换在BASE64字符串的功能.但是无法 ...
- selenium 浏览器无界面模式运行
以Chrome浏览器为例: 方法一: from selenium.webdriver import Chrome, ChromeOptions opt = ChromeOptions() # 创建Ch ...
- SQL语句中 (+) 含义
(+) 表示外连接.条件关联时,一般只列出表中满足连接条件的数据.如果条件的一边出现(+),则可列出该表中在条件另一侧的数据为空的那些记录.比如两个表:员工表和工资表.员工表中有总经理.A.B.C四条 ...