您的位置:首页 > 其它

HDU 6168 Numbers

2017-08-22 20:45 369 查看
题目地址

题意:你原本有一个a序列,然后a序列可以每两个求和得到一个b序列,然后现在ab序列搞混了,希望你能找到a序列

思路:因为b序列是由a序列求和得到的,所以a序列一定是有给你的和序列的最小值,因为map内部是对索引排序的,所以可以直接用map选就好了,新选出的值,然后和之前选出来的求和,把个数在map减去。然后一步一步来就好了

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#define N 3010
#define LL __int64
#define inf 0x3f3f3f3f
#define lson l,mid,ans<<1
#define rson mid+1,r,ans<<1|1
#define getMid (l+r)>>1
#define movel ans<<1
#define mover ans<<1|1
using namespace std;
const LL mod = 1000000007;
int main() {
cin.sync_with_stdio(false);
int n, num;
map<LL,LL> mapp;
vector<LL> v;
while (cin >> n) {
mapp.clear();
v.clear();
for (int i = 0; i < n; i++) {
cin >> num;
mapp[num]++;
}
for (map<LL, LL> ::iterator it = mapp.begin(); it != mapp.end(); it++) {
while(it->second) {
it->second--;
for (int i = 0; i < v.size(); i++) {
mapp[it->first + v[i]]--;
}
v.push_back(it->first);
}
}
cout << v.size() << endl;
for (int i = 0; i < v.size() - 1; i++) {
cout << v[i] << " ";
}
cout << v[v.size() - 1] << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: