Files
lanqiao/12lanqiao/test7-2.cpp

38 lines
747 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// lanqiao 1447 砝码称重(枚举)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
set<int> s;
// n^2 logn
for(int i = 1; i <= n; i++){
int w; cin >> w;
vector<int> v(s.begin(), s.end());
for(int j = 0; j < v.size(); j++){
s.insert(abs(w+v[j]));
s.insert(abs(w-v[j]));
}
s.insert(w);
}
if(s.count(0)) s.erase(0);
cout << s.size() << endl;
return 0;
}
/* test samples -> 10
3
1 4 6
*/
/* process
处理1
s = {1}
处理4
与1组合1+4=5, |1-4|=3
s = {1,3,4,5}
处理6
与1组合1+6=7, |1-6|=5
与3组合3+6=9, |3-6|=3
与4组合4+6=10, |4-6|=2
与5组合5+6=11, |5-6|=1
s = {1,2,3,4,5,6,7,9,10,11}
*/