| ||||||||||
| 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 | |||||||||
c++ 47ms g++WA可以帮我找下原因吗#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<iomanip>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<string.h>
#include<set>
#include<stack>
#include<map>
using namespace std;
#pragma warning(disable:4996)
#define rep(i, n) for(int i=0; i<n ;i++)
#define Rep(i, n) for(int i=1; i<=n; i++)
#define SYS system("pause");
typedef long long ll;
const int INF = 0x7fffffff;
const int MAX_N = 1e3 + 5;
const int MAX_V = 0;
const int MAX_M = 0;
const int MAX_Q = 0;
const int mod = 1e6 + 5;
int N;
int a[MAX_N];
int head[mod + 5];
int cnt = 0;
struct Node {
int x, y, nxt;
}nd[MAX_N*MAX_N];
void add_node(int x, int y) {
nd[cnt].x = x; nd[cnt].y = y;
int key = abs(x + y) % mod;
nd[cnt].nxt = head[key];
head[key] = cnt++;
}
bool search_node(int x, int y) {
int key = abs(x - y) % mod;
for (int i = head[key]; i != -1; i = nd[i].nxt) {
if (nd[i].x != x && nd[i].y != y && nd[i].x != y && nd[i].y != x) {
if(x-y==nd[i].x+nd[i].y)
return true;
}
}
return false;
}
int main() {
ios::sync_with_stdio(0);
while (cin >> N && N) {
cnt = 0;
memset(head, -1, sizeof head);
rep(i, N) {
cin >> a[i];
}
sort(a, a + N);
Rep(i, N - 1) {
rep(j, i) {
add_node(a[i], a[j]);
}
}
for (int i = N - 1; i >= 0; i--) {
for (int j = 0; j < N; j++) {
if (i != j && search_node(a[i], a[j])) {
cout << a[i] << endl;
goto ans;
}
}
}
puts("no solution");
ans:;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator