UVA 10125
2014-11-03 21:53
218 查看
#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 - Sumsets好题
- UVA 10125 Sumsets 技巧性的枚举
- UVA - 10125 Sumsets
- Uva10125/POJ2549——Sumsets(中途相遇法,hash)
- UVA 10125 Sumsets .
- uva 10125
- UVA 10125(p89)----Sumsets
- UVa 10125 - Sumsets
- UVA 10125 Sumsets
- uva 10125和集 sumset(set)
- uva 10125 - Sumsets(a+b+c=d)
- uva 10125 Sumsets(搜索)
- UVA - 10125 Sumsets(二分查找)
- UVA 10125 - Sumsets
- 高效算法设计专项:UVa 10125
- uva10125 (中途相遇法)
- UVa 10125 - Sumsets
- UVa10125--Sumsets(折半搜索)
- UVa:10125 Sumsets
- UVA 10125 - Sumsets(POJ 2549) hash