lanqiao 1447 砝码称重(枚举)
This commit is contained in:
38
12lanqiao/test7-2.cpp
Normal file
38
12lanqiao/test7-2.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// 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}
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user