HDU 6168 Numbers
2017-08-22 20:45
369 查看
题目地址
题意:你原本有一个a序列,然后a序列可以每两个求和得到一个b序列,然后现在ab序列搞混了,希望你能找到a序列
思路:因为b序列是由a序列求和得到的,所以a序列一定是有给你的和序列的最小值,因为map内部是对索引排序的,所以可以直接用map选就好了,新选出的值,然后和之前选出来的求和,把个数在map减去。然后一步一步来就好了
题意:你原本有一个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; }
相关文章推荐
- HDU 6168 Numbers【水题】
- HDU 6168 - Numbers 水题 2017 Multi-University Training Contest - Team 9
- hdu 6168 Numbers
- HDU 6168 Numbers
- HDU 6168-Numbers
- hdu 6168 Numbers
- HDU 6168 Numbers(multiset)
- HDU 6168 Numbers
- HDU 6168 Numbers(规律)
- Hdu 6168 Numbers【思维+暴力】
- HDU 6168 Numbers(排序)
- hdu 6168 Numbers (STL)
- HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9
- hdu--6168--Numbers
- HDU 6168 Numbers
- hdu-6168 Numbers
- HDU - 6168 Numbers
- HDU - 6168 Numbers(贪心+优先队列)
- hdu 6168 Numbers
- 【多校训练】hdu 6168 Numbers