Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// https://www.infoarena.ro/blog/meet-in-the-middle
- /// ptr SET http://www.cplusplus.com/reference/set/set/
- #include <iostream>
- #include <set>
- using namespace std;
- set <int> S,S1,S2;
- int main()
- {
- int b,sum;
- cin>>b>>sum;
- for(int p1=1;p1<=b;++p1)
- for(int p2=1;p2<=b;++p2)
- S.insert(p1+p2),S1.insert(p1),S2.insert(p2);
- std::pair<std::set<int>::const_iterator,std::set<int>::const_iterator> ret1,ret2;
- for(int p3=1;p3<b;++p3)
- for(int p4=1;p4<b;++p4)
- if(sum-(p3+p4)<=*S.rbegin())
- {
- ret1=S1.equal_range(p3);
- ret2=S2.equal_range(p4);
- cout<<*ret1.first<<' '<<*ret2.first<<' '<<p3<<' '<<p4<<endl;
- }
- return 0;
- }
- /*
- def 4sum(A):
- sums = {}
- for a in A:
- for b in A:
- sums[a + b] = (a, b)
- for c in A:
- for d in A:
- if -(c + d) in sums:
- print (sums[-(c + d)][0], sums[-(c + d)][1], c, d)
- return
- print "No solution."
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement