UVA 10125

8 篇文章 0 订阅
#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值