UVA 10125
来源:互联网 发布:淘宝什么物品1元包邮 编辑:程序博客网 时间:2024/05/05 22:33
#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 -536870999struct node{ LL data1, data2; int next;};node hashnode[1111111];//要开的大一点,否则REint 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
- UVA 10125
- uva 10125
- UVa 10125 - Sumsets
- uva 10125 - Sumsets
- uva 10125 Sumsets
- UVa 10125 - Sumsets
- uva 10125 - Sumsets
- UVA 10125 Sumsets
- UVA 10125 - Sumsets
- UVa 10125-Sumsets
- UVa:10125 Sumsets
- uva 10125 Sumsets
- UVA 10125 Sumsets
- UVA 10125 (14.3.6)
- UVa 10125 - Sumsets
- uva 10125(哈希)
- UVA 10125 - Sumsets
- UVA - 10125 Sumsets
- 杭州电子科技大学Online Judge 之 “漂浮的气球(ID1004)”解题报告
- 移动端网站推广
- PARADOX dfs
- Flume 1.5.0.1 User Guide
- 设计模式之建造者模式
- UVA 10125
- [Meteor]Meteor:让实时Web App成为主流
- 基本图形绘制
- Ubuntu中环境变量到底是什么?
- 关于元模型(MetaModel)的理解
- [教程] Unity3d 4.0新动画系统Mecanim初探(一)
- hdu 1258 Sum It Up【深度优先搜索】
- 【软件工程】软工文档
- DES密码算法