| Time Limit: 15000MS | Memory Limit: 228000K | |
| Total Submissions: 17658 | Accepted: 5187 | |
| Case Time Limit: 5000MS | ||
Description
Input
Output
Sample Input
6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45
Sample Output
5
Hint
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <iostream>
#define ll long long
using namespace std;
int const MAX = 4e3 + 5;
int a[MAX], b[MAX], c[MAX], d[MAX];
int num[MAX * MAX];
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
ll ans = 0;
int cnt = 0;
for(int i = 1; i <= n; i++)
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
num[cnt ++] = a[i] + b[j];
sort(num, num + cnt);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
int tmp = -c[i] - d[j];
int t1 = lower_bound(num, num + cnt, tmp) - num;
int t2 = upper_bound(num, num + cnt, tmp) - num;
ans += (ll)(t2 - t1);
}
}
cout << ans << endl;
}
}版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 2785 4 Values whose Sum is 0 (对半分解 二分搜索)
原文:http://blog.csdn.net/tc_to_top/article/details/47088987