题目链接

Problem Description

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has n positive A1−An and their sum is m. Then for each subset S of A, Yuta calculates the sum of S.

Now, Yuta has got 2n numbers between [0,m]. For each i∈[0,m], he counts the number of is he got as Bi.

Yuta shows Rikka the array Bi and he wants Rikka to restore A1−An.

It is too difficult for Rikka. Can you help her?

Input

The first line contains a number t(1≤t≤70), the number of the testcases.

For each testcase, the first line contains two numbers n,m(1≤n≤50,1≤m≤104).

The second line contains m+1 numbers B0−Bm(0≤Bi≤2n).

Output

For each testcase, print a single line with n numbers A1−An.

It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.

Sample Input

2

2 3

1 1 1 1

3 3

1 3 3 1

Sample Output

1 2

1 1 1

Hint

In the first sample, \(A\) is \([1,2]\). \(A\) has four subsets \([],[1],[2],[1,2]\) and the sums of each subset are \(0,1,2,3\). So \(B=[1,1,1,1]\)

题意:

给定数组b,保存的数组a中的所有子集和的个数,让找个这个数组a,并且按照字典序输出来。

分析:

b数组里面除了第一个元素b[0]肯定为1之外(表示空集的个数有且仅有一个),其余的第一次出现的b[i]==j(j!=0),那么就表示i这个数字肯定在a数组中存在,而且为第一个并且为最小的元素,同时将这个数的个数减减(相当于减去单独自己本身一个自己的情况),记录下标i。

这样循环的往后加b数组的元素下标偏移i个单位,如果此时两个数的个数均不为0,也就意味这后面的那个数,可以由前面这个数构成,然后让当前下标的数减去b[i],得到的那个数减去b[i]的个数,(相当于减去这个数可以由b[i]组合而成的个数)剩下的肯定就是这个数字本身的个数

就这样循环着往下找

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; const int maxm = 1100002;
int b[maxm];
int m;
int a[maxm]; int main()
{
int t;
scanf( "%d", &t );
while( t-- )
{
int n;
scanf( "%d%d", &n, &m );
for( int i = 0; i <= m; i++ )
{
scanf( "%d", b+i );
}
b[0] = 0;///空集的情况,不用任何的元素构成,将其赋值为0,不影响后面的计算
for( int i = 0; i < n; i++ )///循环得到a数组中的第i个元素
{
int j;
for( j = 0; j <= m; j++ )///找到当前的第一个不为0的
{
if( b[j] ) break;
}
b[j]--;///相当于有一个本身构成的元素
a[i] = j;///那么就肯定有一个这个元素,而且为当前的最小值
for( int k = j; k <= m; k++ )///找后面的所有可以由j组合而成的是数
{
if( k+j <= m && b[k] && b[k+j] )
{
b[k+j] -= b[k];
}
}
}
for( int i = 0; i < n; i++ )
{
i == 0 ? printf( "%d", a[i] ) : printf( " %d", a[i] );
}
printf( "\n" );
}
return 0;
}

2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)的更多相关文章

  1. 2017 ACM暑期多校联合训练 - Team 9 1008 HDU 6168 Numbers (模拟)

    题目链接 Problem Description zk has n numbers a1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk gen ...

  2. 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)

    题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...

  3. 2017 ACM暑期多校联合训练 - Team 4 1007 HDU 6073 Matching In Multiplication (模拟)

    题目链接 Problem Description In the mathematical discipline of graph theory, a bipartite graph is a grap ...

  4. 2017 ACM暑期多校联合训练 - Team 4 1012 HDU 6078 Wavel Sequence (模拟)

    题目链接 Problem Description Have you ever seen the wave? It's a wonderful view of nature. Little Q is a ...

  5. 2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)

    题目链接 Problem Description There is a nonnegative integer sequence a1...n of length n. HazelFan wants ...

  6. 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)

    题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...

  7. 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)

    题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...

  8. 2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)

    题目链接 Problem Description There are n points on the plane, and the ith points has a value vali, and i ...

  9. 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)

    题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...

随机推荐

  1. phpcms前端模板目录与文件结构分析图【templates】

    phpcms前端模板目录与文件结构分析图[templates] 原文地址:http://www.iphpcms.net/phpcms-ziliao/2015_14.html

  2. webgl 初识1

    1.  webgl是什么?   WebGL其实是一个非常简单的API.好吧,“简单”可能是一个不恰当的描述. 它做的是一件简单的事,它仅仅运行用户提供的两个方法,一个顶点着色器和一个片断着色器, 去绘 ...

  3. SQL Server Management Studio(SSMS)的使用与配置整理

    目录 目录 SQL Server Management Studio的使用与配置 1 设置SSMS显示行号 2 添加注释与取消注释的快捷键 3 新建查询的快捷键 4 开启sql语句TIME与IO的统计 ...

  4. HDU4675_GCD of Sequence

    很有意思的一个数论题. 是这样的,给你一个数数组a[i],其中给出的每一个数字和要求的数字方位都是[1,m],现在问你根据a[]构造一个b[],且a和b中间的不相等的元素的个数恰好有k个. 现在问你g ...

  5. ZOJ2290_Game

    题目意思是这样的,给定一个数N,第一个可以减去任意一个数(不能为N本身),然后接下来轮流减去一个数字,下一个人减去的数字必须大于0,且不大于2倍上一次被减去的数字. 把N减为0的人获胜. 看完题目后不 ...

  6. BZOJ 1266 上学路线(最短路+最小割)

    给出n个点的无向图,每条边有两个属性,边权和代价. 第一问求1-n的最短路.第二问求用最小的代价删边使得最短路的距离变大. 对于第二问.显然该删除的是出现在最短路径上的边.如果我们将图用最短路跑一遍预 ...

  7. document.readyState的使用

    document.readyState:判断文档是否加载完成.firefox不支持. 这个属性是只读的,传回值有以下的可能: 0-UNINITIALIZED:XML 对象被产生,但没有任何文件被加载. ...

  8. 洛谷 P4114 Qtree1

    Qtree系列都跟树有着莫大的联系,这道题当然也不例外 我是题面 读完题,我们大概就知道了,这道题非常简单,可以说是模板题.树剖+线段树轻松解决 直接看代码吧 #include<algorith ...

  9. 洛谷 P2574 XOR的艺术

    刚刚学了,线段树,一道线段树入门题试试水 下面是题面 题目描述 AKN觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个 ...

  10. Qt消息机制和事件

    Qt消息机制和事件 1 事件 事件(event)是由系统或者 Qt 本身在不同的时刻发出的.当用户按下鼠标.敲下键盘,或者是窗口需要重新绘制的时候,都会发出一个相应的事件.一些事件在对用户操作做出响应 ...