Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
其他OJ过了啊 PKU不过 过了的朋友看看~#include <stdio.h> #include <algorithm> using namespace std; const int MAXINT = 2000000000; const int N = 1005; struct Node {int a, b, c;}A[N*N], B[N*N]; int n; int x[N]; bool operator<(const Node& a, const Node& b) { return a.c < b.c; } int main() { int i, j; while(scanf("%d", &n), n) { if(n < 4) { printf("no solution\n"); continue; } for(i = 0; i < n; i++) scanf("%d", x+i); int k = 0; for(i = 0; i < n; i++) { for(j = i+1; j < n; j++) { if(x[i] != x[j]) { A[k].c = x[i] + x[j]; A[k].a = x[i]; A[k].b = x[j]; k++; } } } int k2 = 0; for(i = 0; i < n; i++) { for(j = 0; j<n; j++) { if(x[i] != x[j]) { B[k2].c = x[i] - x[j]; B[k2].a = x[i]; B[k2].b = x[j]; k2++; } } } sort(A, A+k); sort(B, B+k2); i = k-1, j = k2-1; int _max = -MAXINT; while(i >= 0 && j >= 0) { if(A[i].c != B[j].c) { if(A[i].c > B[j].c) i--; else j--; continue; } int o = j; while(A[i].c == B[j].c && j >= 0) { if(A[i].a != B[j].a && A[i].a != B[j].b && A[i].b != B[j].a && A[i].b != B[j].b) { if(B[j].a > _max) _max = B[j].a; } j--; } i--; j = o; } if(_max == -MAXINT) printf("no solution\n"); else printf("%d\n", _max); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator