#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define LL long long
#define mod 100007
#define INF -536870999
struct node
{
LL data1, data2;
int next;
};
node hashnode[1111111];//要开的大一点,否则RE
int head[100007], cnt;
LL set[mod];
void init()
{
memset(head, -1, sizeof(head));
cnt = 0;
}
int gethash( LL num)
{
if(num < 0)
num = -num;
return (num + 1007)%mod;
}
void insert( LL num1, LL num2)
{
int h = gethash(num1 + num2);
hashnode[cnt].data1 = num1;
hashnode[cnt].data2 = num2;
hashnode[cnt].next = head[h];
head[h] = cnt++;
}
bool search( LL num1, LL num2)
{
int h = gethash(num1-num2);
for( int i = head[h]; i != -1; i = hashnode[i].next )
{
LL t1 = hashnode[i].data1;
LL t2 = hashnode[i].data2;
if(t1 != num1 && t1 != num2 && t2 != num1 && t2 != num2 && t1 + t2 == num1 - num2)//注意找KEY的值得时候一定要把条件考虑全面
return true;
}
return false;
}
int main()
{
int n;
while(scanf("%d",&n)!= EOF && n)
{
LL maxn = INF;
if( n < 3)
printf("no solution\n");
else
{
init();
int res = 0;
for( int i = 0; i < n; i++)
scanf("%lld",&set[i]);
sort(set, set + n);
n = unique(set, set + n) - set;
for( int i = 0; i < n ; i++)
{
for( int j = 0; j < n; j++)
{
if(i == j)
continue;
insert(set[i] ,set[j]);
}
}
for( int i = 0; i < n; i++)
{
for( int j = 0; j < n; j++)
{
if( i == j)
continue;
if(search(set[i],set[j]))
maxn = max(maxn, set[i]);
}
}
if(maxn == INF)
printf("no solution\n");
else printf("%lld\n",maxn);
}
}
return 0;
}
UVA 10125
最新推荐文章于 2017-08-18 19:51:52 发布