标签:
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LL;
const int M = 4009,INF = 0x3fffffff;
int n, a[M], b[M], c[M], d[M];
int A[M * M], B[M * M];
int doit(int x, int step) {
int l = 0, r = step , mid = -1, ans = 0;
while(l < r) {
mid = (l + r) / 2;
if(B[mid] == x) {
for(int i = mid - 1; i >= 0; i--) {
if(B[i] != x) break;
ans++;
}
for(int i = mid; i < step; i++) {
if(B[i] != x) break;
ans++;
}
break;
}
if(B[mid] < x) l = mid + 1;
else r = mid;
}
return ans;
}
int main(void) {
//problem:poj 2785 , address: http://poj.org/problem?id=2785
while(cin >> n) {
int step = 0;
for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
A[step] = a[i] + b[j];
B[step++] = c[i] + d[j];
}
}
sort(B, B + step);
int ans = 0;
for(int i = 0; i < step; i++) {
ans += doit(-A[i], step);
}
cout << ans << endl;
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/jibancanyang/article/details/46228355