标签:
5 2 3 5 7 12 5 2 16 64 256 1024 0
12 no solution
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 struct Node { 5 LL val; 6 int x,y; 7 Node(LL v,int a,int b):val(v),x(a),y(b) {} 8 bool operator<(const Node &t) const { 9 return val < t.val; 10 } 11 bool operator>(const Node &t) const { 12 return val > t.val; 13 } 14 bool operator!=(const Node &t) const { 15 return x != t.x && y != t.y && x != t.y && y != t.x; 16 } 17 }; 18 vector<Node>a,b; 19 LL d[1010]; 20 int main() { 21 ios::sync_with_stdio(false); 22 int n; 23 while(cin>>n && n) { 24 for(int i = 0; i < n; ++i) cin>>d[i]; 25 a.clear(); 26 b.clear(); 27 for(int i = 0; i < n; ++i) 28 for(int j = i + 1; j < n; ++j) { 29 a.push_back(Node(d[i] + d[j],i,j)); 30 b.push_back(Node(d[i] - d[j],i,j)); 31 b.push_back(Node(d[j] - d[i],j,i)); 32 } 33 sort(a.begin(),a.end()); 34 sort(b.begin(),b.end()); 35 LL ret; 36 memset(&ret,0x80,sizeof(LL)); 37 for(auto it = a.begin(); it != a.end(); ++it){ 38 auto lvalue = lower_bound(b.begin(),b.end(),*it); 39 auto rvalue = upper_bound(lvalue,b.end(),*it); 40 for(;lvalue != rvalue; ++lvalue) 41 if(*lvalue != *it) 42 ret = max(ret,it->val + d[lvalue->y]); 43 } 44 if (ret < -536870912) 45 cout<<"no solution"<<endl; 46 else cout<<ret<<endl; 47 } 48 return 0; 49 } 50 /* 51 5 52 2 53 3 54 5 55 7 56 12 57 */
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4662562.html