Test instructions
Give n a different number, ask for a combination of 4 numbers (A,B,C,D) to satisfy the A+b+c=d, and the largest d.
Ideas:
I didn't think I could use a hash.
This is the data structure of the separation link method ~
Resolving hash Conflicts: Links all keywords to synonyms in the same single-linked list.
A+b+c=d converted into a+b=d-c;
Hash out all the a+b first.
Then use D-c to find.
Complexity of N^2*hash;
#include <cstdio> #include <string.h> #include <algorithm> using namespace std;
const int MOD=5E5+10;
const int N=5E5+10;
struct node{int x, y;};
Node Q[n];
int ha[mod],nex[mod],s[1010],res,n;
BOOL Flag;
void solve (int x,int y) {int key= (x-y+mod)%mod;
int I=ha[key]; while (I!=-1) {while (q[i].x+q[i].y) = = (x-y) &&q[i].x!=x&&q[i].x!=y&&q[i].y!=y&&
q[i].y!=x) {res=x;
Flag=true;
Return
} I=nex[i];
}} int main () {while (scanf ("%d", &n) &&n) {for (int i=0;i<n;i++) scanf ("%d", &s[i]);
int tot=0;
Sort (s,s+n);
memset (ha,-1,sizeof (Ha));
for (int i=0;i<n-1;i++) for (int j=i+1;j<n;j++) {q[tot].x=s[j];q[tot].y=s[i];
int key= (s[i]+s[j]+mod)%mod;
Nex[tot]=ha[key];
Ha[key]=tot;
tot++; } res=-1000000000;
Flag=false;
for (int i=n-1;i>=1;i--) for (int. j=i-1;j>=0;j--) {if (flag) break;
Solve (s[i],s[j]);
} if (res!=-1000000000) printf ("%d\n", res);
Else puts ("no solution");
} return 0;
}