Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

Re:其他OJ过了啊 PKU不过 过了的朋友看看~

Posted by shulenuoyan at 2009-03-30 16:46:43 on Problem 2549
In Reply To:其他OJ过了啊 PKU不过 过了的朋友看看~ Posted by:alpc12 at 2007-04-03 10:47:51
> #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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator